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:
parent
c364710d1f
commit
922ee480d2
@ -695,7 +695,7 @@ impl Default for UiRect {
|
|||||||
reflect(Serialize, Deserialize)
|
reflect(Serialize, Deserialize)
|
||||||
)]
|
)]
|
||||||
/// Responsive position relative to a UI node.
|
/// Responsive position relative to a UI node.
|
||||||
pub struct Position {
|
pub struct UiPosition {
|
||||||
/// Normalized anchor point
|
/// Normalized anchor point
|
||||||
pub anchor: Vec2,
|
pub anchor: Vec2,
|
||||||
/// Responsive horizontal position relative to the anchor point
|
/// Responsive horizontal position relative to the anchor point
|
||||||
@ -704,13 +704,13 @@ pub struct Position {
|
|||||||
pub y: Val,
|
pub y: Val,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Position {
|
impl Default for UiPosition {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::CENTER
|
Self::CENTER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Position {
|
impl UiPosition {
|
||||||
/// Position at the given normalized anchor point
|
/// Position at the given normalized anchor point
|
||||||
pub const fn anchor(anchor: Vec2) -> Self {
|
pub const fn anchor(anchor: Vec2) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -848,13 +848,13 @@ impl Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Val> for Position {
|
impl From<Val> for UiPosition {
|
||||||
fn from(x: Val) -> Self {
|
fn from(x: Val) -> Self {
|
||||||
Self { x, ..default() }
|
Self { x, ..default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(Val, Val)> for Position {
|
impl From<(Val, Val)> for UiPosition {
|
||||||
fn from((x, y): (Val, Val)) -> Self {
|
fn from((x, y): (Val, Val)) -> Self {
|
||||||
Self { x, y, ..default() }
|
Self { x, y, ..default() }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{Position, Val};
|
use crate::{UiPosition, Val};
|
||||||
use bevy_color::{Color, Srgba};
|
use bevy_color::{Color, Srgba};
|
||||||
use bevy_ecs::component::Component;
|
use bevy_ecs::component::Component;
|
||||||
use bevy_math::Vec2;
|
use bevy_math::Vec2;
|
||||||
@ -328,7 +328,7 @@ impl LinearGradient {
|
|||||||
)]
|
)]
|
||||||
pub struct RadialGradient {
|
pub struct RadialGradient {
|
||||||
/// The center of the radial gradient
|
/// The center of the radial gradient
|
||||||
pub position: Position,
|
pub position: UiPosition,
|
||||||
/// Defines the end shape of the radial gradient
|
/// Defines the end shape of the radial gradient
|
||||||
pub shape: RadialGradientShape,
|
pub shape: RadialGradientShape,
|
||||||
/// The list of color stops
|
/// The list of color stops
|
||||||
@ -337,7 +337,7 @@ pub struct RadialGradient {
|
|||||||
|
|
||||||
impl RadialGradient {
|
impl RadialGradient {
|
||||||
/// Create a new radial gradient
|
/// 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 {
|
Self {
|
||||||
position,
|
position,
|
||||||
shape,
|
shape,
|
||||||
@ -349,7 +349,7 @@ impl RadialGradient {
|
|||||||
impl Default for RadialGradient {
|
impl Default for RadialGradient {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
position: Position::CENTER,
|
position: UiPosition::CENTER,
|
||||||
shape: RadialGradientShape::ClosestCorner,
|
shape: RadialGradientShape::ClosestCorner,
|
||||||
stops: Vec::new(),
|
stops: Vec::new(),
|
||||||
}
|
}
|
||||||
@ -370,14 +370,14 @@ pub struct ConicGradient {
|
|||||||
/// The starting angle of the gradient in radians
|
/// The starting angle of the gradient in radians
|
||||||
pub start: f32,
|
pub start: f32,
|
||||||
/// The center of the conic gradient
|
/// The center of the conic gradient
|
||||||
pub position: Position,
|
pub position: UiPosition,
|
||||||
/// The list of color stops
|
/// The list of color stops
|
||||||
pub stops: Vec<AngularColorStop>,
|
pub stops: Vec<AngularColorStop>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConicGradient {
|
impl ConicGradient {
|
||||||
/// Create a new conic gradient
|
/// Create a new conic gradient
|
||||||
pub fn new(position: Position, stops: Vec<AngularColorStop>) -> Self {
|
pub fn new(position: UiPosition, stops: Vec<AngularColorStop>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
start: 0.,
|
start: 0.,
|
||||||
position,
|
position,
|
||||||
@ -392,7 +392,7 @@ impl ConicGradient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the position of the gradient
|
/// 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.position = position;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ impl Plugin for UiPlugin {
|
|||||||
.register_type::<TextShadow>()
|
.register_type::<TextShadow>()
|
||||||
.register_type::<ColorStop>()
|
.register_type::<ColorStop>()
|
||||||
.register_type::<AngularColorStop>()
|
.register_type::<AngularColorStop>()
|
||||||
.register_type::<Position>()
|
.register_type::<UiPosition>()
|
||||||
.register_type::<RadialGradientShape>()
|
.register_type::<RadialGradientShape>()
|
||||||
.register_type::<Gradient>()
|
.register_type::<Gradient>()
|
||||||
.register_type::<BackgroundGradient>()
|
.register_type::<BackgroundGradient>()
|
||||||
|
@ -579,15 +579,15 @@ mod radial_gradient {
|
|||||||
(RadialGradientShape::FarthestCorner, "FarthestCorner"),
|
(RadialGradientShape::FarthestCorner, "FarthestCorner"),
|
||||||
] {
|
] {
|
||||||
for (position, position_label) in [
|
for (position, position_label) in [
|
||||||
(Position::TOP_LEFT, "TOP_LEFT"),
|
(UiPosition::TOP_LEFT, "TOP_LEFT"),
|
||||||
(Position::LEFT, "LEFT"),
|
(UiPosition::LEFT, "LEFT"),
|
||||||
(Position::BOTTOM_LEFT, "BOTTOM_LEFT"),
|
(UiPosition::BOTTOM_LEFT, "BOTTOM_LEFT"),
|
||||||
(Position::TOP, "TOP"),
|
(UiPosition::TOP, "TOP"),
|
||||||
(Position::CENTER, "CENTER"),
|
(UiPosition::CENTER, "CENTER"),
|
||||||
(Position::BOTTOM, "BOTTOM"),
|
(UiPosition::BOTTOM, "BOTTOM"),
|
||||||
(Position::TOP_RIGHT, "TOP_RIGHT"),
|
(UiPosition::TOP_RIGHT, "TOP_RIGHT"),
|
||||||
(Position::RIGHT, "RIGHT"),
|
(UiPosition::RIGHT, "RIGHT"),
|
||||||
(Position::BOTTOM_RIGHT, "BOTTOM_RIGHT"),
|
(UiPosition::BOTTOM_RIGHT, "BOTTOM_RIGHT"),
|
||||||
] {
|
] {
|
||||||
for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] {
|
for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] {
|
||||||
commands
|
commands
|
||||||
|
@ -135,7 +135,7 @@ fn setup(mut commands: Commands) {
|
|||||||
BackgroundGradient::from(RadialGradient {
|
BackgroundGradient::from(RadialGradient {
|
||||||
stops: stops.clone(),
|
stops: stops.clone(),
|
||||||
shape: RadialGradientShape::ClosestSide,
|
shape: RadialGradientShape::ClosestSide,
|
||||||
position: Position::CENTER,
|
position: UiPosition::CENTER,
|
||||||
}),
|
}),
|
||||||
BorderGradient::from(LinearGradient {
|
BorderGradient::from(LinearGradient {
|
||||||
angle: 3. * TAU / 8.,
|
angle: 3. * TAU / 8.,
|
||||||
@ -158,7 +158,7 @@ fn setup(mut commands: Commands) {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|stop| AngularColorStop::auto(stop.color))
|
.map(|stop| AngularColorStop::auto(stop.color))
|
||||||
.collect(),
|
.collect(),
|
||||||
position: Position::CENTER,
|
position: UiPosition::CENTER,
|
||||||
}),
|
}),
|
||||||
BorderGradient::from(LinearGradient {
|
BorderGradient::from(LinearGradient {
|
||||||
angle: 3. * TAU / 8.,
|
angle: 3. * TAU / 8.,
|
||||||
|
@ -44,7 +44,7 @@ fn setup(mut commands: Commands) {
|
|||||||
.into(),
|
.into(),
|
||||||
ConicGradient {
|
ConicGradient {
|
||||||
start: 0.,
|
start: 0.,
|
||||||
position: Position::CENTER,
|
position: UiPosition::CENTER,
|
||||||
stops: vec![
|
stops: vec![
|
||||||
AngularColorStop::auto(YELLOW.with_alpha(0.)),
|
AngularColorStop::auto(YELLOW.with_alpha(0.)),
|
||||||
AngularColorStop::auto(YELLOW.with_alpha(0.)),
|
AngularColorStop::auto(YELLOW.with_alpha(0.)),
|
||||||
@ -55,7 +55,7 @@ fn setup(mut commands: Commands) {
|
|||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
RadialGradient {
|
RadialGradient {
|
||||||
position: Position::TOP.at_x(Val::Percent(5.)),
|
position: UiPosition::TOP.at_x(Val::Percent(5.)),
|
||||||
shape: RadialGradientShape::Circle(Val::Vh(30.)),
|
shape: RadialGradientShape::Circle(Val::Vh(30.)),
|
||||||
stops: vec![
|
stops: vec![
|
||||||
ColorStop::auto(Color::WHITE),
|
ColorStop::auto(Color::WHITE),
|
||||||
|
@ -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.
|
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user