Viewport issue

Hi there,

I come up with a bug in Viewport dealing with content component after resizing.
The way to reproduce the issue is :

  • Create a viewport, and its viewed component
  • On main window resized, tell that viewed component must have at least same size of viewport
  • Maximize window
  • Unmaximize it
    -> scrollbars may appear now, and it’s the case. Great !
  • Scroll down
  • Maximize window
    -> scrollbars may disappear now, and it’s not the case. WTF ?
  • Scroll up
    -> scrollbars disappear !

In fact, after scrolling down, bounds of content component are (0, -XXX, width, height) and for sure, are not contained in viewport bounds which are (0, 0, width, height).

Tell me if it is enough to understand the issue on that point !

Can you give me some sample code to reproduce this?

Sorry for answering lately. I cannot post some code because of its complexity now.
But I can tell you that the incriminated line is the 194th in juce_Viewport.cpp where :

[code]if (contentComp != nullptr && ! contentArea.contains (contentComp->getBounds()))[/code]

And this return false because of containing rules for Rectangle. As Y coordinate of content bounds is negative, area does not contain it. But they have same size !
So, you should test sizes more than bounds. IMHO :smiley:

No, that’s the way I intended it to work. Even if the item would fit in the viewport, but is currently positioned off one edge, the viewport needs to show the scrollbars, otherwise you could end up with the content getting stuck halfway off the screen, without any way to move it back on.

And why not positioning content in (0,0) when its size fits in viewport size ?

That gets in the way when you try to do things like centring the content inside the viewport. I’ve refactored that code many times, it’s a real pain to make it work correctly in all cases.

I do understand that fact. It is real that if content size is lower than viewport size, it could be also to center content in view. But in this case, can you evaluate the use of a Justification type ? In this way, we could attach content relatively to view area and in the case which I explained above it could be useful to reset content position at (0,0) if Justification was on top left edge of view.
But it is a minor bug, and I will understand if it could give you too many work for fixing it.

I’m still not 100% clear on what the bug is. It may be a legitimate problem which could be fixed in some other way, without breaking anything else, but it’s not obvious to me what’s going on…

When you resize the viewport to the size of its content, if scrollbars were not at 0, they still appears in viewport because of indent.
For example, if you have a content in 800x600, and your viewport is 400x300, you will have scrollbars.
Then move vertical bar to scroll the content which will set its bounds to (0, -200, 800, 600) for example.
If you set the viewport size to 800x600, then content must fit in it, and we do not need scrollbars anymore. But the size of the content is tested against viewport size using ::contains() function. So, as content bounds were set to -200 on y-axis, it will not be contained in viewport bounds.
IMHO, only sizes must be tested, and content position must be reset to (0,0) if its size fit inside viewport size if position was negative.
I do not known how to explain this clearly (maybe in french !)

Unfortunately, that’d break a lot of existing code, including some of my own, so I can’t just change its behaviour in that way.

Ok :smiley: