diff --git a/Include/RmlUi/Core/ElementScroll.h b/Include/RmlUi/Core/ElementScroll.h index 9f428ffdb..1e96bfcc9 100644 --- a/Include/RmlUi/Core/ElementScroll.h +++ b/Include/RmlUi/Core/ElementScroll.h @@ -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(); diff --git a/Source/Core/Element.cpp b/Source/Core/Element.cpp index e225e69f6..5c59b033f 100644 --- a/Source/Core/Element.cpp +++ b/Source/Core/Element.cpp @@ -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() diff --git a/Source/Core/ElementScroll.cpp b/Source/Core/ElementScroll.cpp index 85f598296..2f61d716c 100644 --- a/Source/Core/ElementScroll.cpp +++ b/Source/Core/ElementScroll.cpp @@ -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)