From beacca2ed7b9f4df4941e6c24fee5bd7d2aa735f Mon Sep 17 00:00:00 2001 From: Brice DAVIER Date: Sun, 24 Jan 2021 14:03:21 +0900 Subject: [PATCH 1/2] Prevent ImageBundles from causing constant layout recalculations --- crates/bevy_ui/src/widget/image.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 051a38769f3ca..09b71e681ff60 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -27,10 +27,13 @@ pub fn image_node_system( .and_then(|material| material.texture.as_ref()) .and_then(|texture_handle| textures.get(texture_handle)) { - calculated_size.size = Size { + let size = Size { width: texture.size.width as f32, height: texture.size.height as f32, }; + if size != calculated_size.size { + calculated_size.size = size; + } } } } From a1fa689c2a5bb1a9e6af989e3f0b935d33328c86 Mon Sep 17 00:00:00 2001 From: Brice DAVIER Date: Mon, 25 Jan 2021 13:28:10 +0900 Subject: [PATCH 2/2] Add comment of intent --- crates/bevy_ui/src/widget/image.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 09b71e681ff60..14a84484fb18b 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -31,6 +31,7 @@ pub fn image_node_system( width: texture.size.width as f32, height: texture.size.height as f32, }; + // Update only if size has changed to avoid needless layout calculations if size != calculated_size.size { calculated_size.size = size; }