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

UI image size is only updated on changes to the primary window's scale factor #17613

Closed
ickshonpe opened this issue Jan 30, 2025 · 1 comment · Fixed by #17579
Closed

UI image size is only updated on changes to the primary window's scale factor #17613

ickshonpe opened this issue Jan 30, 2025 · 1 comment · Fixed by #17579
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@ickshonpe
Copy link
Contributor

ickshonpe commented Jan 30, 2025

Bevy version

main + 0.15

What you did

With this example:

use bevy::{
    prelude::*, render::camera::RenderTarget, ui::widget::ImageNodeSize, window::WindowRef,
};

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

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let first_window_camera = commands.spawn((Camera3d::default(),)).id();
    let image = asset_server.load("branding/icon.png");
    // Spawn a second window
    let second_window = commands
        .spawn(Window {
            title: "Second window".to_owned(),
            ..default()
        })
        .id();

    let second_window_camera = commands
        .spawn((
            Camera2d::default(),
            Camera {
                target: RenderTarget::Window(WindowRef::Entity(second_window)),
                ..default()
            },
        ))
        .id();

    commands
        .spawn((Node::default(), UiTargetCamera(first_window_camera)))
        .with_children(|commands| {
            commands.spawn((Node::default(), ImageNode::new(image.clone())));
        });

    commands
        .spawn((Node::default(), UiTargetCamera(second_window_camera)))
        .with_children(|commands| {
            commands.spawn((ImageNode::new(image.clone()),));
        });
}

fn update(image_size_query: Query<Entity, Changed<ImageNodeSize>>) {
    for entity in image_size_query.iter() {
        println!("image size updated for {}", entity.index());
    }
}

If you change the scale factor of the primary window it reports that both image sizes have been updated, even though the target scale factor only changed for the image on the primary window.

Or if you change the scale factor of the secondary window it doesn't update the image size for either image, even though the target scale factor changed for the image on the secondary window.

What went wrong

The UI image size is only updated on changes to the primary window's scale factor.

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jan 30, 2025
@BenjaminBrienen BenjaminBrienen added S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Feb 6, 2025
@ickshonpe
Copy link
Contributor Author

Fixed by by #17579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
2 participants