diff --git a/modules/juce_gui_basics/layout/juce_Viewport.cpp b/modules/juce_gui_basics/layout/juce_Viewport.cpp index a74ee35f47..7e04b3152f 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.cpp +++ b/modules/juce_gui_basics/layout/juce_Viewport.cpp @@ -360,6 +360,12 @@ void Viewport::updateVisibleArea() if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); + if (! vScrollbarRight && vBarVisible) + contentArea.setX (scrollbarWidth); + + if (! hScrollbarBottom && hBarVisible) + contentArea.setY (scrollbarWidth); + if (contentComp == nullptr) { contentHolder.setBounds (contentArea); @@ -383,7 +389,7 @@ void Viewport::updateVisibleArea() auto& hbar = getHorizontalScrollBar(); auto& vbar = getVerticalScrollBar(); - hbar.setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); + hbar.setBounds (contentArea.getX(), hScrollbarBottom ? contentArea.getHeight() : 0, contentArea.getWidth(), scrollbarWidth); hbar.setRangeLimits (0.0, contentBounds.getWidth()); hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth()); hbar.setSingleStepSize (singleStepX); @@ -392,7 +398,7 @@ void Viewport::updateVisibleArea() if (canShowHBar && ! hBarVisible) visibleOrigin.setX (0); - vbar.setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); + vbar.setBounds (vScrollbarRight ? contentArea.getWidth() : 0, contentArea.getY(), scrollbarWidth, contentArea.getHeight()); vbar.setRangeLimits (0.0, contentBounds.getHeight()); vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight()); vbar.setSingleStepSize (singleStepY); @@ -599,4 +605,13 @@ ScrollBar* Viewport::createScrollBarComponent (bool isVertical) return new ScrollBar (isVertical); } +void Viewport::setScrollBarPosition (bool verticalScrollbarOnRight, + bool horizontalScrollbarAtBottom) +{ + vScrollbarRight = verticalScrollbarOnRight; + hScrollbarBottom = horizontalScrollbarAtBottom; + + resized(); +} + } // namespace juce diff --git a/modules/juce_gui_basics/layout/juce_Viewport.h b/modules/juce_gui_basics/layout/juce_Viewport.h index 529e3beaba..f28a85a3d8 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.h +++ b/modules/juce_gui_basics/layout/juce_Viewport.h @@ -204,6 +204,25 @@ public: bool allowVerticalScrollingWithoutScrollbar = false, bool allowHorizontalScrollingWithoutScrollbar = false); + /** Changes where the scroll bars are positioned + + If verticalScrollbarOnRight is set to true, then the vertical scrollbar will + appear on the right side of the view port's content (this is the default), + otherwise it will be on the left side of the content. + + If horizontalScrollbarAtBottom is set to true, then the horizontal scrollbar + will appear at the bottom of the view port's content (this is the default), + otherwise it will be at the top. + */ + void setScrollBarPosition (bool verticalScrollbarOnRight, + bool horizontalScrollbarAtBottom); + + /** True if the vertical scrollbar will appear on the right side of the content */ + bool isVerticalScrollbarOnTheRight() const noexcept { return vScrollbarRight; } + + /** True if the horizontal scrollbar will appear at the bottom of the content */ + bool isHorizontalScrollbarAtBottom() const noexcept { return hScrollbarBottom; } + /** True if the vertical scrollbar is enabled. @see setScrollBarsShown */ @@ -300,6 +319,7 @@ private: bool showHScrollbar = true, showVScrollbar = true, deleteContent = true; bool customScrollBarThickness = false; bool allowScrollingWithoutScrollbarV = false, allowScrollingWithoutScrollbarH = false; + bool vScrollbarRight = true, hScrollbarBottom = true; struct DragToScrollListener; friend struct DragToScrollListener;