Animation not working
Added by Nezar Ab almost 10 years ago
Hey,
I created a WStackedWidget, and It works properly without animation, but when I try to add a simple Fading animation, the stack's widgets don't change.
Please tell me what am I doing wrong, or if you have the same problem when you try to run this in your browser.
Here is the full code : compile with ./app ---docroot . ---http-address 0.0.0.0 ---http-port localhost:portNumber
#include <Wt/WApplication>
#include <Wt/WStackedWidget>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WAnimation>
class MyContainer : public Wt::WContainerWidget
{
public :
MyContainer();
void switchWidget();
private :
Wt::WStackedWidget* theStack;
Wt::WPushButton* theButton;
};
MyContainer::MyContainer()
: WContainerWidget(),
theStack(new Wt::WStackedWidget(this)),
theButton(new Wt::WPushButton("push me", this))
{
theStack->addWidget(new Wt::WText("Widget number 1"));
theStack->addWidget(new Wt::WText("Widget number 2"));
theStack->addWidget(new Wt::WText("Widget number 3"));
theStack->addWidget(new Wt::WText("Widget number 4"));
// When I add the following piece of code, It doesn't work
Wt::WAnimation animation(Wt::WAnimation::Fade,
Wt::WAnimation::Linear, 250);
theStack->setTransitionAnimation(animation,true);
//------------
theButton->clicked().connect(std::bind([&](){
this->switchWidget();
}));
}
void MyContainer::switchWidget() {
int current = theStack->currentIndex();
if(current!=3) theStack->setCurrentIndex(current+1);
else theStack->setCurrentIndex(0);
}
class Napp : public Wt::WApplication
{
public :
Napp(const Wt::WEnvironment &env);
};
Napp::Napp(const Wt::WEnvironment &env)
: WApplication(env)
{
this->root()->addWidget(new MyContainer());
}
Wt::WApplication* createApp(const Wt::WEnvironment &env)
{
return new Napp(env);
}
int main(int argc, char** argv)
{
return WRun(argc,argv,&createApp);
}