bevy/crates/bevy_text/src
ickshonpe 572f0c1a13 Text2d scalefactor change detection fix (#16264)
# Objective 

Text2d doesn't respond to changes to the window scalefactor.

Fixes #16223

## Solution 

In `update_text2d_layout` store the previous scale factor in a `Local`
instead and check against the current scale factor to detect changes.

It seems like previously the text wasn't updated because of a bug with
the `WindowScaleFactorChanged` event and it isn't emitted after changes
to the scale factor. That needs to be looked into, but this will work
for now.

## Testing

Really simple app that draws a big message in the middle of the window:

```
use bevy::prelude::*;

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

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d);
    commands.spawn((
        Text2d::new("Hello"),
        TextFont {
            font_size: 400.,
            ..Default::default()
        },
    ));
}
```

Looks fine:
<img width="500" alt="hello1"
src="https://github.com/user-attachments/assets/5320746b-687e-4682-9e4c-bc43ab7ff9d3">

On main, after changing the monitor's scale factor:
<img width="500" alt="hello2"
src="https://github.com/user-attachments/assets/486cea16-fc44-4d66-9468-6f68905d4196">


With this PR the text maintains the same size and position after the
scale factor is changed.
2024-11-16 15:30:16 +01:00
..
bounds.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
error.rs Remove thiserror from bevy_text (#15762) 2024-10-09 14:27:09 +00:00
FiraMono-subset.ttf add a default font (#8445) 2023-04-21 22:30:18 +00:00
font_atlas_set.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-11 22:16:38 +01:00
font_atlas.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-11 22:16:38 +01:00
font_loader.rs Remove thiserror from bevy_text (#15762) 2024-10-09 14:27:09 +00:00
font.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
glyph.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-11 22:16:38 +01:00
lib.rs Reflect TextLayout and ComputedTextBlock (#16296) 2024-11-11 22:14:08 +01:00
pipeline.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-11 22:16:38 +01:00
text2d.rs Text2d scalefactor change detection fix (#16264) 2024-11-16 15:30:16 +01:00
text_access.rs Merge Style properties into Node. Use ComputedNode for computed properties. (#15975) 2024-10-18 22:25:33 +00:00
text.rs Reflect TextLayout and ComputedTextBlock (#16296) 2024-11-11 22:14:08 +01:00