Project

General

Profile

Bug #6291 ยป hello.cpp

compiling hello.cpp with #define THIS_WORKS makes working exe with two containers - Harald Elmer, 03/14/2018 03:26 PM

 
/*
* Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
*
* See the LICENSE file for terms of use.
*/

#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>
#include <Wt/WStackedWidget.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WLength.h>




class HelloApplication : public Wt::WApplication
{
public:
HelloApplication(const Wt::WEnvironment& env);
void switchStacked();

private:
Wt::WStackedWidget *m_pStack;

};



HelloApplication::HelloApplication(const Wt::WEnvironment& env)
: WApplication(env)
{


setTitle("Hello world");

Wt::WContainerWidget *pCont1 = root()->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());

pCont1->setWidth(Wt::WLength(100, Wt::WLength::Unit::Percentage));
pCont1->setHeight(70);
pCont1->decorationStyle().setBackgroundColor(Wt::WColor("Yellow"));

m_pStack = pCont1->addWidget(Wt::cpp14::make_unique<Wt::WStackedWidget>());

Wt::WContainerWidget *pContStack1 = m_pStack->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());

#ifdef THIS_WORKS
Wt::WContainerWidget *pContStack11 = pContStack1->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
#endif

Wt::WContainerWidget *pContStack2 = m_pStack->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());

#ifndef THIS_WORKS
Wt::WHBoxLayout *pLayout1 = pContStack1->setLayout(Wt::cpp14::make_unique<Wt::WHBoxLayout>());
#else
Wt::WHBoxLayout *pLayout1 = pContStack11->setLayout(Wt::cpp14::make_unique<Wt::WHBoxLayout>());
#endif

Wt::WContainerWidget *pButton1 = pLayout1->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
pButton1->decorationStyle().setBackgroundColor(Wt::WColor("Blue"));
pButton1->setWidth(100);
pButton1->setHeight(25);

Wt::WContainerWidget *pButton2 = pLayout1->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
pButton2->decorationStyle().setBackgroundColor(Wt::WColor("Red"));
pButton2->setWidth(100);
pButton2->setHeight(25);

Wt::WContainerWidget *pButton3 = pLayout1->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
pButton3->decorationStyle().setBackgroundColor(Wt::WColor("Green"));
pButton3->setWidth(100);
pButton3->setHeight(25);

Wt::WText *pText1 = pLayout1->addWidget(Wt::cpp14::make_unique<Wt::WText>("Hallo"));


auto button1 = root()->addWidget(Wt::cpp14::make_unique<Wt::WPushButton>("Switch"));
button1->clicked().connect(std::bind(&HelloApplication::switchStacked, this));


}

void HelloApplication::switchStacked()
{
auto i = m_pStack->currentIndex();
if (i)
m_pStack->setCurrentIndex(0);
else
m_pStack->setCurrentIndex(1);
}


int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
return Wt::cpp14::make_unique<HelloApplication>(env);
});
}
    (1-1/1)