Viewport::setBounds resets view position


#1

The Viewport class resets its view position, after a call to setBounds. Is it supposed to do that ?

I have to admit: I do not quite understand the mechanism, how the reset is done, because setBounds is not reimplemented in Viewport but inherited from component. Anyways, after a setBounds call, the viewPosition is back to (0,0). Even if it was somewhere else before.

Or maybe I am doing something wrong?

There is a workround though, which I currently use. Just remember and reapply the view position. I.e.:

Point<int> oldViewPos = myViewPort.getViewPosition();
myViewPort.setBounds(x,y, width, height);
myViewPort.setViewPosition(oldViewPos);

 

Juce Version: 4.0.2 on Win 7 and VS 2015


#2

When the viewport changes size it has an algorithm for making sure its content is kept on-screen.

Perhaps your content actually fits fully inside the viewport, but you've forced its position to be partially off-screen? If you did that, then when the viewport is given a chance to sanity-check its position (during a resize) then it says "hey, this will fit, there's no reason for it to be off the side, I'll snap it back to the origin".


#3

No, that's not the case. My content is much larger than the viewport.


#4

Well, you might want to look inside the viewport's layout code and see what's going on, I don't know why it would do that if it doesn't need to, but there could be a good reason.