|
#include <Wt/WApplication.h>
|
|
#include <Wt/WBreak.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WLineEdit.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WText.h>
|
|
#include <Wt/WBootstrapTheme.h>
|
|
|
|
class HelloApplication : public Wt::WApplication
|
|
{
|
|
public:
|
|
HelloApplication(const Wt::WEnvironment& env);
|
|
|
|
private:
|
|
Wt::WLineEdit *nameEdit_;
|
|
Wt::WText *greeting_;
|
|
};
|
|
|
|
HelloApplication::HelloApplication(const Wt::WEnvironment& env)
|
|
: Wt::WApplication(env)
|
|
{
|
|
|
|
//Set the theme
|
|
auto theme = std::make_shared<Wt::WBootstrapTheme>();
|
|
theme->setVersion(Wt::BootstrapVersion::v3);
|
|
wApp->setTheme(theme);
|
|
|
|
setTitle("Hello world");
|
|
|
|
auto text = std::make_unique<Wt::WText>("Your name, please? ");
|
|
//add bootstrap style to widget
|
|
text->addStyleClass("label label-primary");
|
|
root()->addWidget(std::move(text));
|
|
|
|
nameEdit_ = root()->addWidget(std::make_unique<Wt::WLineEdit>());
|
|
Wt::WPushButton *button = root()->addWidget(std::make_unique<Wt::WPushButton>("Greet me."));
|
|
button->addStyleClass("btn btn-success");
|
|
root()->addWidget(std::make_unique<Wt::WBreak>());
|
|
greeting_ = root()->addWidget(std::make_unique<Wt::WText>());
|
|
auto greet = [this] {
|
|
greeting_->setText("Hello there, " + nameEdit_->text());
|
|
};
|
|
button->clicked().connect(greet);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
|
|
return std::make_unique<HelloApplication>(env);
|
|
});
|
|
}
|