use dip::{
bevy::{log::LogPlugin, time::TimePlugin, window::PresentMode},
prelude::*,
};
fn main() {
App::new()
.insert_resource(WindowDescriptor {
title: "Window Settings".to_string(),
width: 500.,
height: 300.,
present_mode: PresentMode::Fifo,
..Default::default()
})
.add_plugin(LogPlugin)
.add_plugin(TimePlugin)
.add_plugin(DesktopPlugin::<NoUiState, NoUiAction, NoAsyncAction>::new(
Root,
))
.add_system(change_title)
.add_system(toggle_cursor)
.run();
}
#[allow(non_snake_case)]
fn Root(cx: Scope) -> Element {
cx.render(rsx! {
h1 { "Window Settings" }
})
}
fn change_title(time: Res<Time>, mut windows: ResMut<Windows>) {
let window = windows.primary_mut();
window.set_title(format!(
"Seconds since startup: {}",
time.seconds_since_startup().round()
));
}
fn toggle_cursor(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
let window = windows.primary_mut();
if input.just_pressed(KeyCode::Space) {
window.set_cursor_lock_mode(!window.cursor_locked());
window.set_cursor_visibility(!window.cursor_visible());
}
}