Skip to content

Commit 9478432

Browse files
authored
Fix bevy_ui compilation failure without bevy_text (#8985)
# Objective - Fix #8984 ### Solution - Address compilation errors I admit: I did sneak it an unrelated mini-refactor. of the `measurment.rs` module. it seemed to me that directly importing `taffy` types helped reduce a lot of boilerplate, so I did it.
1 parent 7aa0a47 commit 9478432

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

crates/bevy_ui/src/measurement.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bevy_math::Vec2;
44
use bevy_reflect::Reflect;
55
use std::fmt::Formatter;
66
pub use taffy::style::AvailableSpace;
7+
use taffy::{node::MeasureFunc, prelude::Size as TaffySize};
78

89
impl std::fmt::Debug for ContentSize {
910
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
@@ -50,33 +51,27 @@ impl Measure for FixedMeasure {
5051
pub struct ContentSize {
5152
/// The `Measure` used to compute the intrinsic size
5253
#[reflect(ignore)]
53-
pub(crate) measure_func: Option<taffy::node::MeasureFunc>,
54+
pub(crate) measure_func: Option<MeasureFunc>,
5455
}
5556

5657
impl ContentSize {
5758
/// Set a `Measure` for this function
5859
pub fn set(&mut self, measure: impl Measure) {
59-
let measure_func =
60-
move |size: taffy::prelude::Size<Option<f32>>,
61-
available: taffy::prelude::Size<AvailableSpace>| {
62-
let size =
63-
measure.measure(size.width, size.height, available.width, available.height);
64-
taffy::prelude::Size {
65-
width: size.x,
66-
height: size.y,
67-
}
68-
};
69-
self.measure_func = Some(taffy::node::MeasureFunc::Boxed(Box::new(measure_func)));
60+
let measure_func = move |size: TaffySize<_>, available: TaffySize<_>| {
61+
let size = measure.measure(size.width, size.height, available.width, available.height);
62+
TaffySize {
63+
width: size.x,
64+
height: size.y,
65+
}
66+
};
67+
self.measure_func = Some(MeasureFunc::Boxed(Box::new(measure_func)));
7068
}
7169
}
7270

73-
#[allow(clippy::derivable_impls)]
7471
impl Default for ContentSize {
7572
fn default() -> Self {
7673
Self {
77-
measure_func: Some(taffy::node::MeasureFunc::Raw(|_, _| {
78-
taffy::prelude::Size::ZERO
79-
})),
74+
measure_func: Some(MeasureFunc::Raw(|_, _| TaffySize::ZERO)),
8075
}
8176
}
8277
}

crates/bevy_ui/src/widget/image.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
};
44
use bevy_asset::{Assets, Handle};
55

6-
#[cfg(feature = "bevy_text")]
76
use bevy_ecs::query::Without;
87
use bevy_ecs::{
98
prelude::Component,
@@ -15,8 +14,6 @@ use bevy_math::Vec2;
1514
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1615
use bevy_render::texture::Image;
1716
use bevy_sprite::TextureAtlas;
18-
#[cfg(feature = "bevy_text")]
19-
use bevy_text::Text;
2017
use bevy_window::{PrimaryWindow, Window};
2118

2219
/// The size of the image's texture
@@ -73,20 +70,18 @@ impl Measure for ImageMeasure {
7370
}
7471
}
7572

73+
#[cfg(feature = "bevy_text")]
74+
type UpdateImageFilter = (With<Node>, Without<bevy_text::Text>);
75+
#[cfg(not(feature = "bevy_text"))]
76+
type UpdateImageFilter = With<Node>;
77+
7678
/// Updates content size of the node based on the image provided
7779
pub fn update_image_content_size_system(
7880
mut previous_combined_scale_factor: Local<f64>,
7981
windows: Query<&Window, With<PrimaryWindow>>,
8082
ui_scale: Res<UiScale>,
8183
textures: Res<Assets<Image>>,
82-
#[cfg(feature = "bevy_text")] mut query: Query<
83-
(&mut ContentSize, &UiImage, &mut UiImageSize),
84-
(With<Node>, Without<Text>),
85-
>,
86-
#[cfg(not(feature = "bevy_text"))] mut query: Query<
87-
(&mut ContentSize, &UiImage, &mut UiImageSize),
88-
With<Node>,
89-
>,
84+
mut query: Query<(&mut ContentSize, &UiImage, &mut UiImageSize), UpdateImageFilter>,
9085
) {
9186
let combined_scale_factor = windows
9287
.get_single()
@@ -120,23 +115,14 @@ pub fn update_atlas_content_size_system(
120115
windows: Query<&Window, With<PrimaryWindow>>,
121116
ui_scale: Res<UiScale>,
122117
atlases: Res<Assets<TextureAtlas>>,
123-
#[cfg(feature = "bevy_text")] mut atlas_query: Query<
124-
(
125-
&mut ContentSize,
126-
&Handle<TextureAtlas>,
127-
&UiTextureAtlasImage,
128-
&mut UiImageSize,
129-
),
130-
(With<Node>, Without<Text>, Without<UiImage>),
131-
>,
132-
#[cfg(not(feature = "bevy_text"))] mut atlas_query: Query<
118+
mut atlas_query: Query<
133119
(
134120
&mut ContentSize,
135121
&Handle<TextureAtlas>,
136122
&UiTextureAtlasImage,
137123
&mut UiImageSize,
138124
),
139-
(With<Node>, Without<UiImage>),
125+
(UpdateImageFilter, Without<UiImage>),
140126
>,
141127
) {
142128
let combined_scale_factor = windows

0 commit comments

Comments
 (0)