Project

General

Profile

Bug #5329 ยป test_20161004a_WStackedWidget_animation.C

Bruce Toll, 10/10/2016 09:55 PM

 
#include <Wt/WServer>
#include <Wt/WSignal>
#include <Wt/WAnimation>
#include <Wt/WStackedWidget>
#include <Wt/WFitLayout>
#include <Wt/WHBoxLayout>
#include <Wt/WAnimation>
#include <Wt/WText>
#include <Wt/WIcon>
#include <Wt/WBreak>
#include <Wt/WPushButton>
#include <Wt/WBootstrapTheme>

using namespace Wt;

class TestApplication : public WApplication
{
public:
TestApplication(const WEnvironment& env);
void addButton(const WString &text, const WAnimation &animation);

private:
static constexpr int FadeTime = 3000;
WBootstrapTheme bs_theme_;
WStackedWidget* sw_ = nullptr;
WContainerWidget* lhs_ = nullptr;
std::string smileys_;
};

void TestApplication::addButton(const WString &text, const WAnimation &animation)
{
(new WPushButton(text, lhs_))->clicked().connect(std::bind([this, animation] {
if (sw_->count() < 2) {
auto sw1 = new WContainerWidget();
sw1->decorationStyle().setBackgroundColor(yellow);
sw1->setOverflow(WContainerWidget::OverflowAuto, Vertical);
new WText(smileys_, sw1);
sw_->addWidget(sw1);
}
// ORDER MATTERS for next two statements...
sw_->setTransitionAnimation(animation);
sw_->setCurrentIndex(sw_->currentIndex() ^ 1);
}));
}

TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("StackedWidget layout animation issue");
setTheme(&bs_theme_);
// workaround to load font-awesome icons...
WIcon("bars");

for (int i=0; i < 1000; ++i)
smileys_ += "<i class=\"fa fa-smile-o fa-5x fa-fw\"></i>";

auto h_layout = new WHBoxLayout();
(new WFitLayout(root()))->addItem(h_layout);
h_layout->parentLayout()->setContentsMargins(0, 0, 0, 0);

lhs_ = new WContainerWidget();
new WText("<b>NOTES:</b><br/>"
"Look for initial failure to transition with fade button.<br/><br/>", lhs_);
addButton("Toggle StackedWidget (w/fade)", WAnimation(WAnimation::Fade, WAnimation::Linear, FadeTime));
addButton("Toggle StackedWidget", WAnimation());

h_layout->addWidget(lhs_);
h_layout->addWidget(sw_ = new WStackedWidget(), 1);

auto sw0 = new WContainerWidget();
sw0->decorationStyle().setBackgroundColor(lightGray);
sw_->addWidget(sw0);
}


int main(int argc, char **argv)
{
return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
}
    (1-1/1)