Ask for a unobtrusive ViewportListener

i’m implementing a ViewportNavigator component, which takes a Viewport in the constructor and from a timer it makes a small image of the contained component letting you navigate the whole area.

The ViewportNavigator is a ComponentListener of both the Viewport and the contained Component so the small image will be updated when both change in size. For changing the image also when the Viewport area is changed, i need to subclass the Viewport and make use of the virtual visibleAreaChanged, but then the ViewportNavigator will work only with this new type of component and not with every viewport.

What would be good and logic would be to add a ViewportListener interface so i can be notified of a visibleAreaChanged even from external components.

i hope you’ll find this a sensible request…

ah, would be cool also to be notified from the Viewport when the viewed component changes !


Yes, a sensible request!

i had my brain on fire so i started implementing it. it’s all ok, apart that it will be sensible to have an additional const bool notifyListeners in updateVisibleRegion so that i can select to not go in a endless update loop.
This will require to add the boolean flag to both setViewPosition and setViewPositionProportionately, but they do not call updateVisibleRegion directly, cause it is called from there only when componentMovedOrResized is triggered… this way if i set the new position of the Viewport from the ViewportNavigator, then it will be updated again cause it is a listener to that Viewport too !

what you think about this ?

here it is !

hope you will include it in the library ! it’s very useful !

I was looking for this kind of navigator component, I will try it right away.
Many thanks for sharing :stuck_out_tongue: