Viewport scrollbar jumps to the left when zooming

I’m using a Viewport to show a timeline of audio clips in my plugin.
When the Component where I draw the clips is wider than the Viewport, horizontal scrollbars are shown and work as expected.

I also have a zoom slider, which will change the width of the underlying Component (by calling setBounds() on it), scaling its content to fit the new width.
But when I change the bounds of the viewed Component, the scrollbar (and view) of the Viewport will immediately jump all the way to the left.
This is obviously not what the user wants if they’re trying to zoom in on a particular part of a waveform. :slight_smile:

So I would like the scrollbar to retain its relative position while the content size changes.
Is there a neat way to accomplish this using the Viewport class, or do I have to roll my own?

Perhaps there is a way of doing this out of the box (I can’t find anything obvious in the docs though), however you could :

  1. grab the current Viewport position using getViewPosition
  2. resize your viewed component
  3. set the position again on the Viewport

Yes, I’m going to do something like this. Thank you!