Browse Source

Viewport: Added the ability to position the scrollbars at the top/left

tags/2021-05-28
hogliux 7 years ago
parent
commit
3ae28b3d54
2 changed files with 37 additions and 2 deletions
  1. +17
    -2
      modules/juce_gui_basics/layout/juce_Viewport.cpp
  2. +20
    -0
      modules/juce_gui_basics/layout/juce_Viewport.h

+ 17
- 2
modules/juce_gui_basics/layout/juce_Viewport.cpp View File

@@ -360,6 +360,12 @@ void Viewport::updateVisibleArea()
if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth);
if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth);
if (! vScrollbarRight && vBarVisible)
contentArea.setX (scrollbarWidth);
if (! hScrollbarBottom && hBarVisible)
contentArea.setY (scrollbarWidth);
if (contentComp == nullptr) if (contentComp == nullptr)
{ {
contentHolder.setBounds (contentArea); contentHolder.setBounds (contentArea);
@@ -383,7 +389,7 @@ void Viewport::updateVisibleArea()
auto& hbar = getHorizontalScrollBar(); auto& hbar = getHorizontalScrollBar();
auto& vbar = getVerticalScrollBar(); 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.setRangeLimits (0.0, contentBounds.getWidth());
hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth()); hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth());
hbar.setSingleStepSize (singleStepX); hbar.setSingleStepSize (singleStepX);
@@ -392,7 +398,7 @@ void Viewport::updateVisibleArea()
if (canShowHBar && ! hBarVisible) if (canShowHBar && ! hBarVisible)
visibleOrigin.setX (0); 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.setRangeLimits (0.0, contentBounds.getHeight());
vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight()); vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight());
vbar.setSingleStepSize (singleStepY); vbar.setSingleStepSize (singleStepY);
@@ -599,4 +605,13 @@ ScrollBar* Viewport::createScrollBarComponent (bool isVertical)
return new ScrollBar (isVertical); return new ScrollBar (isVertical);
} }
void Viewport::setScrollBarPosition (bool verticalScrollbarOnRight,
bool horizontalScrollbarAtBottom)
{
vScrollbarRight = verticalScrollbarOnRight;
hScrollbarBottom = horizontalScrollbarAtBottom;
resized();
}
} // namespace juce } // namespace juce

+ 20
- 0
modules/juce_gui_basics/layout/juce_Viewport.h View File

@@ -204,6 +204,25 @@ public:
bool allowVerticalScrollingWithoutScrollbar = false, bool allowVerticalScrollingWithoutScrollbar = false,
bool allowHorizontalScrollingWithoutScrollbar = 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. /** True if the vertical scrollbar is enabled.
@see setScrollBarsShown @see setScrollBarsShown
*/ */
@@ -300,6 +319,7 @@ private:
bool showHScrollbar = true, showVScrollbar = true, deleteContent = true; bool showHScrollbar = true, showVScrollbar = true, deleteContent = true;
bool customScrollBarThickness = false; bool customScrollBarThickness = false;
bool allowScrollingWithoutScrollbarV = false, allowScrollingWithoutScrollbarH = false; bool allowScrollingWithoutScrollbarV = false, allowScrollingWithoutScrollbarH = false;
bool vScrollbarRight = true, hScrollbarBottom = true;
struct DragToScrollListener; struct DragToScrollListener;
friend struct DragToScrollListener; friend struct DragToScrollListener;


Loading…
Cancel
Save