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

window::Cursor does not support ..default() initialization pattern #7941

Closed
Cpapa97 opened this issue Mar 7, 2023 · 1 comment · Fixed by #7988
Closed

window::Cursor does not support ..default() initialization pattern #7941

Cpapa97 opened this issue Mar 7, 2023 · 1 comment · Fixed by #7988
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR

Comments

@Cpapa97
Copy link

Cpapa97 commented Mar 7, 2023

Bevy version

0.10.0

What you did

use bevy::{
    prelude::*,
    window::{Cursor, CursorGrabMode, PresentMode, WindowMode},
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "Title".to_string(),
                present_mode: PresentMode::AutoNoVsync,
                mode: WindowMode::BorderlessFullscreen,
                cursor: Cursor {
                    visible: false,
                    grab_mode: CursorGrabMode::Confined,
                    ..default()
                },
                ..default()
            }),
            ..default()
        }))
    }
    .run();
}

What went wrong

This section errors because Cursor.physical_position is private even though everything else is public. This makes the ..default() initialization pattern not work because it can't set the physical_position field.

cursor: Cursor {
    visible: false,
    grab_mode: CursorGrabMode::Confined,
    ..default()
},

Additional information

Workaround:

cursor: {
    let mut cursor = Cursor::default();
    cursor.visible = false;
    cursor.grab_mode = CursorGrabMode::Confined;
    cursor
},

This workaround is quite compact and just fine honestly, though the current behavior is a bit unexpected considering how many other struct initializations work for Bevy users.

@Cpapa97 Cpapa97 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 7, 2023
@ickk
Copy link
Member

ickk commented Mar 7, 2023

Checking the blame for the relevant line shows this field was intentionally made private to fix another issue, so it does not seem to be a trivial fix unfortunately.

@ickk ickk added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Windowing Platform-agnostic interface layer to run your app in and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 7, 2023
@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants