bevy/crates
ickshonpe dc124ee498
ContentSize replacement fix (#9753)
# Objective

If you remove a `ContentSize` component from a Bevy UI entity and then
replace it `ui_layout_system` will remove the measure func from the
internal Taffy layout tree but no new measure func will be generated to
replace it since it's the widget systems that are responsible for
creating their respective measure funcs not `ui_layout_system`. The
widget systems only perform a measure func update on changes to a widget
entity's content. This means that until its content is changed in some
way, no content will be displayed by the node.

### Example

This example spawns a text node which disappears after a few moments
once its `ContentSize` component is replaced.

```rust
use bevy::prelude::*;
use bevy::ui::ContentSize;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, delayed_replacement)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(
        TextBundle::from_section(
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
            TextStyle::default(),
        )
    );
}

// Waits a few frames to make sure the font is loaded and the text's glyph layout has been generated.
fn delayed_replacement(mut commands: Commands, mut count: Local<usize>, query: Query<Entity, With<Style>>) {
    *count += 1;
    if *count == 10 {
        for item in query.iter() {
            commands
                .entity(item)
                .remove::<ContentSize>()
                .insert(ContentSize::default());
        }
    }
}
```

## Solution

Perform `ui_layout_system`'s `ContentSize` removal detection and
resolution first, before the measure func updates.
Then in the widget systems, generate a new `Measure` when a
`ContentSize` component is added to a widget entity.

## Changelog

* `measure_text_system`, `update_image_content_size_system` and
`update_atlas_content_size_system` generate a new `Measure` when a
`ContentSize` component is added.
2023-09-18 08:54:39 +00:00
..
bevy_a11y Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_animation Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_app Replace IntoSystemSetConfig with IntoSystemSetConfigs (#9247) 2023-09-05 17:15:27 +00:00
bevy_asset Manual "Reflect Value" AssetPath impl to fix dynamic linking (#9752) 2023-09-13 18:29:19 +00:00
bevy_audio Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_core Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_core_pipeline Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_derive bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_diagnostic Add DiagnosticsStore::iter_mut (#9679) 2023-09-03 13:26:13 +00:00
bevy_dylib Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_dynamic_plugin Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_ecs Remove some old references to CoreSet (#9833) 2023-09-18 01:07:11 +00:00
bevy_ecs_compile_fail_tests Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
bevy_encase_derive Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_gilrs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
bevy_gizmos Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_gltf Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
bevy_hierarchy Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
bevy_input Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
bevy_internal "serialize" feature no longer enables the optional "bevy_scene" feature if it's not enabled from elsewhere (#9803) 2023-09-14 21:15:00 +00:00
bevy_log Update tracy-client requirement from 0.15 to 0.16 (#9436) 2023-08-15 07:45:21 +00:00
bevy_macro_utils Add some more helpful errors to BevyManifest when it doesn't find Cargo.toml (#9207) 2023-07-19 12:05:04 +00:00
bevy_macros_compile_fail_tests bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_math Fix erronenous glam version (#9653) 2023-08-31 12:55:17 +00:00
bevy_mikktspace Fix erronenous glam version (#9653) 2023-08-31 12:55:17 +00:00
bevy_pbr Fix wireframe for skinned/morphed meshes (#9734) 2023-09-11 19:14:15 +00:00
bevy_ptr Put #[repr(transparent)] attr to bevy_ptr types (#9068) 2023-07-14 18:55:15 +00:00
bevy_reflect Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
bevy_reflect_compile_fail_tests Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
bevy_render generate indices for Mikktspace (#8862) 2023-09-16 22:10:58 +00:00
bevy_scene Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
bevy_sprite TextureAtlasBuilder padding (#9494) 2023-09-08 15:02:48 +00:00
bevy_tasks elaborate on TaskPool and bevy tasks (#8750) 2023-08-11 21:07:28 +00:00
bevy_text Remove z-axis scaling in extract_text2d_sprite (#9733) 2023-09-11 19:12:23 +00:00
bevy_time Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
bevy_transform Rename RemovedComponents::iter/iter_with_id to read/read_with_id (#9778) 2023-09-15 12:37:20 +00:00
bevy_ui ContentSize replacement fix (#9753) 2023-09-18 08:54:39 +00:00
bevy_utils Manual "Reflect Value" AssetPath impl to fix dynamic linking (#9752) 2023-09-13 18:29:19 +00:00
bevy_window Refer to "macOS", not "macOS X". (#9704) 2023-09-05 19:06:08 +00:00
bevy_winit Rename RemovedComponents::iter/iter_with_id to read/read_with_id (#9778) 2023-09-15 12:37:20 +00:00