Skip to content

Commit

Permalink
Update geometry.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees-van-Beilen committed Dec 14, 2024
1 parent 6178ce9 commit 1e41f52
Showing 1 changed file with 31 additions and 37 deletions.
68 changes: 31 additions & 37 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,11 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ```
pub fn horizontal(value: Val) -> Self {
UiRect {
left: value,
right: value,
..Default::default()
}
pub const fn horizontal(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.left = value;
rect.right = value;
rect
}

/// Creates a new [`UiRect`] where `top` and `bottom` take the given value,
Expand All @@ -413,12 +412,11 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Px(10.0));
/// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ```
pub fn vertical(value: Val) -> Self {
UiRect {
top: value,
bottom: value,
..Default::default()
}
pub const fn vertical(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.top = value;
rect.bottom = value;
rect
}

/// Creates a new [`UiRect`] where both `left` and `right` take the value of `horizontal`, and both `top` and `bottom` take the value of `vertical`.
Expand All @@ -435,7 +433,7 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Percent(15.0));
/// assert_eq!(ui_rect.bottom, Val::Percent(15.0));
/// ```
pub fn axes(horizontal: Val, vertical: Val) -> Self {
pub const fn axes(horizontal: Val, vertical: Val) -> Self {
UiRect {
left: horizontal,
right: horizontal,
Expand All @@ -459,11 +457,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ```
pub fn left(value: Val) -> Self {
UiRect {
left: value,
..Default::default()
}
pub const fn left(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.left = value;
rect
}

/// Creates a new [`UiRect`] where `right` takes the given value,
Expand All @@ -481,11 +478,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ```
pub fn right(value: Val) -> Self {
UiRect {
right: value,
..Default::default()
}
pub const fn right(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.right = value;
rect
}

/// Creates a new [`UiRect`] where `top` takes the given value,
Expand All @@ -503,11 +499,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Px(10.0));
/// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ```
pub fn top(value: Val) -> Self {
UiRect {
top: value,
..Default::default()
}
pub const fn top(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.top = value;
rect
}

/// Creates a new [`UiRect`] where `bottom` takes the given value,
Expand All @@ -525,11 +520,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ```
pub fn bottom(value: Val) -> Self {
UiRect {
bottom: value,
..Default::default()
}
pub const fn bottom(value: Val) -> Self {
let mut rect = UiRect::DEFAULT;
rect.bottom = value;
rect
}

/// Returns the [`UiRect`] with its `left` field set to the given value.
Expand All @@ -546,7 +540,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ```
#[inline]
pub fn with_left(mut self, left: Val) -> Self {
pub const fn with_left(mut self, left: Val) -> Self {
self.left = left;
self
}
Expand All @@ -565,7 +559,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ```
#[inline]
pub fn with_right(mut self, right: Val) -> Self {
pub const fn with_right(mut self, right: Val) -> Self {
self.right = right;
self
}
Expand All @@ -584,7 +578,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ```
#[inline]
pub fn with_top(mut self, top: Val) -> Self {
pub const fn with_top(mut self, top: Val) -> Self {
self.top = top;
self
}
Expand All @@ -603,7 +597,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ```
#[inline]
pub fn with_bottom(mut self, bottom: Val) -> Self {
pub const fn with_bottom(mut self, bottom: Val) -> Self {
self.bottom = bottom;
self
}
Expand Down

0 comments on commit 1e41f52

Please sign in to comment.