From 2b0b9af2016a4c153f9c120b49fab8409a2875d8 Mon Sep 17 00:00:00 2001 From: KDecay Date: Mon, 25 Apr 2022 13:54:46 +0000 Subject: [PATCH] Move `Size` to `bevy_ui` (#4285) # Objective - Related #4276. - Part of the splitting process of #3503. ## Solution - Move `Size` to `bevy_ui`. ## Reasons - `Size` is only needed in `bevy_ui` (because it needs to use `Val` instead of `f32`), but it's also used as a worse `Vec2` replacement in other areas. - `Vec2` is more powerful than `Size` so it should be used whenever possible. - Discussion in #3503. ## Changelog ### Changed - The `Size` type got moved from `bevy_math` to `bevy_ui`. ## Migration Guide - The `Size` type got moved from `bevy::math` to `bevy::ui`. To migrate you just have to import `bevy::ui::Size` instead of `bevy::math::Math` or use the `bevy::prelude` instead. Co-authored-by: KDecay --- crates/bevy_math/src/geometry.rs | 148 ----------------------- crates/bevy_math/src/lib.rs | 4 +- crates/bevy_pbr/src/render/mesh.rs | 4 +- crates/bevy_render/src/texture/image.rs | 8 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 4 +- crates/bevy_sprite/src/render/mod.rs | 2 +- crates/bevy_text/src/glyph_brush.rs | 6 +- crates/bevy_text/src/pipeline.rs | 10 +- crates/bevy_text/src/text2d.rs | 28 ++--- crates/bevy_ui/src/flex/convert.rs | 4 +- crates/bevy_ui/src/geometry.rs | 149 ++++++++++++++++++++++++ crates/bevy_ui/src/lib.rs | 7 +- crates/bevy_ui/src/ui_node.rs | 3 +- crates/bevy_ui/src/widget/image.rs | 2 +- crates/bevy_ui/src/widget/text.rs | 10 +- examples/2d/text2d.rs | 8 +- 16 files changed, 201 insertions(+), 196 deletions(-) create mode 100644 crates/bevy_ui/src/geometry.rs diff --git a/crates/bevy_math/src/geometry.rs b/crates/bevy_math/src/geometry.rs index 0a449e5d026f9f..ed93591485e36d 100644 --- a/crates/bevy_math/src/geometry.rs +++ b/crates/bevy_math/src/geometry.rs @@ -1,29 +1,4 @@ use bevy_reflect::Reflect; -use glam::Vec2; -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; - -/// A two dimensional "size" as defined by a width and height -#[derive(Copy, Clone, PartialEq, Debug, Reflect)] -#[reflect(PartialEq)] -pub struct Size { - pub width: T, - pub height: T, -} - -impl Size { - pub fn new(width: T, height: T) -> Self { - Size { width, height } - } -} - -impl Default for Size { - fn default() -> Self { - Self { - width: Default::default(), - height: Default::default(), - } - } -} /// A rect, as defined by its "side" locations #[derive(Copy, Clone, PartialEq, Debug, Reflect)] @@ -59,126 +34,3 @@ impl Default for Rect { } } } - -impl Add for Size -where - T: Add, -{ - type Output = Size; - - fn add(self, rhs: Vec2) -> Self::Output { - Self { - width: self.width + rhs.x, - height: self.height + rhs.y, - } - } -} - -impl AddAssign for Size -where - T: AddAssign, -{ - fn add_assign(&mut self, rhs: Vec2) { - self.width += rhs.x; - self.height += rhs.y; - } -} - -impl Sub for Size -where - T: Sub, -{ - type Output = Size; - - fn sub(self, rhs: Vec2) -> Self::Output { - Self { - width: self.width - rhs.x, - height: self.height - rhs.y, - } - } -} - -impl SubAssign for Size -where - T: SubAssign, -{ - fn sub_assign(&mut self, rhs: Vec2) { - self.width -= rhs.x; - self.height -= rhs.y; - } -} - -impl Mul for Size -where - T: Mul, -{ - type Output = Size; - - fn mul(self, rhs: f32) -> Self::Output { - Self::Output { - width: self.width * rhs, - height: self.height * rhs, - } - } -} - -impl MulAssign for Size -where - T: MulAssign, -{ - fn mul_assign(&mut self, rhs: f32) { - self.width *= rhs; - self.height *= rhs; - } -} - -impl Div for Size -where - T: Div, -{ - type Output = Size; - - fn div(self, rhs: f32) -> Self::Output { - Self::Output { - width: self.width / rhs, - height: self.height / rhs, - } - } -} - -impl DivAssign for Size -where - T: DivAssign, -{ - fn div_assign(&mut self, rhs: f32) { - self.width /= rhs; - self.height /= rhs; - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn size_ops() { - type SizeF = Size; - - assert_eq!( - SizeF::new(10., 10.) + Vec2::new(10., 10.), - SizeF::new(20., 20.) - ); - assert_eq!( - SizeF::new(20., 20.) - Vec2::new(10., 10.), - SizeF::new(10., 10.) - ); - assert_eq!(SizeF::new(10., 10.) * 2., SizeF::new(20., 20.)); - assert_eq!(SizeF::new(20., 20.) / 2., SizeF::new(10., 10.)); - - let mut size = SizeF::new(10., 10.); - - size += Vec2::new(10., 10.); - - assert_eq!(size, SizeF::new(20., 20.)); - } -} diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index b09230f7478045..866e4ec4d0c703 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -6,7 +6,7 @@ pub use glam::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, Rect, Size, UVec2, - UVec3, UVec4, Vec2, Vec3, Vec4, + BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, Rect, UVec2, UVec3, + UVec4, Vec2, Vec3, Vec4, }; } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 7cff3f9d9fca8a..2ccc6fde6c37dd 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -9,7 +9,7 @@ use bevy_ecs::{ prelude::*, system::{lifetimeless::*, SystemParamItem}, }; -use bevy_math::{Mat4, Size}; +use bevy_math::{Mat4, Vec2}; use bevy_reflect::TypeUuid; use bevy_render::{ mesh::{ @@ -458,7 +458,7 @@ impl FromWorld for MeshPipeline { texture_view, texture_format: image.texture_descriptor.format, sampler, - size: Size::new( + size: Vec2::new( image.texture_descriptor.size.width as f32, image.texture_descriptor.size.height as f32, ), diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index fa4afe04924efd..f9c3bf9207e1e5 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -14,7 +14,7 @@ use crate::{ }; use bevy_asset::HandleUntyped; use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem}; -use bevy_math::{Size, Vec2}; +use bevy_math::Vec2; use bevy_reflect::TypeUuid; use thiserror::Error; use wgpu::{ @@ -533,14 +533,14 @@ impl TextureFormatPixelInfo for TextureFormat { } /// The GPU-representation of an [`Image`]. -/// Consists of the [`Texture`], its [`TextureView`] and the corresponding [`Sampler`], and the texture's [`Size`]. +/// Consists of the [`Texture`], its [`TextureView`] and the corresponding [`Sampler`], and the texture's size. #[derive(Debug, Clone)] pub struct GpuImage { pub texture: Texture, pub texture_view: TextureView, pub texture_format: TextureFormat, pub sampler: Sampler, - pub size: Size, + pub size: Vec2, } impl RenderAsset for Image { @@ -595,7 +595,7 @@ impl RenderAsset for Image { }; let texture_view = texture.create_view(&TextureViewDescriptor::default()); - let size = Size::new( + let size = Vec2::new( image.texture_descriptor.size.width as f32, image.texture_descriptor.size.height as f32, ); diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 4a804372b978a5..47c4efbbb2c1c3 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -4,7 +4,7 @@ use bevy_ecs::{ prelude::*, system::{lifetimeless::*, SystemParamItem}, }; -use bevy_math::{Mat4, Size}; +use bevy_math::{Mat4, Vec2}; use bevy_reflect::{Reflect, TypeUuid}; use bevy_render::{ mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, @@ -195,7 +195,7 @@ impl FromWorld for Mesh2dPipeline { texture_view, texture_format: image.texture_descriptor.format, sampler, - size: Size::new( + size: Vec2::new( image.texture_descriptor.size.width as f32, image.texture_descriptor.size.height as f32, ), diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 577f9da4d855fb..95ddce0649af28 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -431,7 +431,7 @@ pub fn queue_sprites( gpu_images.get(&Handle::weak(new_batch.image_handle_id)) { current_batch = new_batch; - current_image_size = Vec2::new(gpu_image.size.width, gpu_image.size.height); + current_image_size = Vec2::new(gpu_image.size.x, gpu_image.size.y); current_batch_entity = commands.spawn_bundle((current_batch,)).id(); image_bind_groups diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 6d11b07ad1053b..ca7331901775da 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -1,6 +1,6 @@ use ab_glyph::{Font as _, FontArc, Glyph, ScaleFont as _}; use bevy_asset::{Assets, Handle}; -use bevy_math::{Size, Vec2}; +use bevy_math::Vec2; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use glyph_brush_layout::{ @@ -29,11 +29,11 @@ impl GlyphBrush { pub fn compute_glyphs( &self, sections: &[S], - bounds: Size, + bounds: Vec2, text_alignment: TextAlignment, ) -> Result, TextError> { let geom = SectionGeometry { - bounds: (bounds.width, bounds.height), + bounds: (bounds.x, bounds.y), ..Default::default() }; let section_glyphs = Layout::default() diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 5539a4e1d0c07c..5b728552513abf 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -2,7 +2,7 @@ use std::hash::Hash; use ab_glyph::{PxScale, ScaleFont}; use bevy_asset::{Assets, Handle, HandleId}; -use bevy_math::Size; +use bevy_math::Vec2; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_utils::HashMap; @@ -32,7 +32,7 @@ impl Default for TextPipeline { pub struct TextLayoutInfo { pub glyphs: Vec, - pub size: Size, + pub size: Vec2, } impl TextPipeline { @@ -56,7 +56,7 @@ impl TextPipeline { sections: &[TextSection], scale_factor: f64, text_alignment: TextAlignment, - bounds: Size, + bounds: Vec2, font_atlas_set_storage: &mut Assets, texture_atlases: &mut Assets, textures: &mut Assets, @@ -92,7 +92,7 @@ impl TextPipeline { id, TextLayoutInfo { glyphs: Vec::new(), - size: Size::new(0., 0.), + size: Vec2::new(0., 0.), }, ); return Ok(()); @@ -112,7 +112,7 @@ impl TextPipeline { max_y = max_y.max(glyph.position.y - scaled_font.descent()); } - let size = Size::new(max_x - min_x, max_y - min_y); + let size = Vec2::new(max_x - min_x, max_y - min_y); let glyphs = self.brush.process_glyphs( section_glyphs, diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 9bab65aa982970..9127c5932bfcff 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -7,7 +7,7 @@ use bevy_ecs::{ reflect::ReflectComponent, system::{Local, ParamSet, Query, Res, ResMut}, }; -use bevy_math::{Size, Vec3}; +use bevy_math::{Vec2, Vec3}; use bevy_reflect::Reflect; use bevy_render::{texture::Image, view::Visibility, RenderWorld}; use bevy_sprite::{Anchor, ExtractedSprite, ExtractedSprites, TextureAtlas}; @@ -22,7 +22,7 @@ use crate::{ #[derive(Component, Default, Copy, Clone, Debug, Reflect)] #[reflect(Component)] pub struct Text2dSize { - pub size: Size, + pub size: Vec2, } /// The maximum width and height of text. The text will wrap according to the specified size. @@ -35,13 +35,13 @@ pub struct Text2dSize { #[derive(Component, Copy, Clone, Debug, Reflect)] #[reflect(Component)] pub struct Text2dBounds { - pub size: Size, + pub size: Vec2, } impl Default for Text2dBounds { fn default() -> Self { Self { - size: Size::new(f32::MAX, f32::MAX), + size: Vec2::new(f32::MAX, f32::MAX), } } } @@ -73,7 +73,7 @@ pub fn extract_text2d_sprite( if !visibility.is_visible { continue; } - let (width, height) = (calculated_size.size.width, calculated_size.size.height); + let (width, height) = (calculated_size.size.x, calculated_size.size.y); if let Some(text_layout) = text_pipeline.get_glyphs(&entity) { let text_glyphs = &text_layout.glyphs; @@ -161,11 +161,11 @@ pub fn text2d_system( for entity in queued_text.entities.drain(..) { if let Ok((text, bounds, mut calculated_size)) = query.get_mut(entity) { let text_bounds = match bounds { - Some(bounds) => Size { - width: scale_value(bounds.size.width, scale_factor), - height: scale_value(bounds.size.height, scale_factor), - }, - None => Size::new(f32::MAX, f32::MAX), + Some(bounds) => Vec2::new( + scale_value(bounds.size.x, scale_factor), + scale_value(bounds.size.y, scale_factor), + ), + None => Vec2::new(f32::MAX, f32::MAX), }; match text_pipeline.queue_text( entity, @@ -190,10 +190,10 @@ pub fn text2d_system( let text_layout_info = text_pipeline.get_glyphs(&entity).expect( "Failed to get glyphs from the pipeline that have just been computed", ); - calculated_size.size = Size { - width: scale_value(text_layout_info.size.width, 1. / scale_factor), - height: scale_value(text_layout_info.size.height, 1. / scale_factor), - }; + calculated_size.size = Vec2::new( + scale_value(text_layout_info.size.x, 1. / scale_factor), + scale_value(text_layout_info.size.y, 1. / scale_factor), + ); } } } diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index 10e68391343497..fab4e8b8d4dd0f 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -1,8 +1,8 @@ use crate::{ AlignContent, AlignItems, AlignSelf, Direction, Display, FlexDirection, FlexWrap, - JustifyContent, PositionType, Style, Val, + JustifyContent, PositionType, Size, Style, Val, }; -use bevy_math::{Rect, Size}; +use bevy_math::Rect; pub fn from_rect( scale_factor: f64, diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs new file mode 100644 index 00000000000000..f06d1d7ad3cfa1 --- /dev/null +++ b/crates/bevy_ui/src/geometry.rs @@ -0,0 +1,149 @@ +use bevy_math::Vec2; +use bevy_reflect::Reflect; +use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; + +/// A two dimensional "size" as defined by a width and height +#[derive(Copy, Clone, PartialEq, Debug, Reflect)] +#[reflect(PartialEq)] +pub struct Size { + pub width: T, + pub height: T, +} + +impl Size { + pub fn new(width: T, height: T) -> Self { + Size { width, height } + } +} + +impl Default for Size { + fn default() -> Self { + Self { + width: Default::default(), + height: Default::default(), + } + } +} + +impl Add for Size +where + T: Add, +{ + type Output = Size; + + fn add(self, rhs: Vec2) -> Self::Output { + Self { + width: self.width + rhs.x, + height: self.height + rhs.y, + } + } +} + +impl AddAssign for Size +where + T: AddAssign, +{ + fn add_assign(&mut self, rhs: Vec2) { + self.width += rhs.x; + self.height += rhs.y; + } +} + +impl Sub for Size +where + T: Sub, +{ + type Output = Size; + + fn sub(self, rhs: Vec2) -> Self::Output { + Self { + width: self.width - rhs.x, + height: self.height - rhs.y, + } + } +} + +impl SubAssign for Size +where + T: SubAssign, +{ + fn sub_assign(&mut self, rhs: Vec2) { + self.width -= rhs.x; + self.height -= rhs.y; + } +} + +impl Mul for Size +where + T: Mul, +{ + type Output = Size; + + fn mul(self, rhs: f32) -> Self::Output { + Self::Output { + width: self.width * rhs, + height: self.height * rhs, + } + } +} + +impl MulAssign for Size +where + T: MulAssign, +{ + fn mul_assign(&mut self, rhs: f32) { + self.width *= rhs; + self.height *= rhs; + } +} + +impl Div for Size +where + T: Div, +{ + type Output = Size; + + fn div(self, rhs: f32) -> Self::Output { + Self::Output { + width: self.width / rhs, + height: self.height / rhs, + } + } +} + +impl DivAssign for Size +where + T: DivAssign, +{ + fn div_assign(&mut self, rhs: f32) { + self.width /= rhs; + self.height /= rhs; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn size_ops() { + type SizeF = Size; + + assert_eq!( + SizeF::new(10., 10.) + Vec2::new(10., 10.), + SizeF::new(20., 20.) + ); + assert_eq!( + SizeF::new(20., 20.) - Vec2::new(10., 10.), + SizeF::new(10., 10.) + ); + assert_eq!(SizeF::new(10., 10.) * 2., SizeF::new(20., 20.)); + assert_eq!(SizeF::new(20., 20.) / 2., SizeF::new(10., 10.)); + + let mut size = SizeF::new(10., 10.); + + size += Vec2::new(10., 10.); + + assert_eq!(size, SizeF::new(20., 20.)); + } +} diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 872a2bb9eef85b..36ce013d11852f 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -4,6 +4,7 @@ //! This UI is laid out with the Flexbox paradigm (see ) except the vertical axis is inverted mod flex; mod focus; +mod geometry; mod render; mod ui_node; @@ -14,19 +15,21 @@ pub mod widget; use bevy_render::camera::CameraTypePlugin; pub use flex::*; pub use focus::*; +pub use geometry::*; pub use render::*; pub use ui_node::*; #[doc(hidden)] pub mod prelude { #[doc(hidden)] - pub use crate::{entity::*, ui_node::*, widget::Button, Interaction}; + pub use crate::{entity::*, geometry::*, ui_node::*, widget::Button, Interaction}; } +use crate::Size; use bevy_app::prelude::*; use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel}; use bevy_input::InputSystem; -use bevy_math::{Rect, Size}; +use bevy_math::Rect; use bevy_transform::TransformSystem; use update::{ui_z_system, update_clipping_system}; diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index f29e087c825bcd..dbc6d8acd6193b 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -1,6 +1,7 @@ +use crate::Size; use bevy_asset::Handle; use bevy_ecs::{prelude::Component, reflect::ReflectComponent}; -use bevy_math::{Rect, Size, Vec2}; +use bevy_math::{Rect, Vec2}; use bevy_reflect::{Reflect, ReflectDeserialize}; use bevy_render::{ color::Color, diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 9d1a24b55e488d..f8866e72604148 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -1,3 +1,4 @@ +use crate::Size; use crate::{CalculatedSize, UiImage}; use bevy_asset::Assets; use bevy_ecs::{ @@ -6,7 +7,6 @@ use bevy_ecs::{ reflect::ReflectComponent, system::{Query, Res}, }; -use bevy_math::Size; use bevy_reflect::{Reflect, ReflectDeserialize}; use bevy_render::texture::Image; use serde::{Deserialize, Serialize}; diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 9b2d6a9b17b2eb..cb35dd27947abf 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,11 +1,11 @@ -use crate::{CalculatedSize, Style, Val}; +use crate::{CalculatedSize, Size, Style, Val}; use bevy_asset::Assets; use bevy_ecs::{ entity::Entity, query::{Changed, Or, With}, system::{Local, ParamSet, Query, Res, ResMut}, }; -use bevy_math::Size; +use bevy_math::Vec2; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_text::{DefaultTextPipeline, Font, FontAtlasSet, Text, TextError}; @@ -78,7 +78,7 @@ pub fn text_system( let mut query = text_queries.p2(); for entity in queued_text.entities.drain(..) { if let Ok((text, style, mut calculated_size)) = query.get_mut(entity) { - let node_size = Size::new( + let node_size = Vec2::new( text_constraint( style.min_size.width, style.size.width, @@ -117,8 +117,8 @@ pub fn text_system( "Failed to get glyphs from the pipeline that have just been computed", ); calculated_size.size = Size { - width: scale_value(text_layout_info.size.width, inv_scale_factor), - height: scale_value(text_layout_info.size.height, inv_scale_factor), + width: scale_value(text_layout_info.size.x, inv_scale_factor), + height: scale_value(text_layout_info.size.y, inv_scale_factor), }; } } diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index 9a41e7912c2464..e346cee7242e5f 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -52,12 +52,12 @@ fn setup(mut commands: Commands, asset_server: Res) { }) .insert(AnimateScale); // Demonstrate text wrapping - let box_size = Size::new(300.0, 200.0); + let box_size = Vec2::new(300.0, 200.0); let box_position = Vec2::new(0.0, -250.0); commands.spawn_bundle(SpriteBundle { sprite: Sprite { color: Color::rgb(0.25, 0.25, 0.75), - custom_size: Some(Vec2::new(box_size.width, box_size.height)), + custom_size: Some(Vec2::new(box_size.x, box_size.y)), ..default() }, transform: Transform::from_translation(box_position.extend(0.0)), @@ -81,8 +81,8 @@ fn setup(mut commands: Commands, asset_server: Res) { // box is centered at box_position, so it is necessary to move by half of the box size to // keep the text in the box. transform: Transform::from_xyz( - box_position.x - box_size.width / 2.0, - box_position.y + box_size.height / 2.0, + box_position.x - box_size.x / 2.0, + box_position.y + box_size.y / 2.0, 1.0, ), ..default()