From 5edf2d2395508e856a420f7fe9bc7ad85a2aba11 Mon Sep 17 00:00:00 2001 From: davier Date: Mon, 25 Jan 2021 05:00:20 +0000 Subject: [PATCH] Prevent ImageBundles from causing constant layout recalculations (#1299) Prevent ImageBundles from causing constant layout recalculations --- crates/bevy_ui/src/widget/image.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 051a38769f3ca..14a84484fb18b 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -27,10 +27,14 @@ 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, }; + // Update only if size has changed to avoid needless layout calculations + if size != calculated_size.size { + calculated_size.size = size; + } } } }