Browse Source

Update element properties when creating scrollbars.

Michael Ragazzon 6 years ago
parent
commit
c2a1469cc5

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

@@ -619,6 +619,8 @@ protected:
 private:
 private:
 	void SetParent(Element* parent);
 	void SetParent(Element* parent);
 
 
+	void UpdateProperties();
+
 	void DirtyOffset();
 	void DirtyOffset();
 	void UpdateOffset();
 	void UpdateOffset();
 
 
@@ -750,6 +752,7 @@ private:
 	friend class LayoutEngine;
 	friend class LayoutEngine;
 	friend class LayoutInlineBox;
 	friend class LayoutInlineBox;
 	friend struct ElementDeleter;
 	friend struct ElementDeleter;
+	friend class ElementScroll;
 };
 };
 
 
 }
 }

+ 30 - 24
Source/Core/Element.cpp

@@ -206,46 +206,52 @@ void Element::Update(float dp_ratio)
 	UpdateAnimation();
 	UpdateAnimation();
 	AdvanceAnimations();
 	AdvanceAnimations();
 
 
-	style->UpdateDefinition();
 	scroll->Update();
 	scroll->Update();
 
 
-	if(style->AnyPropertiesDirty())
+	UpdateProperties();
+
+	if (box_dirty)
+	{
+		box_dirty = false;
+		OnResize();
+	}
+
+	UpdateTransformState();
+
+	for (size_t i = 0; i < children.size(); i++)
+		children[i]->Update(dp_ratio);
+}
+
+
+void Element::UpdateProperties()
+{
+	style->UpdateDefinition();
+
+	if (style->AnyPropertiesDirty())
 	{
 	{
 		const ComputedValues* parent_values = nullptr;
 		const ComputedValues* parent_values = nullptr;
-		const ComputedValues* document_values = nullptr;
 		if (parent)
 		if (parent)
 			parent_values = &parent->GetComputedValues();
 			parent_values = &parent->GetComputedValues();
+
+		const ComputedValues* document_values = nullptr;
+		float dp_ratio = 1.0f;
 		if (auto doc = GetOwnerDocument())
 		if (auto doc = GetOwnerDocument())
+		{
 			document_values = &doc->GetComputedValues();
 			document_values = &doc->GetComputedValues();
+			if (Context * context = doc->GetContext())
+				dp_ratio = context->GetDensityIndependentPixelRatio();
+		}
 
 
 		// Compute values and clear dirty properties
 		// Compute values and clear dirty properties
-		auto dirty_properties = style->ComputeValues(element_meta->computed_values, parent_values, document_values, computed_values_are_default_initialized, dp_ratio);
+		PropertyIdSet dirty_properties = style->ComputeValues(element_meta->computed_values, parent_values, document_values, computed_values_are_default_initialized, dp_ratio);
 
 
 		computed_values_are_default_initialized = false;
 		computed_values_are_default_initialized = false;
 
 
 		// Computed values are just calculated and can safely be used in OnPropertyChange.
 		// Computed values are just calculated and can safely be used in OnPropertyChange.
 		// However, new properties set during this call will not be available until the next update loop.
 		// However, new properties set during this call will not be available until the next update loop.
-		// Enable RMLUI_DEBUG to get a warning when this happens.
-		if(!dirty_properties.Empty())
+		if (!dirty_properties.Empty())
 			OnPropertyChange(dirty_properties);
 			OnPropertyChange(dirty_properties);
-
-#ifdef RMLUI_DEBUG
-		if (style->AnyPropertiesDirty())
-			Log::Message(Log::LT_WARNING, "One or more properties were set during OnPropertyChange, these will only be evaluated on the next update call and should be avoided.");
-#endif
-	}
-
-
-	if (box_dirty)
-	{
-		box_dirty = false;
-		OnResize();
 	}
 	}
-
-	UpdateTransformState();
-
-	for (size_t i = 0; i < children.size(); i++)
-		children[i]->Update(dp_ratio);
 }
 }
 
 
 void Element::Render()
 void Element::Render()
@@ -1749,7 +1755,7 @@ void Element::OnAttributeChange(const ElementAttributes& changed_attributes)
 void Element::OnPropertyChange(const PropertyIdSet& changed_properties)
 void Element::OnPropertyChange(const PropertyIdSet& changed_properties)
 {
 {
 	const bool all_dirty = changed_properties.IsAllSet();
 	const bool all_dirty = changed_properties.IsAllSet();
-	
+
 	if (!IsLayoutDirty())
 	if (!IsLayoutDirty())
 	{
 	{
 		// Force a relayout if any of the changed properties require it.
 		// Force a relayout if any of the changed properties require it.

+ 4 - 1
Source/Core/ElementScroll.cpp

@@ -242,7 +242,10 @@ bool ElementScroll::CreateScrollbar(Orientation orientation)
 	scrollbars[orientation].widget = new WidgetSliderScroll(scrollbars[orientation].element);
 	scrollbars[orientation].widget = new WidgetSliderScroll(scrollbars[orientation].element);
 	scrollbars[orientation].widget->Initialise(orientation == VERTICAL ? WidgetSlider::VERTICAL : WidgetSlider::HORIZONTAL);
 	scrollbars[orientation].widget->Initialise(orientation == VERTICAL ? WidgetSlider::VERTICAL : WidgetSlider::HORIZONTAL);
 
 
-	element->AppendChild(std::move(scrollbar_element), false);
+	Element* child = element->AppendChild(std::move(scrollbar_element), false);
+
+	// The construction of scrollbars can occur during layouting, then we need some properties and computed values straight away.
+	child->UpdateProperties();
 
 
 	return true;
 	return true;
 }
 }

+ 0 - 2
Source/Core/LayoutInlineBox.h

@@ -46,8 +46,6 @@ class LayoutLineBox;
 
 
 class LayoutInlineBox
 class LayoutInlineBox
 {
 {
-friend class LayoutInlineBoxText;
-
 public:
 public:
 	/// Constructs a new inline box for an element.
 	/// Constructs a new inline box for an element.
 	/// @param element[in] The element this inline box is flowing.
 	/// @param element[in] The element this inline box is flowing.