How to wait using a timer?


I’m trying to use the super fancy fadeOutComponent that jules has created to implement a cool transition from one tab to another in a tabbed component. The transition works well, but the new tab appears before the old one has finished its transition.

So, I derived my tabbed component from the Timer class as well, and tried running the timer starting in createPanelComponentForTab() to cause the creation of the new tab to wait until the old panel’s distructor has finished its fade.

The problem I’m facing is how to implement a hold in the createPanelComponentForTab() in such a way that I don’t hog the thread and allow the timer to spin. Is there a graceful way to wait x seconds before executing the next line of code in this situation?


I don’t recommend it, but MessageManager::dispatchPendingMessages() allows a thread to run the message dispatcher while it waits. There are a lot of ramifications of using this though, as the object that’s waiting could itself be deleted or could recursively call itself while it’s waiting, so only use this if you really know what you’re doing.

It’s always better just to design it so that timers trigger other events and no thread has to block.


I just updated to 1.34, and now I see that I don’t even have a hook to delay in when the tabs are changing as I did before in createPanelComponentForTab(). Any recommendations on how to slow the transition from one tab to another to allow a fade out?


Why not just write a new type of button, and overrideTabbedButtonBar::createTabButton(). You could make the button fade when it gets toggled.

Trying to do stuff like this with dodgy hacks to TabbedComponent is bound to get broken when I make changes!