Browse Source

Allow disabling max-content layout caching, add body attribute `rmlui-disable-layout-cache` for disabling all layout caching on the document

Michael Ragazzon 5 months ago
parent
commit
9d388ccabf

+ 4 - 2
Source/Core/ElementDocument.cpp

@@ -532,6 +532,8 @@ void ElementDocument::UpdateLayout()
 		RMLUI_ZoneScoped;
 		RMLUI_ZoneText(source_url.c_str(), source_url.size());
 
+		const bool allow_layout_cache = !HasAttribute("rmlui-disable-layout-cache");
+
 		constexpr bool debug_logging = false;
 		if (debug_logging)
 			Log::Message(Log::LT_INFO, "UpdateLayout start: %s", GetAddress().c_str());
@@ -578,7 +580,7 @@ void ElementDocument::UpdateLayout()
 
 			// TODO: In some cases, we need to check if size changed, such that we need to do a layout update in its parent.
 			LayoutEngine::FormatElement(element, committed_layout->containing_block_size,
-				committed_layout->absolutely_positioning_containing_block_size);
+				committed_layout->absolutely_positioning_containing_block_size, allow_layout_cache);
 
 			// TODO: A bit ugly
 			element->UpdateRelativeOffsetFromInsetConstraints();
@@ -592,7 +594,7 @@ void ElementDocument::UpdateLayout()
 			if (Element* parent = GetParentNode())
 				containing_block = parent->GetBox().GetSize();
 
-			LayoutEngine::FormatElement(this, containing_block, containing_block);
+			LayoutEngine::FormatElement(this, containing_block, containing_block, allow_layout_cache);
 			// TODO: A bit ugly
 			this->UpdateRelativeOffsetFromInsetConstraints();
 		}

+ 1 - 0
Source/Core/Layout/ContainerBox.h

@@ -44,6 +44,7 @@ struct FormattingMode {
 
 	Constraint constraint = Constraint::None;
 	bool allow_format_independent_cache = true;
+	bool allow_max_content_cache = true;
 };
 
 /**

+ 4 - 3
Source/Core/Layout/FormattingContext.cpp

@@ -214,9 +214,10 @@ float FormattingContext::FormatFitContentHeight(ContainerBox* parent_container,
 		return box.GetSize().y;
 
 	LayoutNode* layout_node = element->GetLayoutNode();
+	const FormattingMode& parent_formatting_mode = parent_container->GetFormattingMode();
 
 	float max_content_height = box.GetSize().y;
-	if (Optional<float> cached_height = layout_node->GetMaxContentHeightIfCached())
+	if (Optional<float> cached_height = (parent_formatting_mode.allow_max_content_cache ? layout_node->GetMaxContentHeightIfCached() : std::nullopt))
 	{
 		max_content_height = *cached_height;
 	}
@@ -226,7 +227,7 @@ float FormattingContext::FormatFitContentHeight(ContainerBox* parent_container,
 		if (type == FormattingContextType::None)
 			type = FormattingContextType::Block;
 
-		FormattingMode formatting_mode = parent_container->GetFormattingMode();
+		FormattingMode formatting_mode = parent_formatting_mode;
 		formatting_mode.constraint = FormattingMode::Constraint::MaxContent;
 		const Vector2f root_containing_block(-1.f);
 		RootBox root(Box(root_containing_block), formatting_mode);
@@ -272,7 +273,7 @@ void FormattingContext::FormatFitContentWidth(Box& box, Element* element, Format
 	float max_content_width = -1.f;
 	bool from_cache = false;
 
-	if (Optional<float> cached_width = layout_node->GetMaxContentWidthIfCached())
+	if (Optional<float> cached_width = (parent_formatting_mode.allow_max_content_cache ? layout_node->GetMaxContentWidthIfCached() : std::nullopt))
 	{
 		max_content_width = *cached_width;
 		from_cache = true;

+ 1 - 1
Source/Core/Layout/LayoutEngine.cpp

@@ -39,7 +39,7 @@ void LayoutEngine::FormatElement(Element* element, Vector2f containing_block, Ve
 {
 	RMLUI_ASSERT(element && containing_block.x >= 0 && containing_block.y >= 0);
 
-	RootBox absolute_root(Box(absolutely_positioning_containing_block), FormattingMode{FormattingMode::Constraint::None, allow_cache});
+	RootBox absolute_root(Box(absolutely_positioning_containing_block), FormattingMode{FormattingMode::Constraint::None, allow_cache, allow_cache});
 	RootBox root(Box(containing_block), &absolute_root);
 
 	auto layout_box = FormattingContext::FormatIndependent(&root, element, nullptr, FormattingContextType::Block);