TL;DR: calling setSize() on a component that is displayed in a juce::Viewport but not owned by the viewport sometimes causes the component to not be made invisible.
I have a component that is displayed in a viewport, but not owned by said viewport.
The component is the view of an entry in a container. When I change the entry (via some << >> buttons that cycle through the container), the component refreshes its child components. This component also resizes itself depending on the number of child components it needs to display based on the data entry it’s displaying
I’m not sure what’s causing the behavior I’m experiencing, but whenever I do this pattern:
void ViewportContentComponent::update(DataModel& dataToDisplay)
{
data = dataToDisplay;
triggerAsyncUpdate();
}
void ViewportContentComponent::handleAsyncUpdate()
{
stateChanged(); //recreates the child component views needed for the updated data
setSize(getWidth(), getNeededHeight() );
}
int ViewportContentComponent::getNeededHeight()
{
//count the number of rows needed to display all of the items in `data`
int numRows = ...; //a bunch of counting and summing of container elements
numRows = juce::jmax(numRows, 6); //must be at least 6 rows tall
return numRows * 30;
}
void EditorComponent::advanceToNextEntry() //user clicked the >> button
{
++entryIndex;
if( entryIndex > dataModel.size() - 1)
entryIndex = 0; //wrap around
currentData = dataModel[entryIndex];
viewportContentComponent->update( dataModel[entryIndex] );
//force-refresh the viewport and other GUI components based on
//the updated 'currentData'
resized();
}
the ViewportContentComponent shown in the viewport stops being displayed.
It’s only if I explicitly call resized() after setSize() that the viewport content refreshes itself.
INFO: setSize() calls resized() if the new bounds are different from the previous bounds.
Any ideas what would cause this issue of the component suddenly disappearing from the viewport?
