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

Weird Ui displacement in 0.12 persumably caused by UiScale #10399

Closed
Litttlefish opened this issue Nov 6, 2023 Discussed in #10381 · 3 comments
Closed

Weird Ui displacement in 0.12 persumably caused by UiScale #10399

Litttlefish opened this issue Nov 6, 2023 Discussed in #10381 · 3 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@Litttlefish
Copy link
Contributor

Discussed in #10381

Originally posted by Litttlefish November 5, 2023
Today I updated bevy to 0.12, and after migration I found this weird UI displacement
图片
In 0.11, the ui works perfectly.
图片

It happens when window resizes, also it seems that the displacement sometimes will change depending on resolution and presumably UiScale
On maximum(UiScale is about 1.9)
image-4
On fullscreen(UiScale is 2.0)
image-5

And I made a minimal reproduce code

for sprite, any 16:9 image is ok
and maximize it after run to see the bug at the right side

Should look like this
图片

As you can see, the right side has one pixel missing

use bevy::prelude::*;
use bevy::render::camera::ScalingMode;
use bevy::window::*;

fn main() {
    App::new()
        .add_systems(Startup, setup)
        .add_systems(Update, (setres.run_if(on_event::<WindowResized>()),))
        .add_plugins((DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "test".into(),
                resolution: (960.0, 540.0).into(),
                resizable: false,
                ..default()
            }),
            ..default()
        }),))
        //.add_plugin(EditorPlugin::default())
        .run();
}

fn setup(mut cmd: Commands, asset_server: Res<AssetServer>) {
    cmd.spawn(Camera2dBundle {
        projection: OrthographicProjection {
            scaling_mode: ScalingMode::AutoMin {
                min_width: 960.,
                min_height: 540.,
            },
            ..Camera2dBundle::default().projection
        },
        ..default()
    });
    cmd.spawn((SpriteBundle {
        sprite: Sprite {
            custom_size: Some((960., 540.).into()),
            ..default()
        },
        texture: asset_server.load("sprites/bedroom_normal.png"),
        ..default()
    },));
    cmd.spawn((NodeBundle {
        style: Style {
            width: Val::Percent(100.),
            height: Val::Percent(100.),
            justify_content: JustifyContent::Center,
            align_items: AlignItems::Center,
            ..default()
        },
        ..default()
    },))
        .with_children(|p| {
            p.spawn(NodeBundle {
                style: Style {
                    width: Val::Px(960.),
                    height: Val::Px(540.),
                    ..default()
                },
                background_color: BackgroundColor(Color::BLACK),
                ..default()
            });
        });
}

fn setres(mut scaler: ResMut<UiScale>, windowq: Query<&Window, With<PrimaryWindow>>) {
    scaler.0 = (windowq.single().height() as f64 / 540.).max(0.1)
}
@Litttlefish
Copy link
Contributor Author

Can anyone label this issue please? I think I don't have the permission to label it
Thanks

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets labels Nov 11, 2023
@Litttlefish Litttlefish changed the title Weird Ui displacement in 0.12 Weird Ui displacement in 0.12 persumably caused by UiScale Nov 23, 2023
@Litttlefish
Copy link
Contributor Author

I think the first issue mentioned can fixed by using 9-sliced (but it also has some issue, #11944)
but the black fill still has one-pixel problem

@Litttlefish
Copy link
Contributor Author

Seems #13503 described the same issue, I'll close this one as abundant.

@Litttlefish Litttlefish closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants