Skip to content

Commit

Permalink
Replace ThemePreference with a boolean for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jul 21, 2024
1 parent f856323 commit 8dea790
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ pub use {
layers::{LayerId, Order},
layout::*,
load::SizeHint,
memory::{Memory, Options, Theme, ThemePreference},
memory::{Memory, Options, Theme},
painter::Painter,
response::{InnerResponse, Response},
sense::Sense,
Expand Down
17 changes: 8 additions & 9 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};

mod theme;
pub use theme::{Theme, ThemePreference};
pub use theme::Theme;

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -172,13 +172,12 @@ pub struct Options {
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) style: std::sync::Arc<Style>,

/// Whether to use a dark style, light style or follow
/// the OS' setting.
/// Whether to update the visuals according to the system theme or not.
///
/// Note: Currently only [`ThemePreference::System`] has an effect.
pub theme_preference: ThemePreference,
/// Default: `true`.
pub follow_system_theme: bool,

/// Which theme to use in case [`Self::theme_preference`] is set to [`ThemePreference::System`]
/// Which theme to use in case [`Self::follow_system_theme`] is set
/// and egui fails to detect the system theme.
///
/// Default: [`crate::Theme::Dark`].
Expand Down Expand Up @@ -280,7 +279,7 @@ impl Default for Options {

Self {
style: Default::default(),
theme_preference: ThemePreference::System,
follow_system_theme: true,
fallback_theme: Theme::Dark,
system_theme: None,
zoom_factor: 1.0,
Expand All @@ -301,7 +300,7 @@ impl Default for Options {

impl Options {
pub(crate) fn begin_frame(&mut self, new_raw_input: &RawInput) {
if self.theme_preference == ThemePreference::System {
if self.follow_system_theme {
let theme_from_visuals = Theme::from_dark_mode(self.style.visuals.dark_mode);
let current_system_theme = self.system_theme.unwrap_or(theme_from_visuals);
let new_system_theme = new_raw_input.system_theme.unwrap_or(self.fallback_theme);
Expand All @@ -325,7 +324,7 @@ impl Options {
pub fn ui(&mut self, ui: &mut crate::Ui) {
let Self {
style, // covered above
theme_preference: _,
follow_system_theme: _,
fallback_theme: _,
system_theme: _,
zoom_factor: _, // TODO(emilk)
Expand Down
25 changes: 0 additions & 25 deletions crates/egui/src/memory/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,3 @@ impl Theme {
}
}
}

/// The user's theme preference.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum ThemePreference {
/// Dark mode: light text on a dark background.
#[doc(hidden)]
Dark,

/// Light mode: dark text on a light background.
#[doc(hidden)]
Light,

/// Follow the system's theme preference.
System,
}

impl From<Theme> for ThemePreference {
fn from(value: Theme) -> Self {
match value {
Theme::Dark => Self::Dark,
Theme::Light => Self::Light,
}
}
}

0 comments on commit 8dea790

Please sign in to comment.