Browse Source

Make Element::IsReplaced virtual

This way, we no longer have to get the intrinsic dimensions just to determine whether the element is replaced. This can save some time e.g. from an image being loaded to retrieve its dimensions.
Michael Ragazzon 6 months ago
parent
commit
7047e36285

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

@@ -180,7 +180,7 @@ public:
 	virtual bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio);
 	virtual bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio);
 	/// Returns true if the element is replaced, thereby handling its own rendering.
 	/// Returns true if the element is replaced, thereby handling its own rendering.
 	/// @return True if the element is a replaced element.
 	/// @return True if the element is a replaced element.
-	bool IsReplaced();
+	virtual bool IsReplaced();
 
 
 	/// Checks if a given point in screen coordinates lies within the bordered area of this element.
 	/// Checks if a given point in screen coordinates lies within the bordered area of this element.
 	/// @param[in] point The point to test.
 	/// @param[in] point The point to test.

+ 3 - 0
Include/RmlUi/Lottie/ElementLottie.h

@@ -50,6 +50,9 @@ public:
 	/// Returns the element's inherent size.
 	/// Returns the element's inherent size.
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 
 
+	/// Returns true if the element is replaced.
+	bool IsReplaced() override;
+
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	void EnsureSourceLoaded();
 	void EnsureSourceLoaded();
 
 

+ 3 - 0
Include/RmlUi/SVG/ElementSVG.h

@@ -47,6 +47,9 @@ public:
 	/// Returns the element's inherent size.
 	/// Returns the element's inherent size.
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 
 
+	/// Returns true if the element is replaced.
+	bool IsReplaced() override;
+
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	void EnsureSourceLoaded();
 	void EnsureSourceLoaded();
 
 

+ 6 - 0
Source/Core/Elements/ElementImage.cpp

@@ -93,6 +93,12 @@ bool ElementImage::GetIntrinsicDimensions(Vector2f& _dimensions, float& _ratio)
 
 
 	return true;
 	return true;
 }
 }
+
+bool ElementImage::IsReplaced()
+{
+	return true;
+}
+
 void ElementImage::EnsureSourceLoaded()
 void ElementImage::EnsureSourceLoaded()
 {
 {
 	if (texture_dirty)
 	if (texture_dirty)

+ 3 - 0
Source/Core/Elements/ElementImage.h

@@ -74,6 +74,9 @@ public:
 	/// Returns the element's inherent size.
 	/// Returns the element's inherent size.
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 	bool GetIntrinsicDimensions(Vector2f& dimensions, float& ratio) override;
 
 
+	/// Returns true if the element is replaced.
+	bool IsReplaced() override;
+
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	/// Loads the current source file if needed. This normally happens automatically during layouting.
 	void EnsureSourceLoaded();
 	void EnsureSourceLoaded();
 
 

+ 5 - 0
Source/Lottie/ElementLottie.cpp

@@ -56,6 +56,11 @@ bool ElementLottie::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 	return true;
 	return true;
 }
 }
 
 
+bool ElementLottie::IsReplaced()
+{
+	return true;
+}
+
 void ElementLottie::EnsureSourceLoaded()
 void ElementLottie::EnsureSourceLoaded()
 {
 {
 	if (animation_dirty)
 	if (animation_dirty)

+ 5 - 0
Source/SVG/ElementSVG.cpp

@@ -61,6 +61,11 @@ bool ElementSVG::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 	return true;
 	return true;
 }
 }
 
 
+bool ElementSVG::IsReplaced()
+{
+	return true;
+}
+
 void ElementSVG::EnsureSourceLoaded()
 void ElementSVG::EnsureSourceLoaded()
 {
 {
 	UpdateCachedData();
 	UpdateCachedData();