From 922ee480d2382ac469b8932fe1298d2ddcffd089 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Thu, 29 May 2025 22:52:44 +0800 Subject: [PATCH] Rename Position to UiPosition in bevy_ui (#19422) # Objective - Fixes #19418 ## Solution - Rename Position to UiPosition in bevy_ui ## Testing - `cargo build` - `cargo run --example gradients` - `cargo run --example stacked_gradients` --- crates/bevy_ui/src/geometry.rs | 10 +++++----- crates/bevy_ui/src/gradients.rs | 14 +++++++------- crates/bevy_ui/src/lib.rs | 2 +- examples/testbed/ui.rs | 18 +++++++++--------- examples/ui/gradients.rs | 4 ++-- examples/ui/stacked_gradients.rs | 4 ++-- release-content/release-notes/ui_gradients.md | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index e41ab5e862..8c6b38083c 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -695,7 +695,7 @@ impl Default for UiRect { reflect(Serialize, Deserialize) )] /// Responsive position relative to a UI node. -pub struct Position { +pub struct UiPosition { /// Normalized anchor point pub anchor: Vec2, /// Responsive horizontal position relative to the anchor point @@ -704,13 +704,13 @@ pub struct Position { pub y: Val, } -impl Default for Position { +impl Default for UiPosition { fn default() -> Self { Self::CENTER } } -impl Position { +impl UiPosition { /// Position at the given normalized anchor point pub const fn anchor(anchor: Vec2) -> Self { Self { @@ -848,13 +848,13 @@ impl Position { } } -impl From for Position { +impl From for UiPosition { fn from(x: Val) -> Self { Self { x, ..default() } } } -impl From<(Val, Val)> for Position { +impl From<(Val, Val)> for UiPosition { fn from((x, y): (Val, Val)) -> Self { Self { x, y, ..default() } } diff --git a/crates/bevy_ui/src/gradients.rs b/crates/bevy_ui/src/gradients.rs index bbccc6b62e..969e062cd7 100644 --- a/crates/bevy_ui/src/gradients.rs +++ b/crates/bevy_ui/src/gradients.rs @@ -1,4 +1,4 @@ -use crate::{Position, Val}; +use crate::{UiPosition, Val}; use bevy_color::{Color, Srgba}; use bevy_ecs::component::Component; use bevy_math::Vec2; @@ -328,7 +328,7 @@ impl LinearGradient { )] pub struct RadialGradient { /// The center of the radial gradient - pub position: Position, + pub position: UiPosition, /// Defines the end shape of the radial gradient pub shape: RadialGradientShape, /// The list of color stops @@ -337,7 +337,7 @@ pub struct RadialGradient { impl RadialGradient { /// Create a new radial gradient - pub fn new(position: Position, shape: RadialGradientShape, stops: Vec) -> Self { + pub fn new(position: UiPosition, shape: RadialGradientShape, stops: Vec) -> Self { Self { position, shape, @@ -349,7 +349,7 @@ impl RadialGradient { impl Default for RadialGradient { fn default() -> Self { Self { - position: Position::CENTER, + position: UiPosition::CENTER, shape: RadialGradientShape::ClosestCorner, stops: Vec::new(), } @@ -370,14 +370,14 @@ pub struct ConicGradient { /// The starting angle of the gradient in radians pub start: f32, /// The center of the conic gradient - pub position: Position, + pub position: UiPosition, /// The list of color stops pub stops: Vec, } impl ConicGradient { /// Create a new conic gradient - pub fn new(position: Position, stops: Vec) -> Self { + pub fn new(position: UiPosition, stops: Vec) -> Self { Self { start: 0., position, @@ -392,7 +392,7 @@ impl ConicGradient { } /// Sets the position of the gradient - pub fn with_position(mut self, position: Position) -> Self { + pub fn with_position(mut self, position: UiPosition) -> Self { self.position = position; self } diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 73e73758b7..a216c4220b 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -182,7 +182,7 @@ impl Plugin for UiPlugin { .register_type::() .register_type::() .register_type::() - .register_type::() + .register_type::() .register_type::() .register_type::() .register_type::() diff --git a/examples/testbed/ui.rs b/examples/testbed/ui.rs index c59867fe0e..eba2afb409 100644 --- a/examples/testbed/ui.rs +++ b/examples/testbed/ui.rs @@ -579,15 +579,15 @@ mod radial_gradient { (RadialGradientShape::FarthestCorner, "FarthestCorner"), ] { for (position, position_label) in [ - (Position::TOP_LEFT, "TOP_LEFT"), - (Position::LEFT, "LEFT"), - (Position::BOTTOM_LEFT, "BOTTOM_LEFT"), - (Position::TOP, "TOP"), - (Position::CENTER, "CENTER"), - (Position::BOTTOM, "BOTTOM"), - (Position::TOP_RIGHT, "TOP_RIGHT"), - (Position::RIGHT, "RIGHT"), - (Position::BOTTOM_RIGHT, "BOTTOM_RIGHT"), + (UiPosition::TOP_LEFT, "TOP_LEFT"), + (UiPosition::LEFT, "LEFT"), + (UiPosition::BOTTOM_LEFT, "BOTTOM_LEFT"), + (UiPosition::TOP, "TOP"), + (UiPosition::CENTER, "CENTER"), + (UiPosition::BOTTOM, "BOTTOM"), + (UiPosition::TOP_RIGHT, "TOP_RIGHT"), + (UiPosition::RIGHT, "RIGHT"), + (UiPosition::BOTTOM_RIGHT, "BOTTOM_RIGHT"), ] { for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] { commands diff --git a/examples/ui/gradients.rs b/examples/ui/gradients.rs index e3ee565fda..ac4786f078 100644 --- a/examples/ui/gradients.rs +++ b/examples/ui/gradients.rs @@ -135,7 +135,7 @@ fn setup(mut commands: Commands) { BackgroundGradient::from(RadialGradient { stops: stops.clone(), shape: RadialGradientShape::ClosestSide, - position: Position::CENTER, + position: UiPosition::CENTER, }), BorderGradient::from(LinearGradient { angle: 3. * TAU / 8., @@ -158,7 +158,7 @@ fn setup(mut commands: Commands) { .iter() .map(|stop| AngularColorStop::auto(stop.color)) .collect(), - position: Position::CENTER, + position: UiPosition::CENTER, }), BorderGradient::from(LinearGradient { angle: 3. * TAU / 8., diff --git a/examples/ui/stacked_gradients.rs b/examples/ui/stacked_gradients.rs index ebda1a6510..ceef53ccdc 100644 --- a/examples/ui/stacked_gradients.rs +++ b/examples/ui/stacked_gradients.rs @@ -44,7 +44,7 @@ fn setup(mut commands: Commands) { .into(), ConicGradient { start: 0., - position: Position::CENTER, + position: UiPosition::CENTER, stops: vec![ AngularColorStop::auto(YELLOW.with_alpha(0.)), AngularColorStop::auto(YELLOW.with_alpha(0.)), @@ -55,7 +55,7 @@ fn setup(mut commands: Commands) { } .into(), RadialGradient { - position: Position::TOP.at_x(Val::Percent(5.)), + position: UiPosition::TOP.at_x(Val::Percent(5.)), shape: RadialGradientShape::Circle(Val::Vh(30.)), stops: vec![ ColorStop::auto(Color::WHITE), diff --git a/release-content/release-notes/ui_gradients.md b/release-content/release-notes/ui_gradients.md index ee806c251e..1a9243d35d 100644 --- a/release-content/release-notes/ui_gradients.md +++ b/release-content/release-notes/ui_gradients.md @@ -23,4 +23,4 @@ Colors are interpolated between the stops in SRGB space. The hint is a normalize For sharp stops with no interpolated transition, place two stops at the same point. -`ConicGradients` and `RadialGradients` have a center which is set using the new `Position` type. `Position` consists of a normalized (relative to the UI node) Vec2 anchor point and a responsive x, y offset. +`ConicGradients` and `RadialGradients` have a center which is set using the new `UiPosition` type. `UiPosition` consists of a normalized (relative to the UI node) Vec2 anchor point and a responsive x, y offset.