Project

General

Profile

Bug #6293 » main.cpp

Velvet Jones, 05/25/2018 01:37 PM

 
1
#include <Wt/WApplication>
2
#include <Wt/WContainerWidget>
3
#include <Wt/WGridLayout>
4
#include <Wt/WText>
5
#include <Wt/WLineEdit>
6
#include <Wt/WVBoxLayout>
7
#include <Wt/WTabWidget>
8
using namespace Wt;
9

    
10
class TestWidget : public Wt::WContainerWidget
11
{
12
  public:
13
    TestWidget(Wt::WString text);
14
    virtual ~TestWidget() {}
15
    void add (WWidget*);
16
    WVBoxLayout*  m_layout;
17
};
18

    
19
TestWidget::TestWidget(Wt::WString text)
20
  : WContainerWidget(),m_layout(0)
21
{
22
  bool CREATE_PROBLEM = true;
23
  if (CREATE_PROBLEM)
24
  {
25
  // PROBLEM: Parent layout is not 70/30, it's completely wrong
26
    m_layout = new WVBoxLayout(this);
27
  }
28
}
29

    
30
void TestWidget::add(Wt::WWidget* widget)
31
{
32
  if (m_layout)
33
    m_layout->addWidget (widget);
34
  else
35
    this->addWidget (widget);
36
}
37

    
38
class Test : public WApplication
39
{
40
    public:
41
        Test(const Wt::WEnvironment& env);
42
};
43

    
44
Test::Test(const Wt::WEnvironment& env)
45
    : Wt::WApplication(env)
46
{
47
  WGridLayout* l = new WGridLayout(root());
48

    
49
  l->setColumnResizable (0,true);
50
  l->setColumnResizable (1,true);
51
  l->setColumnStretch(0,0);
52
  l->setColumnStretch(1,70);
53
  l->setColumnStretch(2,30);
54

    
55
  l->setRowStretch(0,0);
56
  l->setRowStretch(1,1);
57
  l->setRowStretch(2,0);
58

    
59
  l->addWidget (new Wt::WLineEdit (),1,1,Wt::AlignTop);
60

    
61
  Wt::WTabWidget* t (new Wt::WTabWidget (0));
62

    
63
  TestWidget* tw1 = new TestWidget("");
64
  Wt::WLineEdit* le = new Wt::WLineEdit();
65
  le->setText ("Test text");
66
  tw1->add (le);
67
  t->addTab(tw1,"Test",Wt::WTabWidget::PreLoading);
68

    
69
  TestWidget* tw2 = new TestWidget("");
70
  t->addTab(tw2,"Test",Wt::WTabWidget::PreLoading);
71

    
72
  l->addWidget (t,1,2,Wt::AlignTop);
73
}
74

    
75
WApplication* createApplication(const Wt::WEnvironment& env)
76
{
77
    return new Test(env);
78
}
79

    
80
int main(int argc, char *argv[])
81
{
82
   return Wt::WRun(argc, argv, &createApplication);
83
}
(4-4/4)