Skip to content

Commit

Permalink
Add set_theme to event loot target
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Sep 18, 2024
1 parent 9372ae6 commit 6e9252f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ use instant::Instant;
use std::{error, fmt, marker::PhantomData, ops::Deref};

use crate::{
dpi::PhysicalPosition, error::ExternalError, event::Event, monitor::MonitorHandle, platform_impl,
window::ProgressBarState,
dpi::PhysicalPosition,
error::ExternalError,
event::Event,
monitor::MonitorHandle,
platform_impl,
window::{ProgressBarState, Theme},
};

/// Provides a way to retrieve events from the system and from the windows that were registered to
Expand Down Expand Up @@ -296,6 +300,19 @@ impl<T> EventLoopWindowTarget<T> {
#[cfg(any(target_os = "linux", target_os = "macos"))]
self.p.set_progress_bar(_progress)
}

/// Sets the theme for this window.
///
/// ## Platform-specific
///
/// - **Linux / macOS**: Theme is app-wide and not specific to this window.
/// - **Windows:** Unsupported. Use the set_theme function available in Window (Windows can have different themes for different windows)
/// - **iOS / Android:** Unsupported.
#[inline]
pub fn set_theme(&self, #[allow(unused)] theme: Option<Theme>) {
#[cfg(any(target_os = "linux", target_os = "macos"))]
self.p.set_theme(theme)
}
}

#[cfg(feature = "rwh_05")]
Expand Down
12 changes: 11 additions & 1 deletion src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ impl<T> EventLoopWindowTarget<T> {
.window_requests_tx
.send((WindowId::dummy(), WindowRequest::ProgressBarState(progress)))
{
log::warn!("Fail to send update progress bar request: {}", e);
log::warn!("Fail to send update progress bar request: {e}");
}
}

#[inline]
pub fn set_theme(&self, theme: Option<Theme>) {
if let Err(e) = self
.window_requests_tx
.send((WindowId::dummy(), WindowRequest::SetTheme(theme)))
{
log::warn!("Fail to send update theme request: {e}");
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
observer::*,
util::{self, IdRef},
},
platform_impl::set_progress_indicator,
platform_impl::{set_ns_theme, set_progress_indicator},
window::ProgressBarState,
};

Expand Down Expand Up @@ -120,6 +120,11 @@ impl<T: 'static> EventLoopWindowTarget<T> {
pub fn set_progress_bar(&self, progress: ProgressBarState) {
set_progress_indicator(progress);
}

#[inline]
pub fn set_theme(&self, theme: Option<Theme>) {
set_ns_theme(theme)
}
}

pub struct EventLoop<T: 'static> {
Expand Down

0 comments on commit 6e9252f

Please sign in to comment.