Skip to content
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

Desktop scale change does not update text #4688

Closed
lukors opened this issue May 7, 2022 · 2 comments
Closed

Desktop scale change does not update text #4688

lukors opened this issue May 7, 2022 · 2 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@lukors
Copy link
Contributor

lukors commented May 7, 2022

Bevy version

d867b61

Operating system & version

Windows 10

What you did

  1. Run the below code, observe how the text fits in the box for future comparison.
  2. While it's running, change the desktop scaling in Windows, or move the window to another screen with a different scaling. Observe that the text no longer fits the same way in the box.
  3. Press space to "touch" the text. Observe that the text now fits in the box like it should.
use bevy::{prelude::*, text::Text2dBounds};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(touch_text)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
    let text_style = TextStyle {
        font,
        font_size: 60.0,
        color: Color::WHITE,
    };

    // 2d camera
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());

    // Demonstrate text wrapping
    let box_size = Vec2::new(300.0, 200.0);
    let box_position = Vec2::new(0.0, -250.0);
    commands.spawn_bundle(SpriteBundle {
        sprite: Sprite {
            color: Color::rgb(0.25, 0.25, 0.75),
            custom_size: Some(Vec2::new(box_size.x, box_size.y)),
            ..default()
        },
        transform: Transform::from_translation(box_position.extend(0.0)),
        ..default()
    });
    let text_alignment_topleft = TextAlignment {
        vertical: VerticalAlign::Top,
        horizontal: HorizontalAlign::Left,
    };
    commands.spawn_bundle(Text2dBundle {
        text: Text::with_section(
            "this text wraps in the box",
            text_style,
            text_alignment_topleft,
        ),
        text_2d_bounds: Text2dBounds {
            // Wrap text in the rectangle
            size: box_size,
        },
        // We align text to the top-left, so this transform is the top-left corner of our text. The
        // box is centered at box_position, so it is necessary to move by half of the box size to
        // keep the text in the box.
        transform: Transform::from_xyz(
            box_position.x - box_size.x / 2.0,
            box_position.y + box_size.y / 2.0,
            1.0,
        ),
        ..default()
    });
}

fn touch_text(
    keyboard_input: Res<Input<KeyCode>>,
    mut q_text: Query<&mut Text>,
) {
    if keyboard_input.just_pressed(KeyCode::Space) {
        println!("Pressed space");
        for mut text in q_text.iter_mut() {
            text.sections.iter_mut();
        }
    }
}

What you expected to happen

The text should always fit the same way in the box.

What actually happened

The text does not update along with everything else when the scale changes.

Additional information

This system can be used to work around the issue, but it would be better if something equivalent happened automatically inside Bevy by default:

fn touch_text(
    mut window_resized_events: EventReader<WindowResized>,
    mut q_text: Query<&mut Text>,
) {
    if window_resized_events.iter().next().is_some() {
        for mut text in q_text.iter_mut() {
            text.sections.iter_mut();
        }
    }
}
@lukors lukors added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 7, 2022
@DJMcNab
Copy link
Member

DJMcNab commented May 7, 2022

Can you confirm whether #4689 fixes this issue for your case.

I've tested it with the text2d example, and it fixes that.

@DJMcNab DJMcNab added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels May 7, 2022
@lukors
Copy link
Contributor Author

lukors commented May 7, 2022

I'm on v0.7.0 on my project, and I'm running into some issues trying to upgrade to your branch. So Unfortunately I it seems like it'd be too much work to verify it it fixes it.

I can report it again if it doesn't work after 0.8.0 the next version is out.

bors bot pushed a commit that referenced this issue May 9, 2022
# Objective

- Fix #4688

## Solution

- Fixes #4688
- This raises an interesting question about our change detection system - is filtered queries actually a good UX for this? They're ergonomic in the easy case, but what do we recommend when it's not so.
- In this case, the system should have been migrated similary to #4180 anyway, so I've done that.
@bors bors bot closed this as completed in 33a4df8 May 9, 2022
robtfm pushed a commit to robtfm/bevy that referenced this issue May 10, 2022
# Objective

- Fix bevyengine#4688

## Solution

- Fixes bevyengine#4688
- This raises an interesting question about our change detection system - is filtered queries actually a good UX for this? They're ergonomic in the easy case, but what do we recommend when it's not so.
- In this case, the system should have been migrated similary to bevyengine#4180 anyway, so I've done that.
exjam pushed a commit to exjam/bevy that referenced this issue May 22, 2022
# Objective

- Fix bevyengine#4688

## Solution

- Fixes bevyengine#4688
- This raises an interesting question about our change detection system - is filtered queries actually a good UX for this? They're ergonomic in the easy case, but what do we recommend when it's not so.
- In this case, the system should have been migrated similary to bevyengine#4180 anyway, so I've done that.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Fix bevyengine#4688

## Solution

- Fixes bevyengine#4688
- This raises an interesting question about our change detection system - is filtered queries actually a good UX for this? They're ergonomic in the easy case, but what do we recommend when it's not so.
- In this case, the system should have been migrated similary to bevyengine#4180 anyway, so I've done that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants