2022-10-19 05:34:36 +11:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
|
|
|
use winit::{
|
2023-05-29 04:02:59 +10:00
|
|
|
event::{ElementState, Event, KeyEvent, WindowEvent},
|
2022-10-19 05:34:36 +11:00
|
|
|
event_loop::{ControlFlow, EventLoop},
|
2023-05-29 04:02:59 +10:00
|
|
|
keyboard::Key,
|
2022-10-19 05:34:36 +11:00
|
|
|
window::{Theme, WindowBuilder},
|
|
|
|
};
|
|
|
|
|
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-10-19 05:34:36 +11:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2023-08-14 05:20:09 +10:00
|
|
|
let event_loop = EventLoop::new().unwrap();
|
2022-10-19 05:34:36 +11:00
|
|
|
|
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.with_theme(Some(Theme::Dark))
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("Initial theme: {:?}", window.theme());
|
2022-11-29 20:05:51 +11:00
|
|
|
println!("debugging keys:");
|
|
|
|
println!(" (A) Automatic theme");
|
|
|
|
println!(" (L) Light theme");
|
|
|
|
println!(" (D) Dark theme");
|
2022-10-19 05:34:36 +11:00
|
|
|
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
|
2023-08-28 00:15:09 +10:00
|
|
|
if let Event::WindowEvent { window_id, event } = event {
|
|
|
|
match event {
|
|
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
|
|
WindowEvent::ThemeChanged(theme) if window_id == window.id() => {
|
|
|
|
println!("Theme is changed: {theme:?}")
|
2022-11-29 20:05:51 +11:00
|
|
|
}
|
2023-08-28 00:15:09 +10:00
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
event:
|
|
|
|
KeyEvent {
|
|
|
|
logical_key: key,
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => match key.as_ref() {
|
|
|
|
Key::Character("A" | "a") => {
|
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(None);
|
|
|
|
}
|
|
|
|
Key::Character("L" | "l") => {
|
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(Some(Theme::Light));
|
|
|
|
}
|
|
|
|
Key::Character("D" | "d") => {
|
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(Some(Theme::Dark));
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
},
|
|
|
|
WindowEvent::RedrawRequested => {
|
|
|
|
println!("\nredrawing!\n");
|
|
|
|
fill::fill_window(&window);
|
2022-11-29 20:05:51 +11:00
|
|
|
}
|
|
|
|
_ => (),
|
2023-06-20 04:46:38 +10:00
|
|
|
}
|
2022-10-19 05:34:36 +11:00
|
|
|
}
|
2023-04-11 21:50:52 +10:00
|
|
|
})
|
2022-10-19 05:34:36 +11:00
|
|
|
}
|