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`
This commit is contained in:
Daniel Skates 2025-05-29 22:52:44 +08:00 committed by GitHub
parent c364710d1f
commit 922ee480d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 27 deletions

View File

@ -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<Val> for Position {
impl From<Val> 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() }
}

View File

@ -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<ColorStop>) -> Self {
pub fn new(position: UiPosition, shape: RadialGradientShape, stops: Vec<ColorStop>) -> 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<AngularColorStop>,
}
impl ConicGradient {
/// Create a new conic gradient
pub fn new(position: Position, stops: Vec<AngularColorStop>) -> Self {
pub fn new(position: UiPosition, stops: Vec<AngularColorStop>) -> 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
}

View File

@ -182,7 +182,7 @@ impl Plugin for UiPlugin {
.register_type::<TextShadow>()
.register_type::<ColorStop>()
.register_type::<AngularColorStop>()
.register_type::<Position>()
.register_type::<UiPosition>()
.register_type::<RadialGradientShape>()
.register_type::<Gradient>()
.register_type::<BackgroundGradient>()

View File

@ -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

View File

@ -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.,

View File

@ -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),

View File

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