-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Text2D placement and size are wrong (window scale factor) #10407
Comments
Bisected to #9826. (But seemingly not fixed by #10389). I'm also on a Macbook. To reproduce, diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs
index 18a959bef..2988e4bc7 100644
--- a/examples/2d/text2d.rs
+++ b/examples/2d/text2d.rs
@@ -9,11 +9,18 @@ use bevy::{
prelude::*,
sprite::Anchor,
text::{BreakLineOn, Text2dBounds},
+ window::WindowResolution,
};
fn main() {
App::new()
- .add_plugins(DefaultPlugins)
+ .add_plugins(DefaultPlugins.set(WindowPlugin {
+ primary_window: Some(Window {
+ resolution: WindowResolution::default().with_scale_factor_override(2.0),
+ ..default()
+ }),
+ ..default()
+ }))
.add_systems(Startup, setup)
.add_systems(
Update, I seem to recall a similar issue popping up / maybe getting fixed where if a window was not available when the text was created, a default scale factor would be used, and it would never be updated after the window was created. |
It seems that the resolution / scale_factor of |
Here's a new repro of the underlying bug (if you are on a display with use bevy::{core::FrameCount, prelude::*, window::PrimaryWindow};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, dbg)
.run();
}
fn dbg(query: Query<&Window, With<PrimaryWindow>>, frame: Res<FrameCount>) {
if frame.0 > 1 {
return;
}
for window in &query {
info!("F{} {:?}", frame.0, window.resolution);
}
} This outputs (on my
It seems to get slightly weirder when there's a scale factor override involved (physical_width/height never update to match either the overridden or actual scale factor and this was the case even before 9826, but you can still see the bug in
|
Using rparrett's repro I have different behaviour on X11 Lower DPI screen:
Higher DPI screen:
My system seems to create the window before any code runs. |
Do you have any workarounds? I'm experiencing the same issue. |
Bevy version
Bevy 0.12
[Optional] Relevant system information
I'm using MacOS and rust 1.73
What you did
In this hexx example I'm spawning Text 2D bundles to display the grid coordinates.
What went wrong
In my migration PR for bevy 0.12 I noticed the text is very small and moved on the bottom left instead of being centered
Screen.Recording.2023-11-06.at.10.59.49.mp4
But When I enable the world inspector, and simply touch the font size, suddenly the text refreshes and appears at the right size and centered.
Thanks to @rparrett It seems that the underlying issue is related to windows with a
scale_factor
different than1
, like on my MacBook.The text was updated successfully, but these errors were encountered: