From 2e3c0bfab22b7f2c05968f3ea6ff243545d72468 Mon Sep 17 00:00:00 2001 From: KDecay Date: Mon, 25 Apr 2022 19:20:38 +0000 Subject: [PATCH] Move `Rect` to `bevy_ui` and rename it to `UiRect` (#4276) # Objective - Closes #335. - Related #4285. - Part of the splitting process of #3503. ## Solution - Move `Rect` to `bevy_ui` and rename it to `UiRect`. ## Reasons - `Rect` is only used in `bevy_ui` and therefore calling it `UiRect` makes the intent clearer. - We have two types that are called `Rect` currently and it's missleading (see `bevy_sprite::Rect` and #335). - Discussion in #3503. ## Changelog ### Changed - The `Rect` type got moved from `bevy_math` to `bevy_ui` and renamed to `UiRect`. ## Migration Guide - The `Rect` type got renamed to `UiRect`. To migrate you just have to change every occurrence of `Rect` to `UiRect`. Co-authored-by: KDecay --- crates/bevy_math/Cargo.toml | 1 - crates/bevy_math/src/geometry.rs | 36 ------------------------ crates/bevy_math/src/lib.rs | 7 ++--- crates/bevy_ui/src/flex/convert.rs | 5 ++-- crates/bevy_ui/src/geometry.rs | 35 +++++++++++++++++++++++ crates/bevy_ui/src/lib.rs | 3 +- crates/bevy_ui/src/ui_node.rs | 12 ++++---- examples/ecs/state.rs | 2 +- examples/games/alien_cake_addict.rs | 4 +-- examples/games/breakout.rs | 2 +- examples/games/game_menu.rs | 28 +++++++++--------- examples/stress_tests/bevymark.rs | 2 +- examples/ui/button.rs | 2 +- examples/ui/font_atlas_debug.rs | 2 +- examples/ui/text.rs | 2 +- examples/ui/text_debug.rs | 8 +++--- examples/ui/ui.rs | 20 ++++++------- examples/window/low_power.rs | 2 +- examples/window/scale_factor_override.rs | 2 +- 19 files changed, 84 insertions(+), 91 deletions(-) delete mode 100644 crates/bevy_math/src/geometry.rs diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index 64c6e1e7879fbd..72821502982587 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -10,4 +10,3 @@ keywords = ["bevy"] [dependencies] glam = { version = "0.20.0", features = ["serde", "bytemuck"] } -bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] } diff --git a/crates/bevy_math/src/geometry.rs b/crates/bevy_math/src/geometry.rs deleted file mode 100644 index ed93591485e36d..00000000000000 --- a/crates/bevy_math/src/geometry.rs +++ /dev/null @@ -1,36 +0,0 @@ -use bevy_reflect::Reflect; - -/// A rect, as defined by its "side" locations -#[derive(Copy, Clone, PartialEq, Debug, Reflect)] -#[reflect(PartialEq)] -pub struct Rect { - pub left: T, - pub right: T, - pub top: T, - pub bottom: T, -} - -impl Rect { - pub fn all(value: T) -> Self - where - T: Clone, - { - Rect { - left: value.clone(), - right: value.clone(), - top: value.clone(), - bottom: value, - } - } -} - -impl Default for Rect { - fn default() -> Self { - Self { - left: Default::default(), - right: Default::default(), - top: Default::default(), - bottom: Default::default(), - } - } -} diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index 866e4ec4d0c703..f854004559a25c 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -1,12 +1,9 @@ -mod geometry; - -pub use geometry::*; pub use glam::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, Rect, UVec2, UVec3, - UVec4, Vec2, Vec3, Vec4, + BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, UVec2, UVec3, UVec4, + Vec2, Vec3, Vec4, }; } diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index fab4e8b8d4dd0f..3c73b1f566714a 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -1,12 +1,11 @@ use crate::{ AlignContent, AlignItems, AlignSelf, Direction, Display, FlexDirection, FlexWrap, - JustifyContent, PositionType, Size, Style, Val, + JustifyContent, PositionType, Size, Style, UiRect, Val, }; -use bevy_math::Rect; pub fn from_rect( scale_factor: f64, - rect: Rect, + rect: UiRect, ) -> stretch::geometry::Rect { stretch::geometry::Rect { start: from_val(scale_factor, rect.left), diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index f06d1d7ad3cfa1..2ce50140a4eaa7 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -2,6 +2,41 @@ use bevy_math::Vec2; use bevy_reflect::Reflect; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; +/// A rect, as defined by its "side" locations +#[derive(Copy, Clone, PartialEq, Debug, Reflect)] +#[reflect(PartialEq)] +pub struct UiRect { + pub left: T, + pub right: T, + pub top: T, + pub bottom: T, +} + +impl UiRect { + pub fn all(value: T) -> Self + where + T: Clone, + { + UiRect { + left: value.clone(), + right: value.clone(), + top: value.clone(), + bottom: value, + } + } +} + +impl Default for UiRect { + fn default() -> Self { + Self { + left: Default::default(), + right: Default::default(), + top: Default::default(), + bottom: Default::default(), + } + } +} + /// A two dimensional "size" as defined by a width and height #[derive(Copy, Clone, PartialEq, Debug, Reflect)] #[reflect(PartialEq)] diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 2d4f1e2b6f1d84..4155bf11729cc0 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -29,7 +29,6 @@ use crate::Size; use bevy_app::prelude::*; use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel}; use bevy_input::InputSystem; -use bevy_math::Rect; use bevy_transform::TransformSystem; use bevy_window::ModifiesWindows; use update::{ui_z_system, update_clipping_system}; @@ -71,7 +70,7 @@ impl Plugin for UiPlugin { .register_type::() .register_type::>() .register_type::>() - .register_type::>() + .register_type::>() .register_type::