Strange flickering

I’m designing a dynamic panel inside a tab and I have some flickering issues. This is a sequencer where the user always haves one selected track in full size and the other ones in a smaller size. But when I switch between tracks it flickers a bit. Basically I’m resizing the component inside the paint loop and using setVisible() to hide components like this:

[code]void MyComponent::paint (Graphics& g)
{
if (selectedTrackID==ACTIVE){
setTopLeftPosition(0,0);
setSize (800, selectedTrackSize);
sequenceControlComponent->setVisible(true);
patternComponent->setVisible(true);

}else{
    setSize (800, unselectedTrackSize);
    sequenceControlComponent->setVisible(false);
    patternComponent->setVisible(false);
}[/code]

Not sure if this is a design issue…?

Changing the size of your Component from inside the paint() function is a recipe for disaster. Don’t do it.

Always update (aka resized()) before you draw (aka paint() - which gets called if you resize anyways, if I’m not mistaken).

I think what’s happening is he is missing a robust framework for broadcasting changes in meta UI settings (like currently selected track), and he’s relying on timer / paint calls to get the opportunity to perform the necessary user interface manipulation.

OP: Instead of doing this in the paint you should have a ListenerList, ChangeBroadcaster, or use one of the VFLib notification facilities:

vf::componentNotifyParent url=http://vinniefalco.com/VFLib/classcomponent_notify_parent.html[/url]
vf::componentBroadcast url=http://vinniefalco.com/VFLib/classcomponent_broadcast.html[/url]

Probably componentBroadcast is what you want. For each of your Component objects that “cares” about the currently selected track, use multiple inheritance to derive it from this interface:

struct CurrentTrackListener {
  virtual void onCurrentTrackChanged (Track* currentTrack) { }
};

Then when the current track changes, broadcast the event from the top level:

vf::componentBroadcast (topLevelComponent, &CurrentTrackListener::onCurrentTrackChanged, currentTrack);

Thanks guys, I will try this.

Cheers