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;
|
|
|
|
|
2022-10-19 05:34:36 +11:00
|
|
|
fn main() {
|
|
|
|
SimpleLogger::new().init().unwrap();
|
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => *control_flow = ControlFlow::Exit,
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::ThemeChanged(theme),
|
|
|
|
window_id,
|
|
|
|
..
|
|
|
|
} if window_id == window.id() => {
|
2023-01-27 15:18:58 +11:00
|
|
|
println!("Theme is changed: {theme:?}")
|
2022-10-19 05:34:36 +11:00
|
|
|
}
|
2022-11-29 20:05:51 +11:00
|
|
|
Event::WindowEvent {
|
|
|
|
event:
|
|
|
|
WindowEvent::KeyboardInput {
|
2023-05-29 04:02:59 +10:00
|
|
|
event:
|
|
|
|
KeyEvent {
|
|
|
|
logical_key: key,
|
2022-11-29 20:05:51 +11:00
|
|
|
state: ElementState::Pressed,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
2023-05-29 04:02:59 +10:00
|
|
|
} => match key.as_ref() {
|
|
|
|
Key::Character("A" | "a") => {
|
2022-11-29 20:05:51 +11:00
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(None);
|
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
Key::Character("L" | "l") => {
|
2022-11-29 20:05:51 +11:00
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(Some(Theme::Light));
|
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
Key::Character("D" | "d") => {
|
2022-11-29 20:05:51 +11:00
|
|
|
println!("Theme was: {:?}", window.theme());
|
|
|
|
window.set_theme(Some(Theme::Dark));
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
},
|
2023-06-20 04:46:38 +10:00
|
|
|
Event::RedrawRequested(_) => {
|
|
|
|
println!("\nredrawing!\n");
|
|
|
|
fill::fill_window(&window);
|
|
|
|
}
|
2022-10-19 05:34:36 +11:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|