-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Text2d scalefactor change detection fix #16264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In `update_text2d_layout` store the previous scale factor in a `Local` instead and check against the current scale factor to detect changes.
|
the The issue is probably about the first scale change on window creation. I can't reproduce on macOS, but it may be os dependent |
It's actually more complicated than just fixing the event, there are a couple of issues with
So storing the scale factor in a local variable is marginally preferable to watching the event. With the event (if it worked) it triggers updates on changes to the scale factor of any window, not just the primary window. But since text2d always uses the scale factor of the primary window, the text reupdate is needless on changes to non-primary window's scalefactors. It's stupid how it works this way though and we need proper multi-window support.
It can be tricky sometimes to capture scale factor bugs in examples. Easiest way in this case is if you setup two monitors with different scale factors and drag the bevy app from one to the other. |
# 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.
# Objective Text2d doesn't respond to changes to the window scalefactor. Fixes bevyengine#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.
# Objective Text2d doesn't respond to changes to the window scalefactor. Fixes bevyengine#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.
Objective
Text2d doesn't respond to changes to the window scalefactor.
Fixes #16223
Solution
In
update_text2d_layoutstore the previous scale factor in aLocalinstead 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
WindowScaleFactorChangedevent 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:
Looks fine:

On main, after changing the monitor's scale factor:

With this PR the text maintains the same size and position after the scale factor is changed.