Custom Subcomponents not drawing inside Viewport

gui

#1

Hi all, I’m having an issue getting subcomponents to draw once they are hooked up in a Viewport.

I got the Viewport working using a very large button, so I know that works, but when I attach my own component, none of the subcomponents get drawn. Everything renders itself just fine when not using a Viewport, but its a dynamically generated list, so it will need to scroll.

I have a PlaylistPanel component that contains the playlistViewport (and other components). The PlaylistRoll component just manages rendering individual TrackItem components. Everything works fine until I add the playlistRoll as the viewable content for the Viewport like this:

addAndMakeVisible(playlistRoll);
addAndMakeVisible(playlistViewport);
playlistViewport.setViewedComponent(playlistRoll);

In my PlaylistPanel::resized I tried to force the playlist resized function to be called like so:

void PlaylistPanel::resized()
{
    songSelectButton.setBounds(10, 5, 130, 40);
    playlistViewport.setBounds(0, 50, getWidth(), getHeight() - 64);
    if (playlistRoll != nullptr) {
        playlistRoll->resized();
    }
}

This causes the following code to be called, which sets Bounds and makes visible individual TrackItem components stored in the tracks OwnedArray (I’m only iterating to 10 here because right now its just test data and I know how big the array is).

void PlaylistRoll::resized()
{
    for(int i=0; i<10; i++) {
        tracks[i]->setBounds(0, i*tracks[i]->getHeight(), getWidth(), tracks[i]->getHeight());
        addAndMakeVisible(tracks[i]);
        tracks[i]->resized(); 
    }
}

The last line where tracks[i]->resized() calls the tracks resized() function, which simply calls repaint(), but the paint() function in TrackItem is never called, so my Viewport renders blank.

When not using the Viewport, everything renders fine, and I don’t have to manually make calls to resized() to get things to try to draw themselves.

All this seems like a lot of hacky work to cascade drawing calls on a component viewed in a Viewport. Why won’t subcomponents draw themselves when viewed in a Viewport?

Is there something I’m missing or is this a bug in Juce?

Thanks in advance.


#2

You’ve not inherited from a Viewport, have you?


#3

No. Initially I had, but I removed that and just created a Viewport member in my PlaylistPanel class.

I was using Projucer 5.1.x yesterday. Just upgraded to 5.2 today, so I can return to the Viewport issue this afternoon and see if the upgrade affected anything.


#4

Well, I just mentioned that because a common mistake is to inherit from a class and override a method such as resized(), so that the base class’s version of that method doesn’t get to do its job. You also don’t seem to actually be setting a size for the component that goes in your viewport, so that might be it.


#5

Size was definitely the culprit. I just set the size of my custom component and everything worked.

Thanks for you help!