Project

General

Profile

Bug #7009 ยป main.cpp

Maximilian Kleinert, 04/18/2019 10:19 AM

 
1
#include <Wt/WApplication.h>
2
#include <Wt/WContainerWidget.h>
3
#include <Wt/WPushButton.h>
4
#include <Wt/WPopupMenu.h>
5
#include <Wt/WNavigationBar.h>
6

    
7
class MyApp : public Wt::WApplication {
8
    public:
9
        explicit MyApp(const Wt::WEnvironment &env) : Wt::WApplication(env)
10
    {
11
        menu_ = root()->addNew<Wt::WNavigationBar>()->addMenu(Wt::cpp14::make_unique<Wt::WMenu>());
12
        auto item = std::make_unique<Wt::WMenuItem>("Popup Menu");
13
        auto popupMenu = Wt::cpp14::make_unique<Wt::WPopupMenu>();
14
        popupMenu->addItem("Delete Popup Menu")->triggered().connect([=] {
15
                for (auto item : menu_->items())
16
                    menu_->removeItem(item);
17
                });
18
        item->setMenu(std::move(popupMenu));
19
        menu_->addItem(std::move(item));
20

    
21
        auto popupButton = Wt::cpp14::make_unique<Wt::WPopupMenu>();
22
        popupButton->addItem("Delete Popup Button")->triggered().connect([=] { root()->removeWidget(button_); });
23
        button_ = root()->addWidget(Wt::cpp14::make_unique<Wt::WPushButton>("Popup Button"));
24
        button_->setMenu(std::move(popupButton));
25
    }
26
    private:
27
        Wt::WPushButton *button_;
28
        Wt::WMenu *menu_;
29
};
30
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env)
31
{
32
    std::unique_ptr<Wt::WApplication> app = std::make_unique<MyApp>(env);
33
    return app;
34
}
35
int main(int argc, char **argv)
36
{
37
    return Wt::WRun(argc, argv, &createApplication);
38
}
    (1-1/1)