2022-11-29 21:03:51 +11:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
|
|
|
// This example is used by developers to test various window functions.
|
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
|
|
|
use winit::{
|
|
|
|
dpi::LogicalSize,
|
2023-05-29 04:02:59 +10:00
|
|
|
event::{ElementState, Event, KeyEvent, WindowEvent},
|
2023-05-31 05:32:31 +10:00
|
|
|
event_loop::{DeviceEvents, EventLoop},
|
2023-05-29 04:02:59 +10:00
|
|
|
keyboard::Key,
|
2022-11-29 21:03:51 +11:00
|
|
|
window::{WindowBuilder, WindowButtons},
|
|
|
|
};
|
|
|
|
|
2023-06-20 04:46:38 +10:00
|
|
|
#[path = "util/fill.rs"]
|
|
|
|
mod fill;
|
|
|
|
|
2023-04-11 21:50:52 +10:00
|
|
|
fn main() -> Result<(), impl std::error::Error> {
|
2022-11-29 21:03:51 +11:00
|
|
|
SimpleLogger::new().init().unwrap();
|
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
|
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.with_inner_size(LogicalSize::new(300.0, 300.0))
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
eprintln!("Window Button keys:");
|
|
|
|
eprintln!(" (F) Toggle close button");
|
|
|
|
eprintln!(" (G) Toggle maximize button");
|
|
|
|
eprintln!(" (H) Toggle minimize button");
|
|
|
|
|
2023-05-31 05:32:31 +10:00
|
|
|
event_loop.listen_device_events(DeviceEvents::Always);
|
2022-11-29 21:03:51 +11:00
|
|
|
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
control_flow.set_wait();
|
|
|
|
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event:
|
|
|
|
WindowEvent::KeyboardInput {
|
2023-05-29 04:02:59 +10:00
|
|
|
event:
|
|
|
|
KeyEvent {
|
|
|
|
logical_key: key,
|
2022-11-29 21:03:51 +11:00
|
|
|
state: ElementState::Pressed,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
2023-05-29 04:02:59 +10:00
|
|
|
} => match key.as_ref() {
|
|
|
|
Key::Character("F" | "f") => {
|
2022-11-29 21:03:51 +11:00
|
|
|
let buttons = window.enabled_buttons();
|
|
|
|
window.set_enabled_buttons(buttons ^ WindowButtons::CLOSE);
|
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
Key::Character("G" | "g") => {
|
2022-11-29 21:03:51 +11:00
|
|
|
let buttons = window.enabled_buttons();
|
|
|
|
window.set_enabled_buttons(buttons ^ WindowButtons::MAXIMIZE);
|
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
Key::Character("H" | "h") => {
|
2022-11-29 21:03:51 +11:00
|
|
|
let buttons = window.enabled_buttons();
|
|
|
|
window.set_enabled_buttons(buttons ^ WindowButtons::MINIMIZE);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
},
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
window_id,
|
|
|
|
} if window_id == window.id() => control_flow.set_exit(),
|
2023-06-20 04:46:38 +10:00
|
|
|
Event::RedrawRequested(_) => {
|
|
|
|
fill::fill_window(&window);
|
|
|
|
}
|
2022-11-29 21:03:51 +11:00
|
|
|
_ => (),
|
|
|
|
}
|
2023-04-11 21:50:52 +10:00
|
|
|
})
|
2022-11-29 21:03:51 +11:00
|
|
|
}
|