Implement `Default` for `ThemePreference` (#5702)

Convenient if you store it in an options struct in your app, want to
reset it, etc.

* ~Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>~
* [x] I have followed the instructions in the PR template
This commit is contained in:
Michael Grupp 2025-02-18 18:03:02 +01:00 committed by GitHub
parent 43261a5396
commit b48c7a164b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -322,7 +322,7 @@ impl Default for Options {
Self { Self {
dark_style: std::sync::Arc::new(Theme::Dark.default_style()), dark_style: std::sync::Arc::new(Theme::Dark.default_style()),
light_style: std::sync::Arc::new(Theme::Light.default_style()), light_style: std::sync::Arc::new(Theme::Light.default_style()),
theme_preference: ThemePreference::System, theme_preference: Default::default(),
fallback_theme: Theme::Dark, fallback_theme: Theme::Dark,
system_theme: None, system_theme: None,
zoom_factor: 1.0, zoom_factor: 1.0,

View File

@ -66,7 +66,7 @@ impl Theme {
} }
/// The user's theme preference. /// The user's theme preference.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum ThemePreference { pub enum ThemePreference {
/// Dark mode: light text on a dark background. /// Dark mode: light text on a dark background.
@ -76,6 +76,7 @@ pub enum ThemePreference {
Light, Light,
/// Follow the system's theme preference. /// Follow the system's theme preference.
#[default]
System, System,
} }