From 343a52a78967eb3394c836137e399bd6baf62804 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 3 Dec 2024 19:39:45 +0000 Subject: [PATCH] Remove the `min` and `max` fields from `LayoutContext`. (#16459) # Objective Remove the `min` and `max` fields from `LayoutContext`. It doesn't seem useful to cache these values, it's simpler just to call `min_element` and `max_element` on the `physical_size` field. ## Migration Guide The `min` and `max` fields have been removed from `LayoutContext`. To retrieve these values call `min_element` and `max_element` on `LayoutContent::physical_size` instead. --- crates/bevy_ui/src/layout/convert.rs | 12 ++++++------ crates/bevy_ui/src/layout/mod.rs | 8 -------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/bevy_ui/src/layout/convert.rs b/crates/bevy_ui/src/layout/convert.rs index 42aaa77f73..079e73bb49 100644 --- a/crates/bevy_ui/src/layout/convert.rs +++ b/crates/bevy_ui/src/layout/convert.rs @@ -20,12 +20,12 @@ impl Val { Val::Px(value) => { taffy::style::LengthPercentageAuto::Length(context.scale_factor * value) } - Val::VMin(value) => { - taffy::style::LengthPercentageAuto::Length(context.min_size * value / 100.) - } - Val::VMax(value) => { - taffy::style::LengthPercentageAuto::Length(context.max_size * value / 100.) - } + Val::VMin(value) => taffy::style::LengthPercentageAuto::Length( + context.physical_size.min_element() * value / 100., + ), + Val::VMax(value) => taffy::style::LengthPercentageAuto::Length( + context.physical_size.max_element() * value / 100., + ), Val::Vw(value) => { taffy::style::LengthPercentageAuto::Length(context.physical_size.x * value / 100.) } diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index ca077a9e56..99d1f37693 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -33,24 +33,18 @@ pub(crate) mod ui_surface; pub struct LayoutContext { pub scale_factor: f32, pub physical_size: Vec2, - pub min_size: f32, - pub max_size: f32, } impl LayoutContext { pub const DEFAULT: Self = Self { scale_factor: 1.0, physical_size: Vec2::ZERO, - min_size: 0.0, - max_size: 0.0, }; /// create new a [`LayoutContext`] from the window's physical size and scale factor fn new(scale_factor: f32, physical_size: Vec2) -> Self { Self { scale_factor, physical_size, - min_size: physical_size.x.min(physical_size.y), - max_size: physical_size.x.max(physical_size.y), } } } @@ -60,8 +54,6 @@ impl LayoutContext { pub const TEST_CONTEXT: Self = Self { scale_factor: 1.0, physical_size: Vec2::new(1000.0, 1000.0), - min_size: 0.0, - max_size: 1000.0, }; }