
# Objective - `bevy_text` used to be "optional". the feature could be disabled, which meant that the systems were not added but `bevy_text` was still compiled because of a hard dependency in `bevy_ui` - Running something without `bevy_text` enabled and with `bevy_ui` enabled now crashes: ``` thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /bevy/crates/bevy_ecs/src/schedule/schedule.rs:1147:34 ``` - This is because `bevy_ui` declares some of its systems in ambiguity sets with systems from `bevy_text`, which were not added if `bevy_text` is disabled ## Solution - Make `bevy_text` completely optional ## Migration Guide - feature `bevy_text` now completely removes `bevy_text` from the dependencies when not enabled. Enable feature `bevy_text` if you use Bevy to render text
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use crate::{CalculatedSize, UiImage};
|
|
use bevy_asset::Assets;
|
|
#[cfg(feature = "bevy_text")]
|
|
use bevy_ecs::query::Without;
|
|
use bevy_ecs::system::{Query, Res};
|
|
use bevy_math::Vec2;
|
|
use bevy_render::texture::Image;
|
|
#[cfg(feature = "bevy_text")]
|
|
use bevy_text::Text;
|
|
|
|
/// Updates calculated size of the node based on the image provided
|
|
pub fn update_image_calculated_size_system(
|
|
textures: Res<Assets<Image>>,
|
|
#[cfg(feature = "bevy_text")] mut query: Query<(&mut CalculatedSize, &UiImage), Without<Text>>,
|
|
#[cfg(not(feature = "bevy_text"))] mut query: Query<(&mut CalculatedSize, &UiImage)>,
|
|
) {
|
|
for (mut calculated_size, image) in &mut query {
|
|
if let Some(texture) = textures.get(&image.texture) {
|
|
let size = Vec2::new(
|
|
texture.texture_descriptor.size.width as f32,
|
|
texture.texture_descriptor.size.height as f32,
|
|
);
|
|
// Update only if size has changed to avoid needless layout calculations
|
|
if size != calculated_size.size {
|
|
calculated_size.size = size;
|
|
calculated_size.preserve_aspect_ratio = true;
|
|
}
|
|
}
|
|
}
|
|
}
|