Browse Source

Add methods to media elements to manually trigger loading of source files, see #763

This helps when using such elements in the hidden DOM with custom layout, since they normally expect automatic layouting.
Michael Ragazzon 7 months ago
parent
commit
38dd25c45c

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

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

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

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

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

@@ -50,9 +50,7 @@ ElementImage::~ElementImage() {}
 
 bool ElementImage::GetIntrinsicDimensions(Vector2f& _dimensions, float& _ratio)
 {
-	// Check if we need to reload the texture.
-	if (texture_dirty)
-		LoadTexture();
+	EnsureSourceLoaded();
 
 	// Calculate the x dimension.
 	if (HasAttribute("width"))
@@ -79,6 +77,11 @@ bool ElementImage::GetIntrinsicDimensions(Vector2f& _dimensions, float& _ratio)
 
 	return true;
 }
+void ElementImage::EnsureSourceLoaded()
+{
+	if (texture_dirty)
+		LoadTexture();
+}
 
 void ElementImage::OnRender()
 {

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

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

+ 7 - 3
Source/Lottie/ElementLottie.cpp

@@ -47,8 +47,7 @@ ElementLottie::~ElementLottie() {}
 
 bool ElementLottie::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 {
-	if (animation_dirty)
-		LoadAnimation();
+	EnsureSourceLoaded();
 
 	dimensions = intrinsic_dimensions;
 	if (dimensions.y > 0)
@@ -57,10 +56,15 @@ bool ElementLottie::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 	return true;
 }
 
-void ElementLottie::OnUpdate()
+void ElementLottie::EnsureSourceLoaded()
 {
 	if (animation_dirty)
 		LoadAnimation();
+}
+
+void ElementLottie::OnUpdate()
+{
+	EnsureSourceLoaded();
 
 	if (!animation)
 		return;

+ 7 - 2
Source/SVG/ElementSVG.cpp

@@ -48,8 +48,7 @@ ElementSVG::~ElementSVG() {}
 
 bool ElementSVG::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 {
-	if (source_dirty)
-		LoadSource();
+	EnsureSourceLoaded();
 
 	dimensions = intrinsic_dimensions;
 
@@ -68,6 +67,12 @@ bool ElementSVG::GetIntrinsicDimensions(Vector2f& dimensions, float& ratio)
 	return true;
 }
 
+void ElementSVG::EnsureSourceLoaded()
+{
+	if (source_dirty)
+		LoadSource();
+}
+
 void ElementSVG::OnRender()
 {
 	if (svg_document)