From c18f9ae3de664a1991ae09561dd32527ddcf072d Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Sat, 4 Mar 2023 14:24:07 +0000 Subject: [PATCH 01/14] Replaced the image from the `UI` example that was removed by the AccessKit PR. --- examples/ui/ui.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index f06b5c161bf10..936f82aacc95c 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -293,6 +293,8 @@ fn setup(mut commands: Commands, asset_server: Res) { size: Size::width(Val::Px(500.0)), ..default() }, + image: asset_server.load("branding/bevy_logo_dark_big.png").into(), + ..default() ..default() }) .with_children(|parent| { From 50daa18ffbd57fa6636e7d42ea187996391b8158 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Sat, 4 Mar 2023 14:24:37 +0000 Subject: [PATCH 02/14] removed the alt text --- examples/ui/ui.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 936f82aacc95c..d992a7ed5bed6 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -294,14 +294,13 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, image: asset_server.load("branding/bevy_logo_dark_big.png").into(), - ..default() ..default() - }) - .with_children(|parent| { - // alt text - parent - .spawn(TextBundle::from_section("Bevy logo", TextStyle::default())); }); + // .with_children(|parent| { + // // alt text + // parent + // .spawn(TextBundle::from_section("Bevy logo", TextStyle::default())); + // }); }); }); } From d49d2b97c5c5b4159627577ce58cdeb0ae23be19 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Sat, 4 Mar 2023 14:37:15 +0000 Subject: [PATCH 03/14] remove comment --- examples/ui/ui.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index d992a7ed5bed6..a06354ed4ad28 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -296,11 +296,6 @@ fn setup(mut commands: Commands, asset_server: Res) { image: asset_server.load("branding/bevy_logo_dark_big.png").into(), ..default() }); - // .with_children(|parent| { - // // alt text - // parent - // .spawn(TextBundle::from_section("Bevy logo", TextStyle::default())); - // }); }); }); } From b037850444f6b78aba426bbf11137bfe3ddd0a9a Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Sat, 4 Mar 2023 14:55:37 +0000 Subject: [PATCH 04/14] cargo fmt --all --- examples/ui/ui.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index a06354ed4ad28..88f6b77cbb4b4 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -295,6 +295,17 @@ fn setup(mut commands: Commands, asset_server: Res) { }, image: asset_server.load("branding/bevy_logo_dark_big.png").into(), ..default() + }) + .with_children(|parent| { + // alt text + parent.spawn(TextBundle::from_section( + "Bevy logo", + TextStyle { + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + font_size: 20., + color: Color::WHITE, + }, + )); }); }); }); From 27d74e1f0267a2d70ebfd66d09a6d4f5fd28bd5b Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Sat, 4 Mar 2023 16:03:13 +0000 Subject: [PATCH 05/14] set logo image to display at a fixed size --- examples/ui/ui.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 88f6b77cbb4b4..f5961658d7dc8 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -290,7 +290,8 @@ fn setup(mut commands: Commands, asset_server: Res) { parent .spawn(ImageBundle { style: Style { - size: Size::width(Val::Px(500.0)), + min_size: Size::new(Val::Px(500.0), Val::Px(125.0)), + max_size: Size::new(Val::Px(500.0), Val::Px(125.0)), ..default() }, image: asset_server.load("branding/bevy_logo_dark_big.png").into(), @@ -298,14 +299,8 @@ fn setup(mut commands: Commands, asset_server: Res) { }) .with_children(|parent| { // alt text - parent.spawn(TextBundle::from_section( - "Bevy logo", - TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), - font_size: 20., - color: Color::WHITE, - }, - )); + parent + .spawn(TextBundle::from_section("Bevy logo", TextStyle::default())); }); }); }); From 63dc311577f554d73a66b7eba66b9f2eb8d615c3 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 12:18:51 +0000 Subject: [PATCH 06/14] cargo fmt --all --- examples/ui/ui.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index f5961658d7dc8..affcb8927f587 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -288,15 +288,18 @@ fn setup(mut commands: Commands, asset_server: Res) { .with_children(|parent| { // bevy logo (image) parent - .spawn(ImageBundle { - style: Style { - min_size: Size::new(Val::Px(500.0), Val::Px(125.0)), - max_size: Size::new(Val::Px(500.0), Val::Px(125.0)), + .spawn(( + NodeBundle { + style: Style { + min_size: Size::new(Val::Px(500.0), Val::Px(125.0)), + max_size: Size::new(Val::Px(500.0), Val::Px(125.0)), + ..default() + }, + background_color: Color::WHITE.into(), ..default() }, - image: asset_server.load("branding/bevy_logo_dark_big.png").into(), - ..default() - }) + UiImage::new(asset_server.load("branding/bevy_logo_dark_big.png")), + )) .with_children(|parent| { // alt text parent From 6c7b2ab56bf8045e28ea386b31fbf565fb2943f2 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 13:54:46 +0000 Subject: [PATCH 07/14] Added helper functions that calculate the size of a ui node from its node and transform --- crates/bevy_ui/src/helpers.rs | 18 ++++++++++++++++++ crates/bevy_ui/src/lib.rs | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 crates/bevy_ui/src/helpers.rs diff --git a/crates/bevy_ui/src/helpers.rs b/crates/bevy_ui/src/helpers.rs new file mode 100644 index 0000000000000..3cc75aef97cd0 --- /dev/null +++ b/crates/bevy_ui/src/helpers.rs @@ -0,0 +1,18 @@ +use bevy_math::Rect; +use bevy_transform::prelude::GlobalTransform; + +use crate::Node; + +// calculate the geometry of a ui node in logical pixels +pub fn logical_node_rect(node: &Node, transform: &GlobalTransform) -> Rect { + Rect::from_center_size(transform.translation().truncate(), node.size()) +} + +// calculate the geometry of a ui node in physical pixels +pub fn physical_node_rect(node: &Node, transform: &GlobalTransform, scale_factor: f32) -> Rect { + let rect = logical_node_rect(node, transform); + Rect { + min: rect.min / scale_factor, + max: rect.max / scale_factor, + } +} \ No newline at end of file diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index b668c2b9515a4..062210de1f936 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -8,6 +8,7 @@ mod geometry; mod render; mod stack; mod ui_node; +pub mod helpers; #[cfg(feature = "bevy_text")] mod accessibility; @@ -29,7 +30,7 @@ pub use ui_node::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - camera_config::*, geometry::*, node_bundles::*, ui_node::*, widget::*, Interaction, UiScale, + camera_config::*, geometry::*, node_bundles::*, ui_node::*, widget::*, Interaction, UiScale, }; } From 91e9d23401c38219a0bc4536487e1e2644cef8e1 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 14:08:30 +0000 Subject: [PATCH 08/14] Implemented helper functions as methods on `Node` instead. --- crates/bevy_ui/src/helpers.rs | 18 ------------------ crates/bevy_ui/src/lib.rs | 1 - crates/bevy_ui/src/ui_node.rs | 13 +++++++++++++ 3 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 crates/bevy_ui/src/helpers.rs diff --git a/crates/bevy_ui/src/helpers.rs b/crates/bevy_ui/src/helpers.rs deleted file mode 100644 index 3cc75aef97cd0..0000000000000 --- a/crates/bevy_ui/src/helpers.rs +++ /dev/null @@ -1,18 +0,0 @@ -use bevy_math::Rect; -use bevy_transform::prelude::GlobalTransform; - -use crate::Node; - -// calculate the geometry of a ui node in logical pixels -pub fn logical_node_rect(node: &Node, transform: &GlobalTransform) -> Rect { - Rect::from_center_size(transform.translation().truncate(), node.size()) -} - -// calculate the geometry of a ui node in physical pixels -pub fn physical_node_rect(node: &Node, transform: &GlobalTransform, scale_factor: f32) -> Rect { - let rect = logical_node_rect(node, transform); - Rect { - min: rect.min / scale_factor, - max: rect.max / scale_factor, - } -} \ No newline at end of file diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 062210de1f936..3c3b1a5f4422c 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -8,7 +8,6 @@ mod geometry; mod render; mod stack; mod ui_node; -pub mod helpers; #[cfg(feature = "bevy_text")] mod accessibility; diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 46beae57f8247..d7be16d1a72eb 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -7,6 +7,7 @@ use bevy_render::{ color::Color, texture::{Image, DEFAULT_IMAGE_HANDLE}, }; +use bevy_transform::prelude::GlobalTransform; use serde::{Deserialize, Serialize}; use std::ops::{Div, DivAssign, Mul, MulAssign}; use thiserror::Error; @@ -26,6 +27,18 @@ impl Node { pub fn size(&self) -> Vec2 { self.calculated_size } + + pub fn logical_rect(&self, transform: &GlobalTransform) -> Rect { + Rect::from_center_size(transform.translation().truncate(), self.size()) + } + + pub fn physical_rect(&self, transform: &GlobalTransform, scale_factor: f32) -> Rect { + let rect = self.logical_rect(transform); + Rect { + min: rect.min / scale_factor, + max: rect.max / scale_factor, + } + } } impl Node { From 6e33fc0c40c5d768fc1560f26747ef29a3bf0901 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 14:12:19 +0000 Subject: [PATCH 09/14] cargo fmt --- crates/bevy_ui/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 3c3b1a5f4422c..b668c2b9515a4 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -29,7 +29,7 @@ pub use ui_node::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - camera_config::*, geometry::*, node_bundles::*, ui_node::*, widget::*, Interaction, UiScale, + camera_config::*, geometry::*, node_bundles::*, ui_node::*, widget::*, Interaction, UiScale, }; } From b5386a31c8199d239d7f2b9649851f598ccbd39c Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 14:25:36 +0000 Subject: [PATCH 10/14] undo ui example changes --- examples/ui/ui.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index affcb8927f587..5b71f3dc05c1c 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -288,18 +288,13 @@ fn setup(mut commands: Commands, asset_server: Res) { .with_children(|parent| { // bevy logo (image) parent - .spawn(( - NodeBundle { - style: Style { - min_size: Size::new(Val::Px(500.0), Val::Px(125.0)), - max_size: Size::new(Val::Px(500.0), Val::Px(125.0)), - ..default() - }, - background_color: Color::WHITE.into(), + .spawn(ImageBundle { + style: Style { + size: Size::width(Val::Px(500.0)), ..default() }, - UiImage::new(asset_server.load("branding/bevy_logo_dark_big.png")), - )) + ..default() + }) .with_children(|parent| { // alt text parent @@ -336,4 +331,4 @@ fn mouse_scroll( style.position.top = Val::Px(scrolling_list.position); } } -} +} \ No newline at end of file From dd981d7b7d4136973da22c1ed91bf46115a30075 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Mon, 6 Mar 2023 14:26:52 +0000 Subject: [PATCH 11/14] cargo fmt --all --- examples/ui/ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 5b71f3dc05c1c..f06b5c161bf10 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -331,4 +331,4 @@ fn mouse_scroll( style.position.top = Val::Px(scrolling_list.position); } } -} \ No newline at end of file +} From b4cf3d96035c2762257affb4c5faebd72286ab87 Mon Sep 17 00:00:00 2001 From: Ickshonpe Date: Thu, 9 Mar 2023 09:32:30 +0000 Subject: [PATCH 12/14] * Added doc comments for both methods. * Inlined both methods. --- crates/bevy_ui/src/ui_node.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index d7be16d1a72eb..d1daff2d584dd 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -28,10 +28,14 @@ impl Node { self.calculated_size } + /// Returns the logical pixel coordinates of the UI node, based on its GlobalTransform. + #[inline] pub fn logical_rect(&self, transform: &GlobalTransform) -> Rect { Rect::from_center_size(transform.translation().truncate(), self.size()) } + /// Returns the physical pixel coordinates of the UI node, based on its GlobalTransform and the scale factor. + #[inline] pub fn physical_rect(&self, transform: &GlobalTransform, scale_factor: f32) -> Rect { let rect = self.logical_rect(transform); Rect { From b219cb9bf0505f6dc3ae68e05a453d94099218fc Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 9 Mar 2023 10:15:48 +0000 Subject: [PATCH 13/14] Update crates/bevy_ui/src/ui_node.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_ui/src/ui_node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index d1daff2d584dd..d2592e18c2243 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -28,7 +28,7 @@ impl Node { self.calculated_size } - /// Returns the logical pixel coordinates of the UI node, based on its GlobalTransform. + /// Returns the logical pixel coordinates of the UI node, based on its `GlobalTransform`. #[inline] pub fn logical_rect(&self, transform: &GlobalTransform) -> Rect { Rect::from_center_size(transform.translation().truncate(), self.size()) From f0b355bb941a22194edbc3fcb0a735275ab49ed6 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 9 Mar 2023 10:15:54 +0000 Subject: [PATCH 14/14] Update crates/bevy_ui/src/ui_node.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_ui/src/ui_node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index d2592e18c2243..c2fe33a27d3f1 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -34,7 +34,7 @@ impl Node { Rect::from_center_size(transform.translation().truncate(), self.size()) } - /// Returns the physical pixel coordinates of the UI node, based on its GlobalTransform and the scale factor. + /// Returns the physical pixel coordinates of the UI node, based on its `GlobalTransform` and the scale factor. #[inline] pub fn physical_rect(&self, transform: &GlobalTransform, scale_factor: f32) -> Rect { let rect = self.logical_rect(transform);