Skip to content

Commit

Permalink
Update scrollbar properties to ensure they appear or disappear on the…
Browse files Browse the repository at this point in the history
… same frame their visibility changed

Previously, the scrollbars could appear or disappear one frame late.
  • Loading branch information
mikke89 committed Oct 30, 2024
1 parent 514bd17 commit 22c360b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Include/RmlUi/Core/ElementScroll.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class RMLUICORE_API ElementScroll {
/// Formats the enabled scrollbars based on the current size of the host element.
void FormatScrollbars();

/// Updates the scrollbar elements to reflect their current state.
void UpdateProperties();

private:
struct Scrollbar {
Scrollbar();
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,11 @@ void Element::ClampScrollOffset()
scroll_offset = new_scroll_offset;
DirtyAbsoluteOffset();
}

// At this point the scrollbars have been resolved, both in terms of size and visibility. Update their properties
// now so that any visibility changes in particular are reflected immediately on the next render. Otherwise we risk
// that the scrollbars renders a frame late, since changes to scrollbars can happen during layouting.
meta->scroll.UpdateProperties();
}

void Element::ClampScrollOffsetRecursive()
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/ElementScroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ void ElementScroll::FormatScrollbars()
}
}

void ElementScroll::UpdateProperties()
{
for (Element* scroll_element : {scrollbars[VERTICAL].element, scrollbars[HORIZONTAL].element, corner})
{
if (scroll_element)
UpdateScrollElementProperties(scroll_element);
}
}

bool ElementScroll::CreateScrollbar(Orientation orientation)
{
if (scrollbars[orientation].element && scrollbars[orientation].widget)
Expand Down

0 comments on commit 22c360b

Please sign in to comment.