Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made UIRect initialisation functions const #16823

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +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 {
pub const fn horizontal(value: Val) -> Self {
Self {
left: value,
right: value,
..Default::default()
..Self::DEFAULT
}
}

Expand All @@ -413,11 +413,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 {
pub const fn vertical(value: Val) -> Self {
Self {
top: value,
bottom: value,
..Default::default()
..Self::DEFAULT
}
}

Expand All @@ -435,8 +435,8 @@ 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 {
UiRect {
pub const fn axes(horizontal: Val, vertical: Val) -> Self {
Self {
left: horizontal,
right: horizontal,
top: vertical,
Expand All @@ -459,10 +459,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(left: Val) -> Self {
Self {
left,
..Self::DEFAULT
}
}

Expand All @@ -481,10 +481,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(right: Val) -> Self {
Self {
right,
..Self::DEFAULT
}
}

Expand All @@ -503,10 +503,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(top: Val) -> Self {
Self {
top,
..Self::DEFAULT
}
}

Expand All @@ -525,10 +525,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(bottom: Val) -> Self {
Self {
bottom,
..Self::DEFAULT
}
}

Expand All @@ -546,7 +546,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 +565,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 +584,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 +603,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
Loading