mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Add Window::set_theme (#2553)
* Add `Window::set_theme`
* typo
* fix linux build
* fix wayland
* review changes
* update docs
* update changelog
* pin `image` dep
* suppport falling back to system default
* fix linux
* default to dark on macOS and x11
* fix `setAppearance` definition
* add macOS notes
* update docs
* Update CHANGELOG.md
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
* update doc
* Revert "pin `image` dep"
This reverts commit 7517f7c506.
* Update theme example with Window::set_theme
* Fix Window::theme getter on macOS
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use simple_logger::SimpleLogger;
|
||||
use winit::{
|
||||
event::{Event, WindowEvent},
|
||||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::{Theme, WindowBuilder},
|
||||
};
|
||||
@@ -18,6 +18,10 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
println!("Initial theme: {:?}", window.theme());
|
||||
println!("debugging keys:");
|
||||
println!(" (A) Automatic theme");
|
||||
println!(" (L) Light theme");
|
||||
println!(" (D) Dark theme");
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
@@ -34,6 +38,33 @@ fn main() {
|
||||
} if window_id == window.id() => {
|
||||
println!("Theme is changed: {:?}", theme)
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event:
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
virtual_keycode: Some(key),
|
||||
state: ElementState::Pressed,
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
..
|
||||
} => match key {
|
||||
VirtualKeyCode::A => {
|
||||
println!("Theme was: {:?}", window.theme());
|
||||
window.set_theme(None);
|
||||
}
|
||||
VirtualKeyCode::L => {
|
||||
println!("Theme was: {:?}", window.theme());
|
||||
window.set_theme(Some(Theme::Light));
|
||||
}
|
||||
VirtualKeyCode::D => {
|
||||
println!("Theme was: {:?}", window.theme());
|
||||
window.set_theme(Some(Theme::Dark));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user