Get notification that a parent component’s visibilityChanged?

Can you find out if a component’s parent’s visibility has changed?

I’m using a TabbedComponent to show different pages of parameters. I wanted to use setBufferedToImage on some child components, but what happens is when you change tabs, the parent’s visibility is changed (not Visible), and all the cached images are dumped.

So I need to flag a complete redraw in the child component when this happens, so the next time they are shown they rebuild the cached image.

I tried overriding Component::visibilityChanged in the child components, but this is seemingly not called when the parent’s visibility changes.

I seem to recall there was some sort of Listener for this, but I can’t find it…

https://docs.juce.com/master/classTabbedButtonBar.html#a6a11f71e857b122419ed70066b8d4cda

Thanks, but I’m not quite understanding how currentTabChanged() would help.

The child components don’t know what tab they’re in (not without a lot of work…) Maybe I’m misunderstanding…

ComponentMovementWatcher is the closest I can think of. componentVisibilityChanged() is called when visibility changes for the component or any of its parents.

1 Like

When you get the currentTabChanged() notification, you can check if your child is no longer showing using Component::isShowing(). That will return false whether your component or any of its parents are invisible, which seems to suit your case.

2 Likes

Sorry for being dense, but ok: I override TabbedComponent::currentTabChanged() and this gets called when I change the tab.

Then, I have a large number of child components in various tabs of parameters that need to check their Component::isShowing()? How do they get notified to do this? Do I need to have a ListenerList or something, and add each of the components that I want to update to it?

(Side note: why does changing the visibility of the parent tab destroy all the cached images in child components related to using setBufferedToImage()? Having to rebuild all of these on a tab change, when they haven’t changed at all, seems problematic. I may have to just draw and cache my own Images, which is a lot more work…)

OK, it wasn’t as much work as I whined about. :flushed: Caching my own internal image for each component I want to manage this way seems to be the way to go. Then I don’t need to worry at all about the parent’s visibility being changed. Thanks for the suggestions.

1 Like