Made UIRect initialisation functions const (#16823)

# Objective
Destructuring in const code blocks isn't allowed, thus using UIRect in
const code can be a hassle as it initialisation function aren't const.
This Pr makes them const.

## Solution

Removed all destructuring in the UIRect implementation

## Testing

- I've ran a few ui examples to check if i didn't make a mistake,

---
This commit is contained in:
Kees van Beilen 2024-12-15 20:17:43 +01:00 committed by GitHub
parent ae522225cd
commit 8d8622d352
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -390,11 +390,11 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO); /// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO); /// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ``` /// ```
pub fn horizontal(value: Val) -> Self { pub const fn horizontal(value: Val) -> Self {
UiRect { Self {
left: value, left: value,
right: value, right: value,
..Default::default() ..Self::DEFAULT
} }
} }
@ -413,11 +413,11 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Px(10.0)); /// assert_eq!(ui_rect.top, Val::Px(10.0));
/// assert_eq!(ui_rect.bottom, Val::Px(10.0)); /// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ``` /// ```
pub fn vertical(value: Val) -> Self { pub const fn vertical(value: Val) -> Self {
UiRect { Self {
top: value, top: value,
bottom: value, bottom: value,
..Default::default() ..Self::DEFAULT
} }
} }
@ -435,8 +435,8 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Percent(15.0)); /// assert_eq!(ui_rect.top, Val::Percent(15.0));
/// assert_eq!(ui_rect.bottom, 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 { Self {
left: horizontal, left: horizontal,
right: horizontal, right: horizontal,
top: vertical, top: vertical,
@ -459,10 +459,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO); /// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO); /// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ``` /// ```
pub fn left(value: Val) -> Self { pub const fn left(left: Val) -> Self {
UiRect { Self {
left: value, left,
..Default::default() ..Self::DEFAULT
} }
} }
@ -481,10 +481,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO); /// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::ZERO); /// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ``` /// ```
pub fn right(value: Val) -> Self { pub const fn right(right: Val) -> Self {
UiRect { Self {
right: value, right,
..Default::default() ..Self::DEFAULT
} }
} }
@ -503,10 +503,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::Px(10.0)); /// assert_eq!(ui_rect.top, Val::Px(10.0));
/// assert_eq!(ui_rect.bottom, Val::ZERO); /// assert_eq!(ui_rect.bottom, Val::ZERO);
/// ``` /// ```
pub fn top(value: Val) -> Self { pub const fn top(top: Val) -> Self {
UiRect { Self {
top: value, top,
..Default::default() ..Self::DEFAULT
} }
} }
@ -525,10 +525,10 @@ impl UiRect {
/// assert_eq!(ui_rect.top, Val::ZERO); /// assert_eq!(ui_rect.top, Val::ZERO);
/// assert_eq!(ui_rect.bottom, Val::Px(10.0)); /// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ``` /// ```
pub fn bottom(value: Val) -> Self { pub const fn bottom(bottom: Val) -> Self {
UiRect { Self {
bottom: value, bottom,
..Default::default() ..Self::DEFAULT
} }
} }
@ -546,7 +546,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0)); /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ``` /// ```
#[inline] #[inline]
pub fn with_left(mut self, left: Val) -> Self { pub const fn with_left(mut self, left: Val) -> Self {
self.left = left; self.left = left;
self self
} }
@ -565,7 +565,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0)); /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ``` /// ```
#[inline] #[inline]
pub fn with_right(mut self, right: Val) -> Self { pub const fn with_right(mut self, right: Val) -> Self {
self.right = right; self.right = right;
self self
} }
@ -584,7 +584,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(20.0)); /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
/// ``` /// ```
#[inline] #[inline]
pub fn with_top(mut self, top: Val) -> Self { pub const fn with_top(mut self, top: Val) -> Self {
self.top = top; self.top = top;
self self
} }
@ -603,7 +603,7 @@ impl UiRect {
/// assert_eq!(ui_rect.bottom, Val::Px(10.0)); /// assert_eq!(ui_rect.bottom, Val::Px(10.0));
/// ``` /// ```
#[inline] #[inline]
pub fn with_bottom(mut self, bottom: Val) -> Self { pub const fn with_bottom(mut self, bottom: Val) -> Self {
self.bottom = bottom; self.bottom = bottom;
self self
} }