Track window theme in window::State

This commit is contained in:
Héctor Ramón Jiménez 2025-09-08 06:01:36 +02:00
parent 354159bdf4
commit c1d7819c07
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 41 additions and 18 deletions

View file

@ -5,6 +5,7 @@
use crate::core::input_method;
use crate::core::keyboard;
use crate::core::mouse;
use crate::core::theme;
use crate::core::touch;
use crate::core::window;
use crate::core::{Event, Point, Size};
@ -318,6 +319,9 @@ pub fn window_event(
Some(Event::Window(window::Event::Moved(Point::new(x, y))))
}
WindowEvent::ThemeChanged(theme) => Some(Event::Window(
window::Event::ThemeModeChanged(theme_mode(theme)),
)),
_ => None,
}
}
@ -440,6 +444,16 @@ pub fn mode(mode: Option<winit::window::Fullscreen>) -> window::Mode {
}
}
/// Converts a [`winit`] window theme to a [`theme::Mode`].
///
/// [`winit`]: https://github.com/rust-windowing/winit
pub fn theme_mode(theme: winit::window::Theme) -> theme::Mode {
match theme {
winit::window::Theme::Light => theme::Mode::Light,
winit::window::Theme::Dark => theme::Mode::Dark,
}
}
/// Converts a [`mouse::Interaction`] to a [`winit`] cursor icon.
///
/// [`winit`]: https://github.com/rust-windowing/winit