mirror of
https://github.com/bevyengine/bevy
synced 2024-12-19 17:43:07 +00:00
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:
parent
9d142a8025
commit
343a52a789
2 changed files with 6 additions and 14 deletions
|
@ -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.)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue