|
#include <Wt/WApplication.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WHBoxLayout.h>
|
|
#include <Wt/WVBoxLayout.h>
|
|
#include <Wt/WTextArea.h>
|
|
#include <Wt/WLineEdit.h>
|
|
|
|
struct ContainerWidgetBoxer {
|
|
template<typename Layout>
|
|
static Wt::WContainerWidget* box(Wt::WContainerWidget* boxingContainer, std::unique_ptr<Wt::WContainerWidget> &&container, const int stretchFirst = 0, const int stretchSecond = 1)
|
|
{
|
|
auto layout = boxingContainer->setLayout(std::make_unique<Layout>());
|
|
layout->setSpacing(0);
|
|
auto c = layout->addWidget(std::move(container), stretchFirst);
|
|
auto stretcher = layout->addWidget(std::make_unique<Wt::WContainerWidget>(), stretchSecond);
|
|
stretcher->setMargin(0);
|
|
stretcher->setPadding(0);
|
|
return c;
|
|
}
|
|
|
|
static Wt::WContainerWidget* boxboth(Wt::WContainerWidget* boxingContainer, std::unique_ptr<Wt::WContainerWidget> &&container)
|
|
{
|
|
auto innerBox = ContainerWidgetBoxer::box<Wt::WHBoxLayout>(boxingContainer, std::make_unique<Wt::WContainerWidget>());
|
|
auto c = ContainerWidgetBoxer::box<Wt::WVBoxLayout>(innerBox, std::move(container));
|
|
innerBox->setMargin(0);
|
|
innerBox->setPadding(0);
|
|
innerBox->addStyleClass("innerbox");
|
|
return c;
|
|
}
|
|
};
|
|
|
|
class MyApp : public Wt::WApplication {
|
|
public:
|
|
explicit MyApp(const Wt::WEnvironment &env) : Wt::WApplication(env)
|
|
{
|
|
ContainerWidgetBoxer::boxboth(root(), create());
|
|
}
|
|
|
|
private:
|
|
|
|
Wt::WTextArea *logWidget_;
|
|
Wt::WLineEdit* lineEdit_;
|
|
Wt::WPushButton *launch_;
|
|
|
|
void update()
|
|
{
|
|
launch_->disable();
|
|
logWidget_->doJavaScript(
|
|
"var textarea = document.getElementById('" + logWidget_->id() + "');" +
|
|
"textarea.value += " + "'" + lineEdit_->text().toUTF8() + "\\n';" +
|
|
"textarea.scrollTop = textarea.scrollHeight;"
|
|
);
|
|
lineEdit_->setText("");
|
|
launch_->enable();
|
|
}
|
|
std::unique_ptr<Wt::WContainerWidget> create()
|
|
{
|
|
auto c = std::make_unique<Wt::WContainerWidget>();
|
|
auto vbox = c->setLayout(std::make_unique<Wt::WVBoxLayout>());
|
|
logWidget_ = vbox->addWidget(std::make_unique<Wt::WTextArea>());
|
|
auto hbox = vbox->addLayout(std::make_unique<Wt::WHBoxLayout>());
|
|
|
|
lineEdit_ = hbox->addWidget(std::make_unique<Wt::WLineEdit>(), 1);
|
|
launch_ = hbox->addWidget(std::make_unique<Wt::WPushButton>("Run"));
|
|
auto clear = hbox->addWidget(std::make_unique<Wt::WPushButton>("Clear"));
|
|
|
|
launch_->clicked().connect([this]() {
|
|
update();
|
|
});
|
|
clear->clicked().connect([this]() { logWidget_->setText(""); });
|
|
lineEdit_->keyWentUp().connect([this](Wt::WKeyEvent key) {
|
|
if (key.key() == Wt::Key::Enter)
|
|
{
|
|
update();
|
|
}
|
|
});
|
|
return c;
|
|
}
|
|
};
|
|
|
|
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env)
|
|
{
|
|
std::unique_ptr<Wt::WApplication> app = std::make_unique<MyApp>(env);
|
|
return app;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return Wt::WRun(argc, argv, &createApplication);
|
|
}
|