mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
Add with_left
, with_right
, with_top
, with_bottom
to UiRect
(#12487)
# Objective Originally proposed as part of #8973. Adds `with_` methods for each side of `UiRect` ## Solution Add `with_left`, `with_right`, `with_top`, `with_bottom` to `UiRect`.
This commit is contained in:
parent
24b319f6ec
commit
fec00040ef
1 changed files with 76 additions and 0 deletions
|
@ -536,6 +536,82 @@ impl UiRect {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`UiRect`] with its `left` field set to the given value.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use bevy_ui::{UiRect, Val};
|
||||||
|
/// #
|
||||||
|
/// let ui_rect = UiRect::all(Val::Px(20.0)).with_left(Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.left, Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.right, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.top, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn with_left(mut self, left: Val) -> Self {
|
||||||
|
self.left = left;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the [`UiRect`] with its `right` field set to the given value.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use bevy_ui::{UiRect, Val};
|
||||||
|
/// #
|
||||||
|
/// let ui_rect = UiRect::all(Val::Px(20.0)).with_right(Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.left, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.right, Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.top, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn with_right(mut self, right: Val) -> Self {
|
||||||
|
self.right = right;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the [`UiRect`] with its `top` field set to the given value.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use bevy_ui::{UiRect, Val};
|
||||||
|
/// #
|
||||||
|
/// let ui_rect = UiRect::all(Val::Px(20.0)).with_top(Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.left, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.right, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.top, Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.bottom, Val::Px(20.0));
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn with_top(mut self, top: Val) -> Self {
|
||||||
|
self.top = top;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the [`UiRect`] with its `bottom` field set to the given value.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use bevy_ui::{UiRect, Val};
|
||||||
|
/// #
|
||||||
|
/// let ui_rect = UiRect::all(Val::Px(20.0)).with_bottom(Val::Px(10.0));
|
||||||
|
/// assert_eq!(ui_rect.left, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.right, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.top, Val::Px(20.0));
|
||||||
|
/// assert_eq!(ui_rect.bottom, Val::Px(10.0));
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn with_bottom(mut self, bottom: Val) -> Self {
|
||||||
|
self.bottom = bottom;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UiRect {
|
impl Default for UiRect {
|
||||||
|
|
Loading…
Reference in a new issue