Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How, with Bevy, can you get and set Window information after creation?

Tags:

rust

bevy

I want to be able to read and set window-settings with Bevy. I attempted to do so with a basic system:

fn test_system(mut win_desc: ResMut<WindowDescriptor>) {
    win_desc.title = "test".to_string();
    println!("{}",win_desc.title);
}

While this works (partially), it only gives you the original settings, and it doesn't allow changes at all. In this example, the title will not change, but the display of the title will. In another example, changing the window-size (manually at run-time) will not be reflected if you were to print win_desc.width.

like image 607
STF_ZBR Avatar asked Aug 29 '20 23:08

STF_ZBR


1 Answers

At the moment, the WindowDescriptor is used only during window creation and is not updated later

To get notified when the window is resized I use this system:

fn resize_notificator(resize_event: Res<Events<WindowResized>>) {
    let mut reader = resize_event.get_reader();
    for e in reader.iter(&resize_event) {
        println!("width = {} height = {}", e.width, e.height);
    }
}

Other useful events can be found at https://github.com/bevyengine/bevy/blob/master/crates/bevy_window/src/event.rs

like image 102
zyrg Avatar answered Sep 22 '22 12:09

zyrg