From c25d5f56bbcb4841cbd0187ef68c881a85e31a82 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 13 Feb 2023 10:45:24 +0000 Subject: [PATCH 1/7] changes: * Added a constructor function `vertical_horizontal` for `UiRect`. --- crates/bevy_ui/src/geometry.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 76168c98e01f4..63e0e71bc4829 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -235,6 +235,29 @@ impl UiRect { } } + /// Creates a new [`UiRect`] where both `left` and `right` take the value of `horizontal`, and both `top` and `bottom` take the value of `vertical`. + /// + /// # Example + /// + /// ``` + /// # use bevy_ui::{UiRect, Val}; + /// # + /// let ui_rect = UiRect::horizontal_vertical(Val::Px(10.0), Val::Percent(15.0)); + /// + /// assert_eq!(ui_rect.left, Val::Px(10.0)); + /// assert_eq!(ui_rect.right, Val::Px(10.0)); + /// assert_eq!(ui_rect.top, Val::Percent(15.0)); + /// assert_eq!(ui_rect.bottom, Val::Percent(15.0)); + /// ``` + pub fn horizontal_vertical(horizontal: Val, vertical: Val) -> Self { + UiRect { + left: horizontal, + right: horizontal, + top: vertical, + bottom: vertical, + } + } + /// Creates a new [`UiRect`] where `left` takes the given value. /// /// # Example From 0de3a5373b8e99c2ff92a133c6cb9d1505c823e4 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 13 Feb 2023 10:45:24 +0000 Subject: [PATCH 2/7] changes: * Added a constructor function `horizontal_vertical` to `UiRect`. --- crates/bevy_ui/src/geometry.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 76168c98e01f4..63e0e71bc4829 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -235,6 +235,29 @@ impl UiRect { } } + /// Creates a new [`UiRect`] where both `left` and `right` take the value of `horizontal`, and both `top` and `bottom` take the value of `vertical`. + /// + /// # Example + /// + /// ``` + /// # use bevy_ui::{UiRect, Val}; + /// # + /// let ui_rect = UiRect::horizontal_vertical(Val::Px(10.0), Val::Percent(15.0)); + /// + /// assert_eq!(ui_rect.left, Val::Px(10.0)); + /// assert_eq!(ui_rect.right, Val::Px(10.0)); + /// assert_eq!(ui_rect.top, Val::Percent(15.0)); + /// assert_eq!(ui_rect.bottom, Val::Percent(15.0)); + /// ``` + pub fn horizontal_vertical(horizontal: Val, vertical: Val) -> Self { + UiRect { + left: horizontal, + right: horizontal, + top: vertical, + bottom: vertical, + } + } + /// Creates a new [`UiRect`] where `left` takes the given value. /// /// # Example From 6e72c482aa3b9274a560eda38f949995e1122cd0 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 13 Feb 2023 10:57:35 +0000 Subject: [PATCH 3/7] cargo fmt --all --- crates/bevy_ui/src/geometry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 63e0e71bc4829..3bd8dc3c66324 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -254,7 +254,7 @@ impl UiRect { left: horizontal, right: horizontal, top: vertical, - bottom: vertical, + bottom: vertical, } } From d275f0f915e04fee280753bd8a314bd4be158dc2 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Thu, 16 Feb 2023 12:11:42 +0000 Subject: [PATCH 4/7] renamed `horizontal_vertical` to `axes` --- crates/bevy_ui/src/geometry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 3bd8dc3c66324..2c53737860ae1 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -249,7 +249,7 @@ impl UiRect { /// assert_eq!(ui_rect.top, Val::Percent(15.0)); /// assert_eq!(ui_rect.bottom, Val::Percent(15.0)); /// ``` - pub fn horizontal_vertical(horizontal: Val, vertical: Val) -> Self { + pub fn axes(horizontal: Val, vertical: Val) -> Self { UiRect { left: horizontal, right: horizontal, From 4539f89ab82f16c5a7e84754356c0ea4b9be74df Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Thu, 16 Feb 2023 12:37:49 +0000 Subject: [PATCH 5/7] fix doc comment --- crates/bevy_ui/src/geometry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 2c53737860ae1..c708bcbd70038 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -242,7 +242,7 @@ impl UiRect { /// ``` /// # use bevy_ui::{UiRect, Val}; /// # - /// let ui_rect = UiRect::horizontal_vertical(Val::Px(10.0), Val::Percent(15.0)); + /// let ui_rect = UiRect::axes(Val::Px(10.0), Val::Percent(15.0)); /// /// assert_eq!(ui_rect.left, Val::Px(10.0)); /// assert_eq!(ui_rect.right, Val::Px(10.0)); From f3340ced9cf7e77ddb5a03063f05149394f44ce2 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 13 Apr 2023 08:46:08 +0100 Subject: [PATCH 6/7] added a simple test for axes function --- crates/bevy_ui/src/geometry.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index e4c6689e246a8..23d2925bb8ac3 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -530,4 +530,18 @@ mod tests { ); assert_eq!(Size::default(), Size::DEFAULT); } + + #[test] + fn test_uirect_axes() { + let x = Val::Px(1.); + let y = Val::Vw(4.); + let r = UiRect::axes(x, y); + let h = UiRect::horizontal(x); + let v = UiRect::vertical(y); + + assert_eq!(r.top, v.top); + assert_eq!(r.bottom, v.bottom); + assert_eq!(r.left, h.left); + assert_eq!(r.right, h.right); + } } From 235afa53f031d5aabf5dc4c60fa177e9571787d2 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 13 Apr 2023 08:47:46 +0100 Subject: [PATCH 7/7] cargo fmt --- crates/bevy_ui/src/geometry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 23d2925bb8ac3..d58509ab53534 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -538,7 +538,7 @@ mod tests { let r = UiRect::axes(x, y); let h = UiRect::horizontal(x); let v = UiRect::vertical(y); - + assert_eq!(r.top, v.top); assert_eq!(r.bottom, v.bottom); assert_eq!(r.left, h.left);