Browse Source

Add a margin for floating-point imprecision when deciding whether or not to clip overflowing content. Remove unnecessary caching of clip state.

Michael Ragazzon 5 years ago
parent
commit
ddf2e41447

+ 1 - 6
Include/RmlUi/Core/Element.h

@@ -141,7 +141,7 @@ public:
 	/// this element's logical children, plus the element's padding.
 	/// @param[in] content_offset The offset of the box's internal content.
 	/// @param[in] content_box The dimensions of the box's internal content.
-	void SetContentBox(const Vector2f& content_offset, const Vector2f& content_box);
+	void SetContentBox(Vector2f content_offset, Vector2f content_box);
 	/// Sets the box describing the size of the element, and removes all others.
 	/// @param[in] box The new dimensions box for the element.
 	void SetBox(const Box& box);
@@ -738,11 +738,6 @@ private:
 
 	bool computed_values_are_default_initialized;
 
-	// Cached rendering information
-	int clipping_ignore_depth;
-	bool clipping_enabled;
-	bool clipping_state_dirty;
-
 	// Transform state
 	UniquePtr< TransformState > transform_state;
 	bool dirty_transform;

+ 4 - 34
Source/Core/Element.cpp

@@ -144,10 +144,6 @@ transform_state(), dirty_transform(false), dirty_perspective(false), dirty_anima
 
 	computed_values_are_default_initialized = true;
 
-	clipping_ignore_depth = 0;
-	clipping_enabled = false;
-	clipping_state_dirty = true;
-
 	meta = element_meta_chunk_pool.AllocateAndConstruct(this);
 	data_model = nullptr;
 }
@@ -469,7 +465,7 @@ Box::Area Element::GetClientArea() const
 }
 
 // Sets the dimensions of the element's internal content.
-void Element::SetContentBox(const Vector2f& _content_offset, const Vector2f& _content_box)
+void Element::SetContentBox(Vector2f _content_offset, Vector2f _content_box)
 {
 	if (content_offset != _content_offset ||
 		content_box != _content_box)
@@ -1583,31 +1579,13 @@ DataModel* Element::GetDataModel() const
 	
 int Element::GetClippingIgnoreDepth()
 {
-	if (clipping_state_dirty)
-	{
-		IsClippingEnabled();
-	}
-	
-	return clipping_ignore_depth;
+	return GetComputedValues().clip.number;
 }
 	
 bool Element::IsClippingEnabled()
 {
-	if (clipping_state_dirty)
-	{
-		const auto& computed = GetComputedValues();
-
-		// Is clipping enabled for this element, yes unless both overlow properties are set to visible
-		clipping_enabled = computed.overflow_x != Style::Overflow::Visible
-							|| computed.overflow_y != Style::Overflow::Visible;
-		
-		// Get the clipping ignore depth from the clip property
-		clipping_ignore_depth = computed.clip.number;
-
-		clipping_state_dirty = false;
-	}
-	
-	return clipping_enabled;
+	const auto& computed = GetComputedValues();
+	return computed.overflow_x != Style::Overflow::Visible || computed.overflow_y != Style::Overflow::Visible;
 }
 
 // Gets the render interface owned by this element's context.
@@ -1830,14 +1808,6 @@ void Element::OnPropertyChange(const PropertyIdSet& changed_properties)
 	{
 		meta->decoration.DirtyDecorators();
 	}
-	
-	// Check for clipping state changes
-	if (changed_properties.Contains(PropertyId::Clip) ||
-		changed_properties.Contains(PropertyId::OverflowX) ||
-		changed_properties.Contains(PropertyId::OverflowY))
-	{
-		clipping_state_dirty = true;
-	}
 
 	// Check for `perspective' and `perspective-origin' changes
 	if (changed_properties.Contains(PropertyId::Perspective) ||

+ 2 - 2
Source/Core/ElementUtilities.cpp

@@ -198,8 +198,8 @@ bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_d
 		if (num_ignored_clips == 0 && clipping_element->IsClippingEnabled())
 		{
 			// Ignore nodes that don't clip.
-			if (clipping_element->GetClientWidth() < clipping_element->GetScrollWidth()
-				|| clipping_element->GetClientHeight() < clipping_element->GetScrollHeight())
+			if (clipping_element->GetClientWidth() < clipping_element->GetScrollWidth() - 0.5f
+				|| clipping_element->GetClientHeight() < clipping_element->GetScrollHeight() - 0.5f)
 			{
 				Vector2f element_origin_f = clipping_element->GetAbsoluteOffset(Box::PADDING);
 				Vector2f element_dimensions_f = clipping_element->GetBox().GetSize(Box::PADDING);

+ 2 - 2
Source/Core/LayoutBlockBox.cpp

@@ -219,7 +219,7 @@ LayoutBlockBox::CloseResult LayoutBlockBox::Close()
 		// If our content is larger than our window, we can enable the horizontal scrollbar if
 		// we're set to auto-scrollbars. If we're set to always use scrollbars, then the horiontal
 		// scrollbar will already have been enabled in the constructor.
-		if (content_box.x > box.GetSize().x)
+		if (content_box.x > box.GetSize().x + 0.5f)
 		{
 			if (overflow_x_property == Style::Overflow::Auto)
 			{
@@ -724,7 +724,7 @@ bool LayoutBlockBox::CatchVerticalOverflow(float cursor)
 		box_height >= 0 &&
 		overflow_y_property == Style::Overflow::Auto)
 	{
-		if (cursor > box_height - element->GetElementScroll()->GetScrollbarSize(ElementScroll::HORIZONTAL))
+		if (cursor > box_height - element->GetElementScroll()->GetScrollbarSize(ElementScroll::HORIZONTAL) + 0.5f)
 		{
 			RMLUI_ZoneScopedC(0xDD3322);
 			vertical_overflow = true;