Răsfoiți Sursa

Update scrollbar properties to ensure they appear or disappear on the same frame their visibility changed

Previously, the scrollbars could appear or disappear one frame late.
Michael Ragazzon 1 an în urmă
părinte
comite
b32980a0bd

+ 3 - 0
Include/RmlUi/Core/ElementScroll.h

@@ -77,6 +77,9 @@ public:
 	/// 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();

+ 5 - 0
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()

+ 9 - 0
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)