Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <Wt/WPushButton>
- #include <Wt/WServer>
- #include <Wt/WApplication>
- #include <Wt/WServer>
- #include <Wt/WBootstrapTheme>
- #include <Wt/WNavigationBar>
- #include <Wt/WMenu>
- #include <Wt/WStackedWidget>
- #include <Wt/WVBoxLayout>
- #include <Wt/WText>
- #include <boost/bind.hpp>
- namespace blog {
- namespace view {
- class WebGUI : public Wt::WApplication {
- public:
- WebGUI (const Wt::WEnvironment& env, Wt::WServer &server);
- private:
- Wt::WServer &server;
- Wt::WStackedWidget *menuStack;
- Wt::WVBoxLayout *globalLayout;
- void navigation (Wt::WStackedWidget *stack);
- Wt::WNavigationBar * createNavigationBar(Wt::WStackedWidget *stack,
- Wt::WContainerWidget *parent = 0);
- };
- void WebGUI::navigation (Wt::WStackedWidget *stack) {
- auto app = Wt::WApplication::instance();
- if (app->internalPath() == "/"){
- stack->setCurrentIndex(0);
- } else {
- setInternalPathValid (false);
- }
- }
- Wt::WNavigationBar * WebGUI::createNavigationBar(Wt::WStackedWidget *stack, Wt::WContainerWidget *parent) {
- Wt::WNavigationBar * navigation = new Wt::WNavigationBar(parent);
- navigation->setResponsive(true);
- Wt::WMenu *leftMenu = new Wt::WMenu(stack, parent);
- Wt::WVBoxLayout *layout = new Wt::WVBoxLayout();
- auto mainContainer = new Wt::WContainerWidget();
- mainContainer->setLayout(layout);
- leftMenu->addItem("Home", mainContainer);
- for (int i = 0 ; i < 10 ; i++){
- auto container = new Wt::WContainerWidget();
- container->addWidget(new Wt::WText("<ol><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ol>"));
- layout->addWidget(container);
- }
- Wt::WApplication::instance()->enableUpdates(true);
- navigation->addMenu(leftMenu);
- return navigation;
- }
- WebGUI::WebGUI(const Wt::WEnvironment& env, Wt::WServer &server)
- : Wt::WApplication(env),
- server (server){
- menuStack = new Wt::WStackedWidget();
- internalPathChanged().connect(std::bind([=] () {this->navigation(menuStack);}));
- globalLayout = new Wt::WVBoxLayout();
- root()->setLayout(globalLayout);
- setTheme(new Wt::WBootstrapTheme());
- root()->setStyleClass("container");
- auto navBar = createNavigationBar(menuStack, root());
- globalLayout->addWidget(navBar,0);
- globalLayout->addWidget(menuStack,1);
- globalLayout->addStretch(1);
- }
- } // view
- } // blog
- Wt::WApplication *createApplication(const Wt::WEnvironment& env, Wt::WServer &server) {
- return new blog::view::WebGUI(env, server);
- }
- int main(int argc, char **argv) {
- Wt::WServer server(argv[0]);
- server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
- server.addEntryPoint(Wt::Application,
- boost::bind(createApplication, _1, std::ref(server)));
- if (server.start()) {
- int sig = Wt::WServer::waitForShutdown();
- std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
- server.stop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment