Add scroll region parameter to disable right margin

In case that a margin on the right side already exists, this allows creating a symmetric margin around the scrollbar.
This commit is contained in:
Robert Müller 2023-06-06 23:44:59 +02:00
parent f16974d1a9
commit 09835ed342
2 changed files with 11 additions and 4 deletions

View file

@ -34,11 +34,16 @@ void CScrollRegion::Begin(CUIRect *pClipRect, vec2 *pOutOffset, const CScrollReg
const bool ContentOverflows = m_ContentH > pClipRect->h;
const bool ForceShowScrollbar = m_Params.m_Flags & CScrollRegionParams::FLAG_CONTENT_STATIC_WIDTH;
const bool HasScrollBar = ContentOverflows || ForceShowScrollbar;
CUIRect ScrollBarBg;
bool HasScrollBar = ContentOverflows || ForceShowScrollbar;
CUIRect *pModifyRect = HasScrollBar ? pClipRect : nullptr;
pClipRect->VSplitRight(m_Params.m_ScrollbarWidth, pModifyRect, &ScrollBarBg);
ScrollBarBg.Margin(m_Params.m_ScrollbarMargin, &m_RailRect);
pClipRect->VSplitRight(m_Params.m_ScrollbarWidth, HasScrollBar ? pClipRect : nullptr, &ScrollBarBg);
if(m_Params.m_ScrollbarNoMarginRight)
{
ScrollBarBg.HMargin(m_Params.m_ScrollbarMargin, &m_RailRect);
m_RailRect.VSplitLeft(m_Params.m_ScrollbarMargin, nullptr, &m_RailRect);
}
else
ScrollBarBg.Margin(m_Params.m_ScrollbarMargin, &m_RailRect);
// only show scrollbar if required
if(HasScrollBar)

View file

@ -10,6 +10,7 @@ struct CScrollRegionParams
bool m_Active;
float m_ScrollbarWidth;
float m_ScrollbarMargin;
bool m_ScrollbarNoMarginRight;
float m_SliderMinHeight;
float m_ScrollUnit;
ColorRGBA m_ClipBgColor;
@ -30,6 +31,7 @@ struct CScrollRegionParams
m_Active = true;
m_ScrollbarWidth = 20.0f;
m_ScrollbarMargin = 5.0f;
m_ScrollbarNoMarginRight = false;
m_SliderMinHeight = 25.0f;
m_ScrollUnit = 10.0f;
m_ClipBgColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);