Rework theme API

This commit adds support for theming on macOS and
also unifies the system theme handling across platforms.
This commit is contained in:
keiya sasaki 2022-10-19 03:34:36 +09:00 committed by GitHub
parent 4f06cfcf5b
commit 92fdf5ba85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 256 additions and 60 deletions

View file

@ -134,6 +134,7 @@ pub(crate) struct WindowAttributes {
pub decorations: bool,
pub always_on_top: bool,
pub window_icon: Option<Icon>,
pub preferred_theme: Option<Theme>,
pub resize_increments: Option<Size>,
}
@ -154,6 +155,7 @@ impl Default for WindowAttributes {
decorations: true,
always_on_top: false,
window_icon: None,
preferred_theme: None,
resize_increments: None,
}
}
@ -335,6 +337,23 @@ impl WindowBuilder {
self
}
/// Sets a specific theme for the window.
///
/// If `None` is provided, the window will use the system theme.
///
/// The default is `None`.
///
/// ## Platform-specific
///
/// - **Wayland:** This control only CSD. You can also use `WINIT_WAYLAND_CSD_THEME` env variable to set the theme.
/// Possible values for env variable are: "dark" and light".
/// - **iOS / Android / Web / x11:** Ignored.
#[inline]
pub fn with_theme(mut self, theme: Option<Theme>) -> Self {
self.window.preferred_theme = theme;
self
}
/// Build window with resize increments hint.
///
/// The default is `None`.
@ -923,6 +942,16 @@ impl Window {
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
self.window.request_user_attention(request_type)
}
/// Returns the current window theme.
///
/// ## Platform-specific
///
/// - **iOS / Android / Web / x11:** Unsupported.
#[inline]
pub fn theme(&self) -> Option<Theme> {
self.window.theme()
}
}
/// Cursor functions.