My apologies if this is not a bug, I am still new to Juce.
I believe that in juce_Viewport.cpp, everywhere that the horizontal or vertical scrollbar is being hidden, the range limits and current range should also be set to 0, 0. Specifically, when we call either of, or both of:
horizontalScrollBar->setVisible (false);
verticalScrollBar->setVisible (false);
We should also perform
horizontalScrollBar->setRangeLimits (0.0, 0.0);
horizontalScrollBar->setCurrentRange (0.0, 0.0);
verticalScrollBar->setRangeLimits (0.0, 0.0);
verticalScrollBar->setCurrentRange (0.0, 0.0);
Here is the reason:
If you have a non-empty juce_Viewport (one where the contentComponent has a non-empty bounding rectangle), and scrollbars are needed, they will be shown as necessary and the limits and range set appropriately.
However, if the contentComponent of the viewport changes to either fit exactly on screen, or become empty (in my case I am setting it empty), the scrollbars are hidden. This happens in juce_Viewport.cpp, updateVisibleRegion():
if ((contentComp->getWidth() > 0) && showHScrollbar
&& getHeight() > getScrollBarThickness())
{
horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
horizontalScrollBar->setSingleStepSize (singleStepX);
}
else
{
horizontalScrollBar->setVisible (false);
}
if ((contentComp->getHeight() > 0) && showVScrollbar
&& getWidth() > getScrollBarThickness())
{
verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
verticalScrollBar->setSingleStepSize (singleStepY);
}
else
{
verticalScrollBar->setVisible (false);
}
While hiding the scrollbars is the correct behavior (and it works properly), the scrollbars are still left with the old range limit and current range.
Now imagine that the contentComponent of the juce_Viewport again changes size, to exactly the size it had before the scrollbars were hidden. The juce_Viewport will update the scrollbar range limits and current range in updateVisibleRegion().
However, since the scrollbars already had the same range limits and current range, updateThumbPosition() never gets called. updateThumbPosition() is responsible for showing and hiding the scrollbars appropriately depending on their settings. This is where we skip the call to updateThumbPosition(), in juce_Scrollbar.cpp:
void ScrollBar::setCurrentRange (double newStart,
double newSize) throw()
{
newSize = jlimit (0.0, maximum - minimum, newSize);
newStart = jlimit (minimum, maximum - newSize, newStart);
if (rangeStart != newStart
|| rangeSize != newSize)
{
rangeStart = newStart;
rangeSize = newSize;
updateThumbPosition();
triggerAsyncUpdate();
}
}
Since rangeStart==newStart and rangeSize==newSize, because as mentioned earlier when the scrollbars are hidden the values are not changed, the call to updateThumbPosition() is skipped.
Again my apologies if this is not an actual bug and I am just mis-using the library, I am new to Juce.