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.
This commit is contained in:
ickshonpe 2024-12-03 19:39:45 +00:00 committed by GitHub
parent 9d142a8025
commit 343a52a789
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 14 deletions

View file

@ -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.)
}

View file

@ -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,
};
}