Ver código fonte

Layout engine: Clean up some headers and functions.

Michael Ragazzon 5 anos atrás
pai
commit
8cacf8d8c2

+ 10 - 10
Source/Core/LayoutDetails.cpp

@@ -154,10 +154,12 @@ void LayoutDetails::BuildBox(Box& box, float& min_height, float& max_height, Lay
 
 	BuildBox(box, containing_block, element, inline_element, override_shrink_to_fit_width);
 
-	GetMinMaxHeight(min_height, max_height, (element ? &element->GetComputedValues() : nullptr), box, containing_block.y);
+	if (element)
+		GetMinMaxHeight(min_height, max_height, element->GetComputedValues(), box, containing_block.y);
+	else
+		min_height = max_height = box.GetSize().y;
 }
 
-// Clamps the width of an element based from its min-width and max-width properties.
 float LayoutDetails::ClampWidth(float width, const ComputedValues& computed, const Box& box, float containing_block_width)
 {
 	float min_width = ResolveValue(computed.min_width, containing_block_width);
@@ -172,7 +174,6 @@ float LayoutDetails::ClampWidth(float width, const ComputedValues& computed, con
 	return Math::Clamp(width, min_width, max_width);
 }
 
-// Clamps the height of an element based from its min-height and max-height properties.
 float LayoutDetails::ClampHeight(float height, const ComputedValues& computed, const Box& box, float containing_block_height)
 {
 	float min_height = ResolveValue(computed.min_height, containing_block_height);
@@ -187,16 +188,15 @@ float LayoutDetails::ClampHeight(float height, const ComputedValues& computed, c
 	return Math::Clamp(height, min_height, max_height);
 }
 
-// Generates the box for an element placed in a block box.
-void LayoutDetails::GetMinMaxHeight(float& min_height, float& max_height, const ComputedValues* computed, const Box& box, float containing_block_height)
+void LayoutDetails::GetMinMaxHeight(float& min_height, float& max_height, const ComputedValues& computed, const Box& box, float containing_block_height)
 {
 	const float box_height = box.GetSize().y;
-	if (box_height < 0 && computed)
+	if (box_height < 0)
 	{
-		min_height = ResolveValue(computed->min_height, containing_block_height);
-		max_height = (computed->max_height.value < 0.f ? FLT_MAX : ResolveValue(computed->max_height, containing_block_height));
+		min_height = ResolveValue(computed.min_height, containing_block_height);
+		max_height = (computed.max_height.value < 0.f ? FLT_MAX : ResolveValue(computed.max_height, containing_block_height));
 
-		if (computed->box_sizing == Style::BoxSizing::BorderBox)
+		if (computed.box_sizing == Style::BoxSizing::BorderBox)
 		{
 			min_height = BorderHeightToContentHeight(min_height, box);
 			max_height = BorderHeightToContentHeight(max_height, box);
@@ -247,7 +247,7 @@ float LayoutDetails::GetShrinkToFitWidth(Element* element, Vector2f containing_b
 	Box box;
 	float min_height, max_height;
 	LayoutDetails::BuildBox(box, containing_block, element, false, containing_block.x);
-	LayoutDetails::GetMinMaxHeight(min_height, max_height, &element->GetComputedValues(), box, containing_block.y);
+	LayoutDetails::GetMinMaxHeight(min_height, max_height, element->GetComputedValues(), box, containing_block.y);
 
 	// First we need to format the element, then we get the shrink-to-fit width based on the largest line or box.
 	LayoutBlockBox containing_block_box(nullptr, nullptr, Box(containing_block), 0.0f, FLT_MAX);

+ 4 - 19
Source/Core/LayoutDetails.h

@@ -61,28 +61,13 @@ public:
 	/// @param[in] override_shrink_to_fit_width Provide a fixed shrink-to-fit width instead of formatting the element when its properties allow shrinking.
 	static void BuildBox(Box& box, float& min_height, float& max_height, LayoutBlockBox* containing_box, Element* element, bool inline_element, float override_shrink_to_fit_width = -1);
 
-	/// Clamps the width of an element based from its min-width and max-width properties.
-	/// @param[in] width The width to clamp.
-	/// @param[in] element The element to read the properties from.
-	/// @param[in] box The box to base the calculations on.
-	/// @param[in] containing_block_width The width of the element's containing block.
-	/// @return The clamped width.
+	// Returns the clamped width based on the min-/max-width and box-sizing computed values.
 	static float ClampWidth(float width, const ComputedValues& computed, const Box& box, float containing_block_width);
-	/// Clamps the height of an element based from its min-height and max-height properties.
-	/// @param[in] height The height to clamp.
-	/// @param[in] element The element to read the properties from.
-	/// @param[in] box The box to base the calculations on.
-	/// @param[in] containing_block_height The height of the element's containing block.
-	/// @return The clamped height.
+	// Returns the clamped height based on the min-/max-height and box-sizing computed values.
 	static float ClampHeight(float height, const ComputedValues& computed, const Box& box, float containing_block_height);
 
-	/// Retrieves the minimum and maximum height of an element's box.
-	/// @param[out] min_height The minimum height of the element's box.
-	/// @param[out] max_height The maximum height of the element's box.
-	/// @param[in] computed The computed values to get the min/max-height values, or nullptr.
-	/// @param[in] box The box to base the calculations on.
-	/// @param[in] containing_block_height The height of the element's containing block.
-	static void GetMinMaxHeight(float& min_height, float& max_height, const ComputedValues* computed, const Box& box, float containing_block_height);
+	// Retrieves the minimum and maximum height from on an element's computed values if the box has an indefinite height.
+	static void GetMinMaxHeight(float& min_height, float& max_height, const ComputedValues& computed, const Box& box, float containing_block_height);
 
 	/// Returns the fully-resolved, fixed-width and -height containing block from a block box.
 	/// @param[in] containing_box The leaf box.

+ 5 - 4
Source/Core/LayoutEngine.cpp

@@ -36,6 +36,7 @@
 #include "../../Include/RmlUi/Core/Profiling.h"
 #include "../../Include/RmlUi/Core/Types.h"
 #include <cstddef>
+#include <float.h>
 
 namespace Rml {
 
@@ -50,7 +51,7 @@ struct LayoutChunk
 static Pool< LayoutChunk > layout_chunk_pool(200, true);
 
 // Formats the contents for a root-level element (usually a document or floating element).
-void LayoutEngine::FormatElement(Element* element, Vector2f containing_block, const Box* override_initial_box, Vector2f* visible_overflow_size)
+void LayoutEngine::FormatElement(Element* element, Vector2f containing_block, const Box* override_initial_box, Vector2f* out_visible_overflow_size)
 {
 	RMLUI_ASSERT(element && containing_block.x >= 0 && containing_block.y >= 0);
 #ifdef RMLUI_ENABLE_PROFILING
@@ -68,7 +69,7 @@ void LayoutEngine::FormatElement(Element* element, Vector2f containing_block, co
 		LayoutDetails::BuildBox(box, containing_block, element, false);
 
 	float min_height, max_height;
-	LayoutDetails::GetMinMaxHeight(min_height, max_height, &element->GetComputedValues(), box, containing_block.y);
+	LayoutDetails::GetMinMaxHeight(min_height, max_height, element->GetComputedValues(), box, containing_block.y);
 
 	LayoutBlockBox* block_context_box = containing_block_box.AddBlockElement(element, box, min_height, max_height);
 
@@ -86,8 +87,8 @@ void LayoutEngine::FormatElement(Element* element, Vector2f containing_block, co
 
 	block_context_box->CloseAbsoluteElements();
 
-	if (visible_overflow_size)
-		*visible_overflow_size = block_context_box->GetVisibleOverflowSize();
+	if (out_visible_overflow_size)
+		*out_visible_overflow_size = block_context_box->GetVisibleOverflowSize();
 
 	element->OnLayout();
 }

+ 2 - 1
Source/Core/LayoutEngine.h

@@ -47,7 +47,8 @@ public:
 	/// @param[in] element The element to lay out.
 	/// @param[in] containing_block The size of the containing block.
 	/// @param[in] override_initial_box Optional pointer to a box to override the generated box for the element.
-	static void FormatElement(Element* element, Vector2f containing_block, const Box* override_initial_box = nullptr, Vector2f* visible_overflow_size = nullptr);
+	/// @param[out] visible_overflow_size Optionally output the overflow size of the element.
+	static void FormatElement(Element* element, Vector2f containing_block, const Box* override_initial_box = nullptr, Vector2f* out_visible_overflow_size = nullptr);
 
 	/// Positions a single element and its children within a block formatting context.
 	/// @param[in] block_context_box The open block box to layout the element in.

+ 2 - 1
Source/Core/LayoutTable.cpp

@@ -34,6 +34,7 @@
 #include "../../Include/RmlUi/Core/Types.h"
 #include <cstddef>
 #include <algorithm>
+#include <float.h>
 
 namespace Rml {
 
@@ -115,7 +116,7 @@ LayoutTable::CloseResult LayoutTable::FormatTable(LayoutBlockBox* table_block_co
 		Box row_box;
 		float row_min_height, row_max_height;
 		LayoutDetails::BuildBox(row_box, table_initial_content_size, element_row, false, 0.f);
-		LayoutDetails::GetMinMaxHeight(row_min_height, row_max_height, &computed_row, row_box, table_initial_content_size.y);
+		LayoutDetails::GetMinMaxHeight(row_min_height, row_max_height, computed_row, row_box, table_initial_content_size.y);
 
 		const Vector2f row_element_offset = table_cursor + Vector2f(0.0f, table_gap.y) + Vector2f(row_box.GetEdge(Box::MARGIN, Box::LEFT), row_box.GetEdge(Box::MARGIN, Box::TOP));