Project

General

Profile

Bug #7195 ยป main.cpp

Marco Kinski, 08/13/2019 08:28 PM

 

#include <Wt/WServer.h>

#include <Wt/WApplication.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WTabWidget.h>
#include <Wt/WVBoxLayout.h>
#include <Wt/WText.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WStackedWidget.h>
#include <Wt/WMenu.h>


class ContentWidget : public Wt::WCompositeWidget {
public:
ContentWidget ()
{
auto container = setImplementation(std::make_unique<Wt::WContainerWidget>());
auto layout = container->setLayout(std::make_unique<Wt::WVBoxLayout>());

layout->addWidget(std::make_unique<Wt::WText>("On top of window"));
layout->addStretch(1);
layout->addWidget(std::make_unique<Wt::WText>("On bottom of window"));

container->decorationStyle().setBorder(Wt::WBorder{Wt::BorderStyle::Solid, Wt::BorderWidth::Thick, Wt::StandardColor::Green});
}
};





class AppMain : public Wt::WApplication {
private:
void IndexWidget ()
{
root()->addWidget(std::make_unique<Wt::WText>(R"(
<a href="/tab"> Notebook </a><br />
<a href="/direct"> Direct </a><br />
<a href="/stack"> Stack </a><br />
)"));
}

void TabWidget ()
{
auto layout = root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
auto tab = layout->addWidget(std::make_unique<Wt::WTabWidget>());
for (auto i = 0; i < 10; ++i) {
tab->addTab(std::make_unique<ContentWidget>(), "tab " + std::to_string(i));
}

tab->decorationStyle().setBorder(Wt::WBorder{Wt::BorderStyle::Solid, Wt::BorderWidth::Thick, Wt::StandardColor::Red});
}

void DirectWidget ()
{
auto layout = root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
auto tab = layout->addWidget(std::make_unique<ContentWidget>());
}

void StackWidget ()
{
auto layout = root()->setLayout(std::make_unique<Wt::WHBoxLayout>());

auto stack_= std::make_unique<Wt::WStackedWidget>();
auto menu = layout->addWidget(std::make_unique<Wt::WMenu>(stack_.get()));
auto stack = layout->addWidget(std::move(stack_), 1);

for (auto i = 0; i < 10; ++i) {
menu->addItem("menu " + std::to_string(i), std::make_unique<ContentWidget>());
}

stack->decorationStyle().setBorder(Wt::WBorder{Wt::BorderStyle::Solid, Wt::BorderWidth::Thick, Wt::StandardColor::Red});
}

public:
AppMain (const Wt::WEnvironment& env)
: WApplication{env}
{
root()->decorationStyle().setBorder(Wt::WBorder{Wt::BorderStyle::Solid, Wt::BorderWidth::Thick});
}

static std::unique_ptr<AppMain> Instance (const Wt::WEnvironment& env)
{
auto app = std::make_unique<AppMain>(env);
app->IndexWidget();
return app;
}

static std::unique_ptr<AppMain> InstanceTab (const Wt::WEnvironment& env)
{
auto app = std::make_unique<AppMain>(env);
app->TabWidget();
return app;
}

static std::unique_ptr<AppMain> InstanceDirect (const Wt::WEnvironment& env)
{
auto app = std::make_unique<AppMain>(env);
app->DirectWidget();
return app;
}

static std::unique_ptr<AppMain> InstanceStack (const Wt::WEnvironment& env)
{
auto app = std::make_unique<AppMain>(env);
app->StackWidget();
return app;
}
};






int main (int argc, char** argv)
{
auto wserver = Wt::WServer(argc, argv);
wserver.addEntryPoint(Wt::EntryPointType::Application, &AppMain::Instance);
wserver.addEntryPoint(Wt::EntryPointType::Application, &AppMain::InstanceTab, "/tab");
wserver.addEntryPoint(Wt::EntryPointType::Application, &AppMain::InstanceDirect, "/direct");
wserver.addEntryPoint(Wt::EntryPointType::Application, &AppMain::InstanceStack, "/stack");

wserver.run();
return 0;
}
    (1-1/1)