Skip to content

Commit

Permalink
add adjustable minimum scroller size for the scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Oct 23, 2024
1 parent 2a6086e commit b55ef07
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
15 changes: 13 additions & 2 deletions vstgui/lib/controls/cscrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void CScrollbar::calculateScrollerLength ()
factor = 0;
newScrollerLength = (CCoord) (getViewSize ().getHeight () * factor);
}
if (newScrollerLength < 8. && newScrollerLength > 0.)
newScrollerLength = 8.;
if (newScrollerLength < minScrollerLenght && newScrollerLength > 0.)
newScrollerLength = minScrollerLenght;
if (newScrollerLength != scrollerLength)
{
scrollerLength = newScrollerLength;
Expand Down Expand Up @@ -175,6 +175,17 @@ void CScrollbar::setOverlayStyle (bool state)
}
}

//------------------------------------------------------------------------
void CScrollbar::setMinScrollerLength (CCoord length)
{
if (minScrollerLenght != length)
{
minScrollerLenght = length;
calculateScrollerLength ();
setDirty ();
}
}

//-----------------------------------------------------------------------------
CMouseEventResult CScrollbar::onMouseEntered (CPoint& where, const CButtonState& buttons)
{
Expand Down
8 changes: 6 additions & 2 deletions vstgui/lib/controls/cscrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class CScrollbar : public CControl

bool getOverlayStyle () const { return overlayStyle; }
virtual void setOverlayStyle (bool state);


void setMinScrollerLength (CCoord length);
CCoord getMinScrollerLength () const { return minScrollerLenght; }

virtual void onVisualChange ();
CRect getScrollerRect ();
//@}
Expand Down Expand Up @@ -81,7 +84,8 @@ class CScrollbar : public CControl

float stepValue;
CCoord scrollerLength;

CCoord minScrollerLenght {8.0};

CColor frameColor;
CColor scrollerColor;
CColor backgroundColor;
Expand Down
2 changes: 2 additions & 0 deletions vstgui/standalone/examples/standalone/resource/test.uidesc
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@
"overlay-scrollbars": "false",
"scrollbar-background-color": "~ TransparentCColor",
"scrollbar-frame-color": "~ TransparentCColor",
"scrollbar-min-scroller-size": "8",
"scrollbar-scroller-color": "~ WhiteCColor",
"scrollbar-width": "12",
"size": "110, 140",
Expand Down Expand Up @@ -963,6 +964,7 @@
"overlay-scrollbars": "false",
"scrollbar-background-color": "~ TransparentCColor",
"scrollbar-frame-color": "~ TransparentCColor",
"scrollbar-min-scroller-size": "18",
"scrollbar-scroller-color": "~ WhiteCColor",
"scrollbar-width": "12",
"size": "270, 140",
Expand Down
1 change: 1 addition & 0 deletions vstgui/uidescription/detail/uiviewcreatorattributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static const std::string kAttrScrollbarBackgroundColor = "scrollbar-background-c
static const std::string kAttrScrollbarFrameColor = "scrollbar-frame-color";
static const std::string kAttrScrollbarScrollerColor = "scrollbar-scroller-color";
static const std::string kAttrScrollbarWidth = "scrollbar-width";
static const std::string kAttrMinScrollerSize = "scrollbar-min-scroller-size";

//-----------------------------------------------------------------------------
// CControlCreator attributes
Expand Down
15 changes: 15 additions & 0 deletions vstgui/uidescription/viewcreator/scrollviewcreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ bool ScrollViewCreator::apply (CView* view, const UIAttributes& attributes,
CCoord width;
if (attributes.getDoubleAttribute (kAttrScrollbarWidth, width))
scrollView->setScrollbarWidth (width);
if (attributes.getDoubleAttribute (kAttrMinScrollerSize, width))
{
if (vscrollbar)
vscrollbar->setMinScrollerLength (width);
if (hscrollbar)
hscrollbar->setMinScrollerLength (width);
}
return true;
}

Expand All @@ -127,6 +134,7 @@ bool ScrollViewCreator::getAttributeNames (StringList& attributeNames) const
attributeNames.emplace_back (kAttrAutoDragScrolling);
attributeNames.emplace_back (kAttrOverlayScrollbars);
attributeNames.emplace_back (kAttrScrollbarWidth);
attributeNames.emplace_back (kAttrMinScrollerSize);
attributeNames.emplace_back (kAttrBordered);
attributeNames.emplace_back (kAttrFollowFocusView);
return true;
Expand Down Expand Up @@ -155,6 +163,8 @@ auto ScrollViewCreator::getAttributeType (const string& attributeName) const ->
return kBooleanType;
if (attributeName == kAttrScrollbarWidth)
return kIntegerType;
if (attributeName == kAttrMinScrollerSize)
return kIntegerType;
if (attributeName == kAttrBordered)
return kBooleanType;
if (attributeName == kAttrFollowFocusView)
Expand Down Expand Up @@ -199,6 +209,11 @@ bool ScrollViewCreator::getAttributeValue (CView* view, const string& attributeN
colorToString (scrollbar->getScrollerColor (), stringValue, desc);
return true;
}
if (attributeName == kAttrMinScrollerSize)
{
stringValue = UIAttributes::doubleToString (scrollbar->getMinScrollerLength ());
return true;
}
}
if (attributeName == kAttrHorizontalScrollbar)
{
Expand Down

0 comments on commit b55ef07

Please sign in to comment.