Skip to content

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

@ickshonpe

Description

@ickshonpe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions