diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index 7ebc0fd0cd30e..60e22f0e0b9ba 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -11,13 +11,12 @@ impl Val { Val::Auto => Val::Auto, Val::Percent(value) => Val::Percent(value), Val::Px(value) => Val::Px((scale_factor * value as f64) as f32), - Val::Undefined => Val::Undefined, } } fn to_inset(self) -> LengthPercentageAuto { match self { - Val::Auto | Val::Undefined => taffy::style::LengthPercentageAuto::Auto, + Val::Auto => taffy::style::LengthPercentageAuto::Auto, Val::Percent(value) => taffy::style::LengthPercentageAuto::Percent(value / 100.0), Val::Px(value) => taffy::style::LengthPercentageAuto::Points(value), } @@ -67,7 +66,7 @@ impl> From for taffy::prelude::Size { impl From for taffy::style::Dimension { fn from(value: Val) -> Self { match value { - Val::Auto | Val::Undefined => taffy::style::Dimension::Auto, + Val::Auto => taffy::style::Dimension::Auto, Val::Percent(value) => taffy::style::Dimension::Percent(value / 100.0), Val::Px(value) => taffy::style::Dimension::Points(value), } @@ -77,7 +76,7 @@ impl From for taffy::style::Dimension { impl From for taffy::style::LengthPercentage { fn from(value: Val) -> Self { match value { - Val::Auto | Val::Undefined => taffy::style::LengthPercentage::Points(0.0), + Val::Auto => taffy::style::LengthPercentage::Points(0.0), Val::Percent(value) => taffy::style::LengthPercentage::Percent(value / 100.0), Val::Px(value) => taffy::style::LengthPercentage::Points(value), } @@ -90,7 +89,6 @@ impl From for taffy::style::LengthPercentageAuto { Val::Auto => taffy::style::LengthPercentageAuto::Auto, Val::Percent(value) => taffy::style::LengthPercentageAuto::Percent(value / 100.0), Val::Px(value) => taffy::style::LengthPercentageAuto::Points(value), - Val::Undefined => taffy::style::LengthPercentageAuto::Points(0.), } } } @@ -106,10 +104,10 @@ pub fn from_style(scale_factor: f64, style: &Style) -> taffy::style::Style { align_content: Some(style.align_content.into()), justify_content: Some(style.justify_content.into()), inset: taffy::prelude::Rect { - left: style.position.left.scaled(scale_factor).to_inset(), - right: style.position.right.scaled(scale_factor).to_inset(), - top: style.position.top.scaled(scale_factor).to_inset(), - bottom: style.position.bottom.scaled(scale_factor).to_inset(), + left: style.left.scaled(scale_factor).to_inset(), + right: style.right.scaled(scale_factor).to_inset(), + top: style.top.scaled(scale_factor).to_inset(), + bottom: style.bottom.scaled(scale_factor).to_inset(), }, margin: style.margin.scaled(scale_factor).into(), padding: style.padding.scaled(scale_factor).into(), @@ -224,3 +222,190 @@ impl From for taffy::style::FlexWrap { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_convert_from() { + let bevy_style = crate::Style { + display: Display::Flex, + position_type: PositionType::Absolute, + left: Val::Px(0.), + right: Val::Percent(0.), + top: Val::Auto, + bottom: Val::Auto, + direction: crate::Direction::Inherit, + flex_direction: FlexDirection::ColumnReverse, + flex_wrap: FlexWrap::WrapReverse, + align_items: AlignItems::Baseline, + align_self: AlignSelf::Start, + align_content: AlignContent::SpaceAround, + justify_content: JustifyContent::SpaceEvenly, + margin: UiRect { + left: Val::Percent(0.), + right: Val::Px(0.), + top: Val::Auto, + bottom: Val::Auto, + }, + padding: UiRect { + left: Val::Percent(0.), + right: Val::Px(0.), + top: Val::Percent(0.), + bottom: Val::Percent(0.), + }, + border: UiRect { + left: Val::Px(0.), + right: Val::Px(0.), + top: Val::Auto, + bottom: Val::Px(0.), + }, + flex_grow: 1., + flex_shrink: 0., + flex_basis: Val::Px(0.), + size: Size { + width: Val::Px(0.), + height: Val::Auto, + }, + min_size: Size { + width: Val::Px(0.), + height: Val::Percent(0.), + }, + max_size: Size { + width: Val::Auto, + height: Val::Px(0.), + }, + aspect_ratio: None, + overflow: crate::Overflow::Hidden, + gap: Size { + width: Val::Px(0.), + height: Val::Percent(0.), + }, + }; + let taffy_style = from_style(1.0, &bevy_style); + assert_eq!(taffy_style.display, taffy::style::Display::Flex); + assert_eq!(taffy_style.position, taffy::style::Position::Absolute); + assert!(matches!( + taffy_style.inset.left, + taffy::style::LengthPercentageAuto::Points(_) + )); + assert!(matches!( + taffy_style.inset.right, + taffy::style::LengthPercentageAuto::Percent(_) + )); + assert!(matches!( + taffy_style.inset.top, + taffy::style::LengthPercentageAuto::Auto + )); + assert!(matches!( + taffy_style.inset.bottom, + taffy::style::LengthPercentageAuto::Auto + )); + assert_eq!( + taffy_style.flex_direction, + taffy::style::FlexDirection::ColumnReverse + ); + assert_eq!(taffy_style.flex_wrap, taffy::style::FlexWrap::WrapReverse); + assert_eq!( + taffy_style.align_items, + Some(taffy::style::AlignItems::Baseline) + ); + assert_eq!(taffy_style.align_self, Some(taffy::style::AlignSelf::Start)); + assert_eq!( + taffy_style.align_content, + Some(taffy::style::AlignContent::SpaceAround) + ); + assert_eq!( + taffy_style.justify_content, + Some(taffy::style::JustifyContent::SpaceEvenly) + ); + assert!(matches!( + taffy_style.margin.left, + taffy::style::LengthPercentageAuto::Percent(_) + )); + assert!(matches!( + taffy_style.margin.right, + taffy::style::LengthPercentageAuto::Points(_) + )); + assert!(matches!( + taffy_style.margin.top, + taffy::style::LengthPercentageAuto::Auto + )); + assert!(matches!( + taffy_style.margin.bottom, + taffy::style::LengthPercentageAuto::Auto + )); + assert!(matches!( + taffy_style.padding.left, + taffy::style::LengthPercentage::Percent(_) + )); + assert!(matches!( + taffy_style.padding.right, + taffy::style::LengthPercentage::Points(_) + )); + assert!(matches!( + taffy_style.padding.top, + taffy::style::LengthPercentage::Percent(_) + )); + assert!(matches!( + taffy_style.padding.bottom, + taffy::style::LengthPercentage::Percent(_) + )); + assert!(matches!( + taffy_style.border.left, + taffy::style::LengthPercentage::Points(_) + )); + assert!(matches!( + taffy_style.border.right, + taffy::style::LengthPercentage::Points(_) + )); + assert!(matches!( + taffy_style.border.top, + taffy::style::LengthPercentage::Points(_) + )); + assert!(matches!( + taffy_style.border.bottom, + taffy::style::LengthPercentage::Points(_) + )); + assert_eq!(taffy_style.flex_grow, 1.); + assert_eq!(taffy_style.flex_shrink, 0.); + assert!(matches!( + taffy_style.flex_basis, + taffy::style::Dimension::Points(_) + )); + assert!(matches!( + taffy_style.size.width, + taffy::style::Dimension::Points(_) + )); + assert!(matches!( + taffy_style.size.height, + taffy::style::Dimension::Auto + )); + assert!(matches!( + taffy_style.min_size.width, + taffy::style::Dimension::Points(_) + )); + assert!(matches!( + taffy_style.min_size.height, + taffy::style::Dimension::Percent(_) + )); + assert!(matches!( + taffy_style.max_size.width, + taffy::style::Dimension::Auto + )); + assert!(matches!( + taffy_style.max_size.height, + taffy::style::Dimension::Points(_) + )); + assert_eq!(taffy_style.aspect_ratio, None); + assert_eq!( + taffy_style.gap.width, + taffy::style::LengthPercentage::Points(0.) + ); + assert_eq!( + taffy_style.gap.height, + taffy::style::LengthPercentage::Percent(0.) + ); + } +} diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index fd90c711c993a..ac70c93834d32 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -2,83 +2,10 @@ use crate::Val; use bevy_reflect::Reflect; use std::ops::{Div, DivAssign, Mul, MulAssign}; -/// A type which is commonly used to define positions, margins, paddings and borders. +/// A type which is commonly used to define margins, paddings and borders. /// /// # Examples -/// -/// ## Position -/// -/// A position is used to determine where to place a UI element. -/// -/// ``` -/// # use bevy_ui::{UiRect, Val}; -/// # use bevy_utils::default; -/// # -/// let position = UiRect { -/// left: Val::Px(100.0), -/// top: Val::Px(50.0), -/// ..default() -/// }; -/// ``` -/// -/// If you define opposite sides of the position, the size of the UI element will automatically be calculated -/// if not explicitly specified. This means that if you have a [`Size`] that uses [`Val::Undefined`](crate::Val::Undefined) -/// as a width and height, the size would be determined by the window size and the values specified in the position. -/// -/// ``` -/// # use bevy_ui::{UiRect, Val}; -/// # -/// let position = UiRect { -/// left: Val::Px(100.0), -/// right: Val::Px(200.0), -/// top: Val::Px(300.0), -/// bottom: Val::Px(400.0), -/// }; -/// ``` -/// -/// To determine the width of the UI element you have to take the width of the window and subtract it by the -/// left and right values of the position. To determine the height of the UI element you have to take the height -/// of the window and subtract it by the top and bottom values of the position. If we had a window with a width -/// and height of 1000px, the UI element declared above would have a width of 700px and a height of 300px. -/// -/// ``` -/// // Size of the window -/// let window_width = 1000.0; -/// let window_height = 1000.0; -/// -/// // Values of the position -/// let left = 100.0; -/// let right = 200.0; -/// let top = 300.0; -/// let bottom = 400.0; -/// -/// // Calculation to get the size of the UI element -/// let ui_element_width = window_width - left - right; -/// let ui_element_height = window_height - top - bottom; -/// -/// assert_eq!(ui_element_width, 700.0); -/// assert_eq!(ui_element_height, 300.0); -/// ``` -/// -/// If you define a [`Size`] and also all four sides of the position, the top and left values of the position -/// are used to determine where to place the UI element. The size will not be calculated using the bottom and -/// right values of the position because the size of the UI element is already explicitly specified. -/// -/// ``` -/// # use bevy_ui::{UiRect, Size, Val, Style}; -/// # use bevy_utils::default; -/// # -/// let style = Style { -/// position: UiRect { // Defining all four sides -/// left: Val::Px(100.0), -/// right: Val::Px(200.0), -/// top: Val::Px(300.0), -/// bottom: Val::Px(400.0), -/// }, -/// size: Size::new(Val::Percent(100.0), Val::Percent(50.0)), // but also explicitly specifying a size -/// ..default() -/// }; -/// ``` + /// /// ## Margin /// @@ -134,10 +61,10 @@ pub struct UiRect { impl UiRect { pub const DEFAULT: Self = Self { - left: Val::DEFAULT, - right: Val::DEFAULT, - top: Val::DEFAULT, - bottom: Val::DEFAULT, + left: Val::Px(0.), + right: Val::Px(0.), + top: Val::Px(0.), + bottom: Val::Px(0.), }; /// Creates a new [`UiRect`] from the values specified. @@ -191,7 +118,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `left` and `right` take the given value. + /// Creates a new [`UiRect`] where `left` and `right` take the given value, + /// and `top` and `bottom` set to zero `Val::Px(0.)`. /// /// # Example /// @@ -202,8 +130,8 @@ impl UiRect { /// /// assert_eq!(ui_rect.left, Val::Px(10.0)); /// assert_eq!(ui_rect.right, Val::Px(10.0)); - /// assert_eq!(ui_rect.top, Val::Undefined); - /// assert_eq!(ui_rect.bottom, Val::Undefined); + /// assert_eq!(ui_rect.top, Val::Px(0.)); + /// assert_eq!(ui_rect.bottom, Val::Px(0.)); /// ``` pub fn horizontal(value: Val) -> Self { UiRect { @@ -213,7 +141,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `top` and `bottom` take the given value. + /// Creates a new [`UiRect`] where `top` and `bottom` take the given value, + /// and `left` and `right` are set to `Val::Px(0.)`. /// /// # Example /// @@ -222,8 +151,8 @@ impl UiRect { /// # /// let ui_rect = UiRect::vertical(Val::Px(10.0)); /// - /// assert_eq!(ui_rect.left, Val::Undefined); - /// assert_eq!(ui_rect.right, Val::Undefined); + /// assert_eq!(ui_rect.left, Val::Px(0.)); + /// assert_eq!(ui_rect.right, Val::Px(0.)); /// assert_eq!(ui_rect.top, Val::Px(10.0)); /// assert_eq!(ui_rect.bottom, Val::Px(10.0)); /// ``` @@ -235,7 +164,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `left` takes the given value. + /// Creates a new [`UiRect`] where `left` takes the given value, and + /// the other fields are set to `Val::Px(0.)`. /// /// # Example /// @@ -245,9 +175,9 @@ impl UiRect { /// let ui_rect = UiRect::left(Val::Px(10.0)); /// /// assert_eq!(ui_rect.left, Val::Px(10.0)); - /// assert_eq!(ui_rect.right, Val::Undefined); - /// assert_eq!(ui_rect.top, Val::Undefined); - /// assert_eq!(ui_rect.bottom, Val::Undefined); + /// assert_eq!(ui_rect.right, Val::Px(0.)); + /// assert_eq!(ui_rect.top, Val::Px(0.)); + /// assert_eq!(ui_rect.bottom, Val::Px(0.)); /// ``` pub fn left(value: Val) -> Self { UiRect { @@ -256,7 +186,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `right` takes the given value. + /// Creates a new [`UiRect`] where `right` takes the given value, + /// and the other fields are set to `Val::Px(0.)`. /// /// # Example /// @@ -265,10 +196,10 @@ impl UiRect { /// # /// let ui_rect = UiRect::right(Val::Px(10.0)); /// - /// assert_eq!(ui_rect.left, Val::Undefined); + /// assert_eq!(ui_rect.left, Val::Px(0.)); /// assert_eq!(ui_rect.right, Val::Px(10.0)); - /// assert_eq!(ui_rect.top, Val::Undefined); - /// assert_eq!(ui_rect.bottom, Val::Undefined); + /// assert_eq!(ui_rect.top, Val::Px(0.)); + /// assert_eq!(ui_rect.bottom, Val::Px(0.)); /// ``` pub fn right(value: Val) -> Self { UiRect { @@ -277,7 +208,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `top` takes the given value. + /// Creates a new [`UiRect`] where `top` takes the given value, + /// and the other fields are set to `Val::Px(0.)`. /// /// # Example /// @@ -286,10 +218,10 @@ impl UiRect { /// # /// let ui_rect = UiRect::top(Val::Px(10.0)); /// - /// assert_eq!(ui_rect.left, Val::Undefined); - /// assert_eq!(ui_rect.right, Val::Undefined); + /// assert_eq!(ui_rect.left, Val::Px(0.)); + /// assert_eq!(ui_rect.right, Val::Px(0.)); /// assert_eq!(ui_rect.top, Val::Px(10.0)); - /// assert_eq!(ui_rect.bottom, Val::Undefined); + /// assert_eq!(ui_rect.bottom, Val::Px(0.)); /// ``` pub fn top(value: Val) -> Self { UiRect { @@ -298,7 +230,8 @@ impl UiRect { } } - /// Creates a new [`UiRect`] where `bottom` takes the given value. + /// Creates a new [`UiRect`] where `bottom` takes the given value, + /// and the other fields are set to `Val::Px(0.)`. /// /// # Example /// @@ -307,9 +240,9 @@ impl UiRect { /// # /// let ui_rect = UiRect::bottom(Val::Px(10.0)); /// - /// assert_eq!(ui_rect.left, Val::Undefined); - /// assert_eq!(ui_rect.right, Val::Undefined); - /// assert_eq!(ui_rect.top, Val::Undefined); + /// assert_eq!(ui_rect.left, Val::Px(0.)); + /// assert_eq!(ui_rect.right, Val::Px(0.)); + /// assert_eq!(ui_rect.top, Val::Px(0.)); /// assert_eq!(ui_rect.bottom, Val::Px(10.0)); /// ``` pub fn bottom(value: Val) -> Self { @@ -376,7 +309,9 @@ impl Size { } } - /// Creates a new [`Size`] where `width` takes the given value and its `height` is `Val::Auto`. + /// Creates a new [`Size`] where `width` takes the given value, + /// and `height` is set to [`Val::Auto`]. + /// /// # Example /// @@ -395,7 +330,8 @@ impl Size { } } - /// Creates a new [`Size`] where `height` takes the given value and its `width` is `Val::Auto`. + /// Creates a new [`Size`] where `height` takes the given value, + /// and `width` is set to [`Val::Auto`]. /// /// # Example /// @@ -416,9 +352,6 @@ impl Size { /// Creates a Size where both values are [`Val::Auto`]. pub const AUTO: Self = Self::all(Val::Auto); - - /// Creates a Size where both values are [`Val::Undefined`]. - pub const UNDEFINED: Self = Self::all(Val::Undefined); } impl Default for Size { @@ -481,10 +414,10 @@ mod tests { assert_eq!( UiRect::default(), UiRect { - left: Val::Undefined, - right: Val::Undefined, - top: Val::Undefined, - bottom: Val::Undefined + left: Val::Px(0.), + right: Val::Px(0.), + top: Val::Px(0.), + bottom: Val::Px(0.) } ); assert_eq!(UiRect::default(), UiRect::DEFAULT); diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 52290aa3a5f56..2a28c5a1e508c 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -61,8 +61,6 @@ impl Default for Node { #[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)] #[reflect(PartialEq, Serialize, Deserialize)] pub enum Val { - /// No value defined - Undefined, /// Automatically determine this value Auto, /// Set this value in pixels @@ -72,7 +70,7 @@ pub enum Val { } impl Val { - pub const DEFAULT: Self = Self::Undefined; + pub const DEFAULT: Self = Self::Auto; } impl Default for Val { @@ -86,7 +84,6 @@ impl Mul for Val { fn mul(self, rhs: f32) -> Self::Output { match self { - Val::Undefined => Val::Undefined, Val::Auto => Val::Auto, Val::Px(value) => Val::Px(value * rhs), Val::Percent(value) => Val::Percent(value * rhs), @@ -97,7 +94,7 @@ impl Mul for Val { impl MulAssign for Val { fn mul_assign(&mut self, rhs: f32) { match self { - Val::Undefined | Val::Auto => {} + Val::Auto => {} Val::Px(value) | Val::Percent(value) => *value *= rhs, } } @@ -108,7 +105,6 @@ impl Div for Val { fn div(self, rhs: f32) -> Self::Output { match self { - Val::Undefined => Val::Undefined, Val::Auto => Val::Auto, Val::Px(value) => Val::Px(value / rhs), Val::Percent(value) => Val::Percent(value / rhs), @@ -119,7 +115,7 @@ impl Div for Val { impl DivAssign for Val { fn div_assign(&mut self, rhs: f32) { match self { - Val::Undefined | Val::Auto => {} + Val::Auto => {} Val::Px(value) | Val::Percent(value) => *value /= rhs, } } @@ -139,7 +135,7 @@ impl Val { /// When adding non-numeric [`Val`]s, it returns the value unchanged. pub fn try_add(&self, rhs: Val) -> Result { match (self, rhs) { - (Val::Undefined, Val::Undefined) | (Val::Auto, Val::Auto) => Ok(*self), + (Val::Auto, Val::Auto) => Ok(*self), (Val::Px(value), Val::Px(rhs_value)) => Ok(Val::Px(value + rhs_value)), (Val::Percent(value), Val::Percent(rhs_value)) => Ok(Val::Percent(value + rhs_value)), _ => Err(ValArithmeticError::NonIdenticalVariants), @@ -157,7 +153,7 @@ impl Val { /// When adding non-numeric [`Val`]s, it returns the value unchanged. pub fn try_sub(&self, rhs: Val) -> Result { match (self, rhs) { - (Val::Undefined, Val::Undefined) | (Val::Auto, Val::Auto) => Ok(*self), + (Val::Auto, Val::Auto) => Ok(*self), (Val::Px(value), Val::Px(rhs_value)) => Ok(Val::Px(value - rhs_value)), (Val::Percent(value), Val::Percent(rhs_value)) => Ok(Val::Percent(value - rhs_value)), _ => Err(ValArithmeticError::NonIdenticalVariants), @@ -236,6 +232,10 @@ pub struct Style { pub display: Display, /// Whether to arrange this node relative to other nodes, or positioned absolutely pub position_type: PositionType, + pub left: Val, + pub right: Val, + pub top: Val, + pub bottom: Val, /// Which direction the content of this node should go pub direction: Direction, /// Whether to use column or row layout @@ -252,8 +252,6 @@ pub struct Style { pub align_content: AlignContent, /// How items align according to the main axis pub justify_content: JustifyContent, - /// The position of the node as described by its Rect - pub position: UiRect, /// The amount of space around a node outside its border. /// /// If a percentage value is used, the percentage is calculated based on the width of the parent node. @@ -329,7 +327,7 @@ pub struct Style { pub overflow: Overflow, /// The size of the gutters between the rows and columns of the flexbox layout /// - /// Values of `Size::UNDEFINED` and `Size::AUTO` are treated as zero. + /// A value of `Size::AUTO` is treated as zero. pub gap: Size, } @@ -337,6 +335,10 @@ impl Style { pub const DEFAULT: Self = Self { display: Display::DEFAULT, position_type: PositionType::DEFAULT, + left: Val::Auto, + right: Val::Auto, + top: Val::Auto, + bottom: Val::Auto, direction: Direction::DEFAULT, flex_direction: FlexDirection::DEFAULT, flex_wrap: FlexWrap::DEFAULT, @@ -344,7 +346,6 @@ impl Style { align_self: AlignSelf::DEFAULT, align_content: AlignContent::DEFAULT, justify_content: JustifyContent::DEFAULT, - position: UiRect::DEFAULT, margin: UiRect::DEFAULT, padding: UiRect::DEFAULT, border: UiRect::DEFAULT, @@ -356,7 +357,7 @@ impl Style { max_size: Size::AUTO, aspect_ratio: None, overflow: Overflow::DEFAULT, - gap: Size::UNDEFINED, + gap: Size::AUTO, }; } @@ -769,12 +770,10 @@ mod tests { #[test] fn val_try_add() { - let undefined_sum = Val::Undefined.try_add(Val::Undefined).unwrap(); let auto_sum = Val::Auto.try_add(Val::Auto).unwrap(); let px_sum = Val::Px(20.).try_add(Val::Px(22.)).unwrap(); let percent_sum = Val::Percent(50.).try_add(Val::Percent(50.)).unwrap(); - assert_eq!(undefined_sum, Val::Undefined); assert_eq!(auto_sum, Val::Auto); assert_eq!(px_sum, Val::Px(42.)); assert_eq!(percent_sum, Val::Percent(100.)); @@ -791,12 +790,10 @@ mod tests { #[test] fn val_try_sub() { - let undefined_sum = Val::Undefined.try_sub(Val::Undefined).unwrap(); let auto_sum = Val::Auto.try_sub(Val::Auto).unwrap(); let px_sum = Val::Px(72.).try_sub(Val::Px(30.)).unwrap(); let percent_sum = Val::Percent(100.).try_sub(Val::Percent(50.)).unwrap(); - assert_eq!(undefined_sum, Val::Undefined); assert_eq!(auto_sum, Val::Auto); assert_eq!(px_sum, Val::Px(42.)); assert_eq!(percent_sum, Val::Percent(50.)); @@ -804,9 +801,8 @@ mod tests { #[test] fn different_variant_val_try_add() { - let different_variant_sum_1 = Val::Undefined.try_add(Val::Auto); - let different_variant_sum_2 = Val::Px(50.).try_add(Val::Percent(50.)); - let different_variant_sum_3 = Val::Percent(50.).try_add(Val::Undefined); + let different_variant_sum_1 = Val::Px(50.).try_add(Val::Percent(50.)); + let different_variant_sum_2 = Val::Percent(50.).try_add(Val::Auto); assert_eq!( different_variant_sum_1, @@ -816,17 +812,12 @@ mod tests { different_variant_sum_2, Err(ValArithmeticError::NonIdenticalVariants) ); - assert_eq!( - different_variant_sum_3, - Err(ValArithmeticError::NonIdenticalVariants) - ); } #[test] fn different_variant_val_try_sub() { - let different_variant_diff_1 = Val::Undefined.try_sub(Val::Auto); - let different_variant_diff_2 = Val::Px(50.).try_sub(Val::Percent(50.)); - let different_variant_diff_3 = Val::Percent(50.).try_sub(Val::Undefined); + let different_variant_diff_1 = Val::Px(50.).try_sub(Val::Percent(50.)); + let different_variant_diff_2 = Val::Percent(50.).try_sub(Val::Auto); assert_eq!( different_variant_diff_1, @@ -836,10 +827,6 @@ mod tests { different_variant_diff_2, Err(ValArithmeticError::NonIdenticalVariants) ); - assert_eq!( - different_variant_diff_3, - Err(ValArithmeticError::NonIdenticalVariants) - ); } #[test] @@ -861,10 +848,8 @@ mod tests { #[test] fn val_invalid_evaluation() { let size = 250.; - let evaluate_undefined = Val::Undefined.evaluate(size); let evaluate_auto = Val::Auto.evaluate(size); - assert_eq!(evaluate_undefined, Err(ValArithmeticError::NonEvaluateable)); assert_eq!(evaluate_auto, Err(ValArithmeticError::NonEvaluateable)); } @@ -906,10 +891,8 @@ mod tests { fn val_try_add_non_numeric_with_size() { let size = 250.; - let undefined_sum = Val::Undefined.try_add_with_size(Val::Undefined, size); let percent_sum = Val::Auto.try_add_with_size(Val::Auto, size); - assert_eq!(undefined_sum, Err(ValArithmeticError::NonEvaluateable)); assert_eq!(percent_sum, Err(ValArithmeticError::NonEvaluateable)); } @@ -924,4 +907,9 @@ mod tests { "the given variant of Val is not evaluateable (non-numeric)" ); } + + #[test] + fn default_val_equals_const_default_val() { + assert_eq!(Val::default(), Val::DEFAULT); + } } diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index a4464701fdcee..e3404575e8ee3 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -25,9 +25,7 @@ pub fn text_constraint(min_size: Val, size: Val, max_size: Val, scale_factor: f6 match (min_size, size, max_size) { (_, _, Val::Px(max)) => scale_value(max, scale_factor), (Val::Px(min), _, _) => scale_value(min, scale_factor), - (Val::Undefined, Val::Px(size), Val::Undefined) | (Val::Auto, Val::Px(size), Val::Auto) => { - scale_value(size, scale_factor) - } + (Val::Auto, Val::Px(size), Val::Auto) => scale_value(size, scale_factor), _ => f32::MAX, } } diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 825f4803bf439..3a7ae32a4d503 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -78,11 +78,8 @@ fn setup( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + bottom: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); diff --git a/examples/3d/atmospheric_fog.rs b/examples/3d/atmospheric_fog.rs index 1969303ff75bd..0bf6d52aba48d 100644 --- a/examples/3d/atmospheric_fog.rs +++ b/examples/3d/atmospheric_fog.rs @@ -101,11 +101,8 @@ fn setup_instructions(mut commands: Commands, asset_server: Res) { ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + bottom: Val::Px(10.0), + left: Val::Px(10.0), ..default() }),)); } diff --git a/examples/3d/blend_modes.rs b/examples/3d/blend_modes.rs index 5fe22dfc4a177..458b5a6582ebc 100644 --- a/examples/3d/blend_modes.rs +++ b/examples/3d/blend_modes.rs @@ -203,23 +203,16 @@ fn setup( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); commands.spawn(( TextBundle::from_section("", text_style).with_style(Style { - position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - right: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + right: Val::Px(10.0), ..default() }), ExampleDisplay, @@ -365,8 +358,8 @@ fn example_control_system( .world_to_viewport(camera_global_transform, world_position) .unwrap(); - style.position.bottom = Val::Px(viewport_position.y); - style.position.left = Val::Px(viewport_position.x); + style.bottom = Val::Px(viewport_position.y); + style.left = Val::Px(viewport_position.x); } let mut display = display.single_mut(); diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs index 94fcdf90fd789..92688846d73b7 100644 --- a/examples/3d/bloom_3d.rs +++ b/examples/3d/bloom_3d.rs @@ -106,11 +106,8 @@ fn setup_scene( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + bottom: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 745b828982ddd..3e0c74861909d 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -145,11 +145,8 @@ fn setup_instructions(mut commands: Commands, asset_server: Res) { ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + left: Val::Px(10.0), ..default() }),)); } diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index ccf34966d975d..a6deda72708f1 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -84,11 +84,8 @@ fn setup( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(20.0), - left: Val::Px(100.0), - ..default() - }, + top: Val::Px(20.0), + left: Val::Px(100.0), ..default() }), ); @@ -104,11 +101,8 @@ fn setup( ), style: Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(130.0), - right: Val::Px(0.0), - ..default() - }, + top: Val::Px(130.0), + right: Val::Px(0.0), ..default() }, transform: Transform { @@ -129,11 +123,8 @@ fn setup( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(20.0), - right: Val::Px(20.0), - ..default() - }, + bottom: Val::Px(20.0), + right: Val::Px(20.0), ..default() }), EnvironmentMapLabel, diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index 996f6cbe14758..81cd602b04578 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -76,11 +76,8 @@ fn setup( ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); diff --git a/examples/games/alien_cake_addict.rs b/examples/games/alien_cake_addict.rs index 138186acaa46b..7fbc2961c8a03 100644 --- a/examples/games/alien_cake_addict.rs +++ b/examples/games/alien_cake_addict.rs @@ -173,11 +173,8 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(5.0), - left: Val::Px(5.0), - ..default() - }, + top: Val::Px(5.0), + left: Val::Px(5.0), ..default() }), ); diff --git a/examples/games/breakout.rs b/examples/games/breakout.rs index bc308797fb3e5..d74822872f6a3 100644 --- a/examples/games/breakout.rs +++ b/examples/games/breakout.rs @@ -240,11 +240,8 @@ fn setup( ]) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: SCOREBOARD_TEXT_PADDING, - left: SCOREBOARD_TEXT_PADDING, - ..default() - }, + top: SCOREBOARD_TEXT_PADDING, + left: SCOREBOARD_TEXT_PADDING, ..default() }), ); diff --git a/examples/games/game_menu.rs b/examples/games/game_menu.rs index 64710c5e2aee7..8dc39e701df44 100644 --- a/examples/games/game_menu.rs +++ b/examples/games/game_menu.rs @@ -401,12 +401,8 @@ mod menu { // This takes the icons out of the flexbox flow, to be positioned exactly position_type: PositionType::Absolute, // The icon will be close to the left border of the button - position: UiRect { - left: Val::Px(10.0), - right: Val::Auto, - top: Val::Auto, - bottom: Val::Auto, - }, + left: Val::Px(10.0), + right: Val::Auto, ..default() }; let button_text_style = TextStyle { diff --git a/examples/input/text_input.rs b/examples/input/text_input.rs index 4263bfc42e6aa..e083f76d255de 100644 --- a/examples/input/text_input.rs +++ b/examples/input/text_input.rs @@ -78,11 +78,8 @@ fn setup_scene(mut commands: Commands, asset_server: Res) { ]) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index 366c933162e81..66ae6696765df 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -100,12 +100,10 @@ fn setup_scene( justify_content: JustifyContent::Center, align_items: AlignItems::Center, position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(50.0), - right: Val::Px(50.0), - top: Val::Auto, - bottom: Val::Px(50.0), - }, + left: Val::Px(50.0), + right: Val::Px(50.0), + top: Val::Auto, + bottom: Val::Px(50.0), ..default() }, ..default() diff --git a/examples/shader/shader_prepass.rs b/examples/shader/shader_prepass.rs index 9770d9f46a48e..0271977128a45 100644 --- a/examples/shader/shader_prepass.rs +++ b/examples/shader/shader_prepass.rs @@ -140,11 +140,8 @@ fn setup( ]) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(10.0), - left: Val::Px(10.0), - ..default() - }, + top: Val::Px(10.0), + left: Val::Px(10.0), ..default() }), ); diff --git a/examples/stress_tests/bevymark.rs b/examples/stress_tests/bevymark.rs index 876ef68fa54fe..e4131e029fb7a 100644 --- a/examples/stress_tests/bevymark.rs +++ b/examples/stress_tests/bevymark.rs @@ -121,11 +121,8 @@ fn setup(mut commands: Commands, asset_server: Res) { ]) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(5.0), - left: Val::Px(5.0), - ..default() - }, + top: Val::Px(5.0), + left: Val::Px(5.0), ..default() }), StatsText, diff --git a/examples/stress_tests/many_buttons.rs b/examples/stress_tests/many_buttons.rs index d39cfb38810e5..826aa5395c282 100644 --- a/examples/stress_tests/many_buttons.rs +++ b/examples/stress_tests/many_buttons.rs @@ -89,12 +89,8 @@ fn spawn_button( ButtonBundle { style: Style { size: Size::new(Val::Percent(width), Val::Percent(width)), - - position: UiRect { - bottom: Val::Percent(100.0 / total * i as f32), - left: Val::Percent(100.0 / total * j as f32), - ..default() - }, + bottom: Val::Percent(100.0 / total * i as f32), + left: Val::Percent(100.0 / total * j as f32), align_items: AlignItems::Center, position_type: PositionType::Absolute, ..default() diff --git a/examples/ui/font_atlas_debug.rs b/examples/ui/font_atlas_debug.rs index a732baca7c366..0ca5596d24323 100644 --- a/examples/ui/font_atlas_debug.rs +++ b/examples/ui/font_atlas_debug.rs @@ -49,11 +49,8 @@ fn atlas_render_system( image: texture_atlas.texture.clone().into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(0.0), - left: Val::Px(512.0 * x_offset), - ..default() - }, + top: Val::Px(0.0), + left: Val::Px(512.0 * x_offset), ..default() }, ..default() @@ -85,10 +82,7 @@ fn setup(mut commands: Commands, asset_server: Res, mut state: ResM background_color: Color::NONE.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(0.0), - ..default() - }, + bottom: Val::Px(0.0), ..default() }, ..default() diff --git a/examples/ui/text.rs b/examples/ui/text.rs index 3e73c847af3a9..607a204ec62a0 100644 --- a/examples/ui/text.rs +++ b/examples/ui/text.rs @@ -43,11 +43,8 @@ fn setup(mut commands: Commands, asset_server: Res) { // Set the style of the TextBundle itself. .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(5.0), - right: Val::Px(15.0), - ..default() - }, + bottom: Val::Px(5.0), + right: Val::Px(15.0), ..default() }), ColorText, diff --git a/examples/ui/text_debug.rs b/examples/ui/text_debug.rs index 286558bcbbc00..759ee88a669f4 100644 --- a/examples/ui/text_debug.rs +++ b/examples/ui/text_debug.rs @@ -37,11 +37,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { ) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(5.0), - left: Val::Px(15.0), - ..default() - }, + top: Val::Px(5.0), + left: Val::Px(15.0), ..default() }), ); @@ -56,15 +53,9 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { .with_text_alignment(TextAlignment::Center) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(5.0), - right: Val::Px(15.0), - ..default() - }, - max_size: Size { - width: Val::Px(400.), - height: Val::Undefined, - }, + top: Val::Px(5.0), + right: Val::Px(15.0), + max_size: Size::width(Val::Px(400.)), ..default() }) ); @@ -115,11 +106,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { ]) .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(5.0), - right: Val::Px(15.0), - ..default() - }, + bottom: Val::Px(5.0), + right: Val::Px(15.0), ..default() }), TextChanges, @@ -136,11 +124,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { .with_style(Style { align_self: AlignSelf::FlexEnd, position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(5.0), - left: Val::Px(15.0), - ..default() - }, + bottom: Val::Px(5.0), + left: Val::Px(15.0), size: Size { width: Val::Px(200.0), ..default() diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 954708c6335d9..827a75aa198ae 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -27,7 +27,7 @@ fn setup(mut commands: Commands, asset_server: Res) { commands .spawn(NodeBundle { style: Style { - size: Size::width(Val::Percent(100.0)), + size: Size::all(Val::Percent(100.)), justify_content: JustifyContent::SpaceBetween, ..default() }, @@ -38,8 +38,8 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(NodeBundle { style: Style { - size: Size::width(Val::Px(200.0)), - border: UiRect::all(Val::Px(2.0)), + size: Size::width(Val::Px(200.)), + border: UiRect::all(Val::Px(2.)), ..default() }, background_color: Color::rgb(0.65, 0.65, 0.65).into(), @@ -50,7 +50,7 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(NodeBundle { style: Style { - size: Size::width(Val::Percent(100.0)), + size: Size::width(Val::Percent(100.)), ..default() }, background_color: Color::rgb(0.15, 0.15, 0.15).into(), @@ -68,7 +68,7 @@ fn setup(mut commands: Commands, asset_server: Res) { }, ) .with_style(Style { - margin: UiRect::all(Val::Px(5.0)), + margin: UiRect::all(Val::Px(5.)), ..default() }), // Because this is a distinct label widget and @@ -85,7 +85,7 @@ fn setup(mut commands: Commands, asset_server: Res) { flex_direction: FlexDirection::Column, justify_content: JustifyContent::Center, align_items: AlignItems::Center, - size: Size::width(Val::Px(200.0)), + size: Size::width(Val::Px(200.)), ..default() }, background_color: Color::rgb(0.15, 0.15, 0.15).into(), @@ -101,11 +101,7 @@ fn setup(mut commands: Commands, asset_server: Res) { font_size: 25., color: Color::WHITE, }, - ) - .with_style(Style { - size: Size::height(Val::Px(25.)), - ..default() - }), + ), Label, )); // List with hidden overflow @@ -114,7 +110,7 @@ fn setup(mut commands: Commands, asset_server: Res) { style: Style { flex_direction: FlexDirection::Column, align_self: AlignSelf::Stretch, - size: Size::height(Val::Percent(50.0)), + size: Size::height(Val::Percent(50.)), overflow: Overflow::Hidden, ..default() }, @@ -129,7 +125,6 @@ fn setup(mut commands: Commands, asset_server: Res) { style: Style { flex_direction: FlexDirection::Column, flex_grow: 1.0, - max_size: Size::UNDEFINED, align_items: AlignItems::Center, ..default() }, @@ -153,7 +148,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ) .with_style(Style { flex_shrink: 0., - size: Size::new(Val::Undefined, Val::Px(20.)), + size: Size::height(Val::Px(20.)), ..default() }), Label, @@ -166,26 +161,23 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(NodeBundle { style: Style { - size: Size::new(Val::Px(200.0), Val::Px(200.0)), + size: Size::all(Val::Px(200.)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(210.0), - bottom: Val::Px(10.0), - ..default() - }, - border: UiRect::all(Val::Px(20.0)), + left: Val::Px(210.), + bottom: Val::Px(10.), + border: UiRect::all(Val::Px(20.)), ..default() }, - background_color: Color::rgb(0.4, 0.4, 1.0).into(), + background_color: Color::rgb(0.4, 0.4, 1.).into(), ..default() }) .with_children(|parent| { parent.spawn(NodeBundle { style: Style { - size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), + size: Size::all(Val::Percent(100.)), ..default() }, - background_color: Color::rgb(0.8, 0.8, 1.0).into(), + background_color: Color::rgb(0.8, 0.8, 1.).into(), ..default() }); }); @@ -193,7 +185,7 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(NodeBundle { style: Style { - size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), + size: Size::all(Val::Percent(100.)), position_type: PositionType::Absolute, align_items: AlignItems::Center, justify_content: JustifyContent::Center, @@ -205,10 +197,10 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(NodeBundle { style: Style { - size: Size::new(Val::Px(100.0), Val::Px(100.0)), + size: Size::all(Val::Px(100.)), ..default() }, - background_color: Color::rgb(1.0, 0.0, 0.0).into(), + background_color: Color::rgb(1.0, 0.0, 0.).into(), ..default() }) .with_children(|parent| { @@ -217,11 +209,8 @@ fn setup(mut commands: Commands, asset_server: Res) { // Take the size of the parent node. size: Size::all(Val::Percent(100.)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(20.0), - bottom: Val::Px(20.0), - ..default() - }, + left: Val::Px(20.), + bottom: Val::Px(20.), ..default() }, background_color: Color::rgb(1.0, 0.3, 0.3).into(), @@ -231,11 +220,8 @@ fn setup(mut commands: Commands, asset_server: Res) { style: Style { size: Size::all(Val::Percent(100.)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(40.0), - bottom: Val::Px(40.0), - ..default() - }, + left: Val::Px(40.), + bottom: Val::Px(40.), ..default() }, background_color: Color::rgb(1.0, 0.5, 0.5).into(), @@ -245,11 +231,8 @@ fn setup(mut commands: Commands, asset_server: Res) { style: Style { size: Size::all(Val::Percent(100.)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(60.0), - bottom: Val::Px(60.0), - ..default() - }, + left: Val::Px(60.), + bottom: Val::Px(60.), ..default() }, background_color: Color::rgb(1.0, 0.7, 0.7).into(), @@ -260,11 +243,8 @@ fn setup(mut commands: Commands, asset_server: Res) { style: Style { size: Size::all(Val::Percent(100.)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(80.0), - bottom: Val::Px(80.0), - ..default() - }, + left: Val::Px(80.), + bottom: Val::Px(80.), ..default() }, background_color: Color::rgba(1.0, 0.9, 0.9, 0.4).into(), @@ -286,6 +266,7 @@ fn setup(mut commands: Commands, asset_server: Res) { }) .with_children(|parent| { // bevy logo (image) + parent .spawn(ImageBundle { style: Style { @@ -327,7 +308,7 @@ fn mouse_scroll( }; scrolling_list.position += dy; scrolling_list.position = scrolling_list.position.clamp(-max_scroll, 0.); - style.position.top = Val::Px(scrolling_list.position); + style.top = Val::Px(scrolling_list.position); } } } diff --git a/examples/ui/ui_scaling.rs b/examples/ui/ui_scaling.rs index 877857a352867..d9a0adbbb1adc 100644 --- a/examples/ui/ui_scaling.rs +++ b/examples/ui/ui_scaling.rs @@ -38,11 +38,8 @@ fn setup(mut commands: Commands, asset_server: ResMut) { style: Style { size: Size::new(Val::Percent(50.0), Val::Percent(50.0)), position_type: PositionType::Absolute, - position: UiRect { - left: Val::Percent(25.), - top: Val::Percent(25.), - ..default() - }, + left: Val::Percent(25.), + top: Val::Percent(25.), justify_content: JustifyContent::SpaceAround, align_items: AlignItems::Center, ..default() diff --git a/examples/ui/window_fallthrough.rs b/examples/ui/window_fallthrough.rs index 123b40b41d50b..21c00cfd33621 100644 --- a/examples/ui/window_fallthrough.rs +++ b/examples/ui/window_fallthrough.rs @@ -40,11 +40,8 @@ fn setup(mut commands: Commands, asset_server: Res) { // Set the style of the TextBundle itself. .with_style(Style { position_type: PositionType::Absolute, - position: UiRect { - bottom: Val::Px(5.), - right: Val::Px(10.), - ..default() - }, + bottom: Val::Px(5.), + right: Val::Px(10.), ..default() }), )); diff --git a/examples/ui/z_index.rs b/examples/ui/z_index.rs index 08a51b0a68060..05d6e9c77b3b2 100644 --- a/examples/ui/z_index.rs +++ b/examples/ui/z_index.rs @@ -45,11 +45,8 @@ fn setup(mut commands: Commands) { background_color: Color::RED.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(10.0), - bottom: Val::Px(40.0), - ..default() - }, + left: Val::Px(10.0), + bottom: Val::Px(40.0), size: Size::new(Val::Px(100.0), Val::Px(50.0)), ..default() }, @@ -63,11 +60,8 @@ fn setup(mut commands: Commands) { background_color: Color::BLUE.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(45.0), - bottom: Val::Px(30.0), - ..default() - }, + left: Val::Px(45.0), + bottom: Val::Px(30.0), size: Size::new(Val::Px(100.0), Val::Px(50.0)), ..default() }, @@ -81,11 +75,8 @@ fn setup(mut commands: Commands) { background_color: Color::GREEN.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(70.0), - bottom: Val::Px(20.0), - ..default() - }, + left: Val::Px(70.0), + bottom: Val::Px(20.0), size: Size::new(Val::Px(100.0), Val::Px(75.0)), ..default() }, @@ -100,11 +91,8 @@ fn setup(mut commands: Commands) { background_color: Color::PURPLE.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(15.0), - bottom: Val::Px(10.0), - ..default() - }, + left: Val::Px(15.0), + bottom: Val::Px(10.0), size: Size::new(Val::Px(100.0), Val::Px(60.0)), ..default() }, @@ -119,11 +107,8 @@ fn setup(mut commands: Commands) { background_color: Color::YELLOW.into(), style: Style { position_type: PositionType::Absolute, - position: UiRect { - left: Val::Px(-15.0), - bottom: Val::Px(-15.0), - ..default() - }, + left: Val::Px(-15.0), + bottom: Val::Px(-15.0), size: Size::new(Val::Px(100.0), Val::Px(125.0)), ..default() }, diff --git a/examples/window/low_power.rs b/examples/window/low_power.rs index f57183cc8be36..8a457cbd0b08b 100644 --- a/examples/window/low_power.rs +++ b/examples/window/low_power.rs @@ -201,11 +201,8 @@ pub(crate) mod test_setup { .with_style(Style { align_self: AlignSelf::FlexStart, position_type: PositionType::Absolute, - position: UiRect { - top: Val::Px(5.0), - left: Val::Px(5.0), - ..default() - }, + top: Val::Px(5.0), + left: Val::Px(5.0), ..default() }), ModeText,