@@ -536,6 +536,82 @@ impl UiRect {
536536 ..Default :: default ( )
537537 }
538538 }
539+
540+ /// Returns the [`UiRect`] with its `left` field set to the given value.
541+ ///
542+ /// # Example
543+ ///
544+ /// ```
545+ /// # use bevy_ui::{UiRect, Val};
546+ /// #
547+ /// let ui_rect = UiRect::all(Val::Px(20.0)).with_left(Val::Px(10.0));
548+ /// assert_eq!(ui_rect.left, Val::Px(10.0));
549+ /// assert_eq!(ui_rect.right, Val::Px(20.0));
550+ /// assert_eq!(ui_rect.top, Val::Px(20.0));
551+ /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
552+ /// ```
553+ #[ inline]
554+ pub fn with_left ( mut self , left : Val ) -> Self {
555+ self . left = left;
556+ self
557+ }
558+
559+ /// Returns the [`UiRect`] with its `right` field set to the given value.
560+ ///
561+ /// # Example
562+ ///
563+ /// ```
564+ /// # use bevy_ui::{UiRect, Val};
565+ /// #
566+ /// let ui_rect = UiRect::all(Val::Px(20.0)).with_right(Val::Px(10.0));
567+ /// assert_eq!(ui_rect.left, Val::Px(20.0));
568+ /// assert_eq!(ui_rect.right, Val::Px(10.0));
569+ /// assert_eq!(ui_rect.top, Val::Px(20.0));
570+ /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
571+ /// ```
572+ #[ inline]
573+ pub fn with_right ( mut self , right : Val ) -> Self {
574+ self . right = right;
575+ self
576+ }
577+
578+ /// Returns the [`UiRect`] with its `top` field set to the given value.
579+ ///
580+ /// # Example
581+ ///
582+ /// ```
583+ /// # use bevy_ui::{UiRect, Val};
584+ /// #
585+ /// let ui_rect = UiRect::all(Val::Px(20.0)).with_top(Val::Px(10.0));
586+ /// assert_eq!(ui_rect.left, Val::Px(20.0));
587+ /// assert_eq!(ui_rect.right, Val::Px(20.0));
588+ /// assert_eq!(ui_rect.top, Val::Px(10.0));
589+ /// assert_eq!(ui_rect.bottom, Val::Px(20.0));
590+ /// ```
591+ #[ inline]
592+ pub fn with_top ( mut self , top : Val ) -> Self {
593+ self . top = top;
594+ self
595+ }
596+
597+ /// Returns the [`UiRect`] with its `bottom` field set to the given value.
598+ ///
599+ /// # Example
600+ ///
601+ /// ```
602+ /// # use bevy_ui::{UiRect, Val};
603+ /// #
604+ /// let ui_rect = UiRect::all(Val::Px(20.0)).with_bottom(Val::Px(10.0));
605+ /// assert_eq!(ui_rect.left, Val::Px(20.0));
606+ /// assert_eq!(ui_rect.right, Val::Px(20.0));
607+ /// assert_eq!(ui_rect.top, Val::Px(20.0));
608+ /// assert_eq!(ui_rect.bottom, Val::Px(10.0));
609+ /// ```
610+ #[ inline]
611+ pub fn with_bottom ( mut self , bottom : Val ) -> Self {
612+ self . bottom = bottom;
613+ self
614+ }
539615}
540616
541617impl Default for UiRect {
0 commit comments