Project

General

Profile

Bug #10871 » main.cpp

Stefan Bn, 08/26/2022 02:01 PM

 
1
#include <Wt/WApplication.h>
2
#include <Wt/WBootstrap5Theme.h>
3
#include <Wt/WServer.h>
4

    
5
#include <Wt/WContainerWidget.h>
6
#include <Wt/WTemplate.h>
7
#include <Wt/WLineEdit.h>
8

    
9

    
10
using namespace Wt;
11

    
12

    
13

    
14
// -----------------------------------------------------------------------------------
15
std::unique_ptr<WApplication> createHelloApplication(const WEnvironment &env)
16
{
17
    auto app = std::make_unique<WApplication>(env);
18

    
19
    auto theme = std::make_shared<WBootstrap5Theme>();
20
    app->setTheme(theme);
21

    
22
    WString floatTempl = "<form class='form-floating' id='floatingInputValue'> ${InputWidget}"
23
                         "<label for='floatingInputValue'>${MainLabel}</label> </form>";
24

    
25
    for (int i = 0; i < 5; i++)
26
    {
27
        auto userTemplate = app->root()->addWidget(std::make_unique<WTemplate>(floatTempl));
28
        userTemplate->addFunction("id", &WTemplate::Functions::id);
29

    
30
        userTemplate->setMargin(10, Side::Bottom);
31
        userTemplate->setMaximumSize(400, WLength::Auto);
32

    
33
        auto userEdit = userTemplate->bindWidget("InputWidget", std::make_unique<WLineEdit>());
34
        userEdit->setMaxLength(64);
35
        userEdit->setPlaceholderText(" ");  // Required damit es floated
36

    
37
        userTemplate->bindString("MainLabel", "Floating Label Field " + std::to_string(i));
38
    }
39

    
40
    return app;
41
}
42

    
43

    
44
// -----------------------------------------------------------------------------------
45
int main(int argc, char *argv[])
46
{
47
    try
48
    {
49
        WServer server(argc, argv, WTHTTP_CONFIGURATION);
50

    
51
        server.addEntryPoint(EntryPointType::Application,
52
                             std::bind(&createHelloApplication, std::placeholders::_1));
53

    
54
        if (server.start())
55
        {
56
          int sig = WServer::waitForShutdown();
57

    
58
          std::cerr << "*** Shutdown (signal = " << sig << ")" << std::endl;
59
          server.stop();
60

    
61
          if (sig == 1) // SIGHUP
62
            WServer::restart(argc, argv, environ);
63

    
64
          return 0;
65
        }
66
    }
67
    catch (WServer::Exception &e)
68
    {
69
        std::cerr << "*** Server Exception: " << e.what() << std::endl;
70
    }
71
    catch (std::exception &e)
72
    {
73
        std::cerr << "*** Std Exception: " << e.what() << std::endl;
74
    }
75
}
(1-1/2)