Add Window::set_theme

This commit is contained in:
amrbashir
2022-11-08 18:48:56 +02:00
parent 50bbc85dc3
commit e8acf8b9ec
10 changed files with 46 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased
- On Windows, macOS and Wayland, add `Window::set_theme`.
- On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one.
- On Windows and macOS, add `Window::title` to query the current window title.
- On Windows, fix focusing menubar when pressing `Alt`.

View File

@@ -853,6 +853,8 @@ impl Window {
ndk_glue::content_rect()
}
pub fn set_theme(&self, _theme: Theme) {}
pub fn theme(&self) -> Option<Theme> {
None
}

View File

@@ -348,6 +348,11 @@ impl Inner {
None
}
#[inline]
pub fn set_theme(&self, _theme: Theme) {
warn!("`Window::set_theme` is ignored on iOS");
}
pub fn title(&self) -> String {
warn!("`Window::title` is ignored on iOS");
String::new()

View File

@@ -585,6 +585,11 @@ impl Window {
x11_or_wayland!(match self; Window(window) => window.raw_display_handle())
}
#[inlnie]
pub fn set_theme(&self, theme: Theme) {
x11_or_wayland!(match self; Window(window) => window.set_theme())
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
x11_or_wayland!(match self; Window(window) => window.theme())

View File

@@ -620,6 +620,12 @@ impl Window {
self.event_loop_awakener.ping();
}
#[inline]
pub fn set_theme(&self, _theme: Theme) {
#[cfg(feature = "sctk-adwaita")]
window.set_frame_config(theme.into());
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
None

View File

@@ -1547,6 +1547,9 @@ impl UnownedWindow {
RawDisplayHandle::Xlib(display_handle)
}
#[inline]
pub fn set_theme(&self, _theme: Theme) {}
#[inline]
pub fn theme(&self) -> Option<Theme> {
None

View File

@@ -1122,6 +1122,11 @@ impl WinitWindow {
state.current_theme
}
#[inline]
pub fn set_theme(&self, theme: Theme) {
set_ns_theme(theme);
}
#[inline]
pub fn title(&self) -> String {
self.title_().to_string()

View File

@@ -374,6 +374,9 @@ impl Window {
RawDisplayHandle::Web(WebDisplayHandle::empty())
}
#[inline]
pub fn set_theme(&self, _theme: Theme) {}
#[inline]
pub fn theme(&self) -> Option<Theme> {
None

View File

@@ -693,6 +693,11 @@ impl Window {
});
}
#[inline]
pub fn set_theme(&self, theme: Theme) {
try_theme(self.window.0, Some(theme));
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
Some(self.window_state_lock().current_theme)

View File

@@ -943,12 +943,22 @@ impl Window {
self.window.request_user_attention(request_type)
}
/// Returns the current window theme.
/// Sets the current window theme.
///
/// ## Platform-specific
///
/// - **iOS / Android / Web / x11:** Unsupported.
#[inline]
pub fn set_theme(&self, theme: Theme) {
self.window.set_theme(theme)
}
/// Returns the current window theme.
///
/// ## Platform-specific
///
/// - **iOS / Android / Web / Wayland / x11:** Unsupported.
#[inline]
pub fn theme(&self) -> Option<Theme> {
self.window.theme()
}