From baa1517efe4ab16ed19124dd539a2402d2f32dbf Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Wed, 28 Jun 2023 16:06:15 +0200 Subject: [PATCH 1/3] Fix bevy_ui compilation failure without bevy_text --- crates/bevy_ui/src/measurement.rs | 27 ++++++++++--------------- crates/bevy_ui/src/node_bundles.rs | 2 +- crates/bevy_ui/src/widget/image.rs | 32 ++++++++++-------------------- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/crates/bevy_ui/src/measurement.rs b/crates/bevy_ui/src/measurement.rs index fd31ae9ab4f96..344efd3775d2e 100644 --- a/crates/bevy_ui/src/measurement.rs +++ b/crates/bevy_ui/src/measurement.rs @@ -4,6 +4,7 @@ use bevy_math::Vec2; use bevy_reflect::Reflect; use std::fmt::Formatter; pub use taffy::style::AvailableSpace; +use taffy::{node::MeasureFunc, prelude::Size as TaffySize}; impl std::fmt::Debug for ContentSize { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { @@ -50,33 +51,27 @@ impl Measure for FixedMeasure { pub struct ContentSize { /// The `Measure` used to compute the intrinsic size #[reflect(ignore)] - pub(crate) measure_func: Option, + pub(crate) measure_func: Option, } impl ContentSize { /// Set a `Measure` for this function pub fn set(&mut self, measure: impl Measure) { - let measure_func = - move |size: taffy::prelude::Size>, - available: taffy::prelude::Size| { - let size = - measure.measure(size.width, size.height, available.width, available.height); - taffy::prelude::Size { - width: size.x, - height: size.y, - } - }; - self.measure_func = Some(taffy::node::MeasureFunc::Boxed(Box::new(measure_func))); + let measure_func = move |size: TaffySize<_>, available: TaffySize<_>| { + let size = measure.measure(size.width, size.height, available.width, available.height); + TaffySize { + width: size.x, + height: size.y, + } + }; + self.measure_func = Some(MeasureFunc::Boxed(Box::new(measure_func))); } } -#[allow(clippy::derivable_impls)] impl Default for ContentSize { fn default() -> Self { Self { - measure_func: Some(taffy::node::MeasureFunc::Raw(|_, _| { - taffy::prelude::Size::ZERO - })), + measure_func: Some(MeasureFunc::Raw(|_, _| TaffySize::ZERO)), } } } diff --git a/crates/bevy_ui/src/node_bundles.rs b/crates/bevy_ui/src/node_bundles.rs index a8c82a4828893..8cc7bc6bb700c 100644 --- a/crates/bevy_ui/src/node_bundles.rs +++ b/crates/bevy_ui/src/node_bundles.rs @@ -172,7 +172,7 @@ pub struct TextBundle { /// Text layout information pub text_layout_info: TextLayoutInfo, /// Text system flags - pub text_flags: TextFlags, + pub text_flags: crate::widget::TextFlags, /// The calculated size based on the given image pub calculated_size: ContentSize, /// Whether this node should block interaction with lower nodes diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index be9df0590c09c..8ff005778ba47 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -3,7 +3,6 @@ use crate::{ }; use bevy_asset::{Assets, Handle}; -#[cfg(feature = "bevy_text")] use bevy_ecs::query::Without; use bevy_ecs::{ prelude::Component, @@ -15,8 +14,6 @@ use bevy_math::Vec2; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; -#[cfg(feature = "bevy_text")] -use bevy_text::Text; use bevy_window::{PrimaryWindow, Window}; /// The size of the image's texture @@ -73,20 +70,20 @@ impl Measure for ImageMeasure { } } +/// The filter type for `update_image_content_size_system` and `update_atlas_content_size_system`. +#[cfg(feature = "bevy_text")] +pub type UpdateImageFilter = (With, Without); +/// The filter type for `update_image_content_size_system` and `update_atlas_content_size_system`. +#[cfg(not(feature = "bevy_text"))] +pub type UpdateImageFilter = With; + /// Updates content size of the node based on the image provided pub fn update_image_content_size_system( mut previous_combined_scale_factor: Local, windows: Query<&Window, With>, ui_scale: Res, textures: Res>, - #[cfg(feature = "bevy_text")] mut query: Query< - (&mut ContentSize, &UiImage, &mut UiImageSize), - (With, Without), - >, - #[cfg(not(feature = "bevy_text"))] mut query: Query< - (&mut ContentSize, &UiImage, &mut UiImageSize), - With, - >, + mut query: Query<(&mut ContentSize, &UiImage, &mut UiImageSize), UpdateImageFilter>, ) { let combined_scale_factor = windows .get_single() @@ -120,23 +117,14 @@ pub fn update_atlas_content_size_system( windows: Query<&Window, With>, ui_scale: Res, atlases: Res>, - #[cfg(feature = "bevy_text")] mut atlas_query: Query< - ( - &mut ContentSize, - &Handle, - &UiTextureAtlasImage, - &mut UiImageSize, - ), - (With, Without, Without), - >, - #[cfg(not(feature = "bevy_text"))] mut atlas_query: Query< + mut atlas_query: Query< ( &mut ContentSize, &Handle, &UiTextureAtlasImage, &mut UiImageSize, ), - (With, Without), + (UpdateImageFilter, Without), >, ) { let combined_scale_factor = windows From de7a6a9750298c5a106ec7b834e89d16d12505b4 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 29 Jun 2023 07:42:26 +0200 Subject: [PATCH 2/3] Revert qualified path --- crates/bevy_ui/src/node_bundles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/node_bundles.rs b/crates/bevy_ui/src/node_bundles.rs index 8cc7bc6bb700c..a8c82a4828893 100644 --- a/crates/bevy_ui/src/node_bundles.rs +++ b/crates/bevy_ui/src/node_bundles.rs @@ -172,7 +172,7 @@ pub struct TextBundle { /// Text layout information pub text_layout_info: TextLayoutInfo, /// Text system flags - pub text_flags: crate::widget::TextFlags, + pub text_flags: TextFlags, /// The calculated size based on the given image pub calculated_size: ContentSize, /// Whether this node should block interaction with lower nodes From 242433647f006a7f9f48c1319c136efa45e5e7e2 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 29 Jun 2023 11:37:36 +0200 Subject: [PATCH 3/3] Make UpdateImageFilter private --- crates/bevy_ui/src/widget/image.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 8ff005778ba47..f46dd5b4faa38 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -70,12 +70,10 @@ impl Measure for ImageMeasure { } } -/// The filter type for `update_image_content_size_system` and `update_atlas_content_size_system`. #[cfg(feature = "bevy_text")] -pub type UpdateImageFilter = (With, Without); -/// The filter type for `update_image_content_size_system` and `update_atlas_content_size_system`. +type UpdateImageFilter = (With, Without); #[cfg(not(feature = "bevy_text"))] -pub type UpdateImageFilter = With; +type UpdateImageFilter = With; /// Updates content size of the node based on the image provided pub fn update_image_content_size_system(