diff --git a/crates/egui/src/memory/theme.rs b/crates/egui/src/memory/theme.rs index 640979e99daa..62035ede3570 100644 --- a/crates/egui/src/memory/theme.rs +++ b/crates/egui/src/memory/theme.rs @@ -1,3 +1,5 @@ +use crate::{Button, ComboBox}; + /// Dark or Light theme. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -44,3 +46,21 @@ impl From for ThemePreference { } } } + +impl ThemePreference { + pub fn small_combobox(self, ui: &mut crate::Ui) -> Option { + let mut new = self; + ui.selectable_value(&mut new, Self::System, icon(Self::System)); + ui.selectable_value(&mut new, Self::Dark, icon(Self::Dark)); + ui.selectable_value(&mut new, Self::Light, icon(Self::Light)); + (new != self).then_some(new) + } +} + +fn icon(preference: ThemePreference) -> &'static str { + match preference { + ThemePreference::Dark => "🌙", + ThemePreference::Light => "☀", + ThemePreference::System => "⚙", + } +} diff --git a/crates/egui/src/widgets/mod.rs b/crates/egui/src/widgets/mod.rs index 9900117062e9..ec66dfa8dcf8 100644 --- a/crates/egui/src/widgets/mod.rs +++ b/crates/egui/src/widgets/mod.rs @@ -134,10 +134,9 @@ pub fn stroke_ui(ui: &mut crate::Ui, stroke: &mut epaint::Stroke, text: &str) { /// Show a small button to switch to/from dark/light mode (globally). pub fn global_dark_light_mode_switch(ui: &mut Ui) { - let style: crate::Style = (*ui.ctx().style()).clone(); - let new_visuals = style.visuals.light_dark_small_toggle_button(ui); - if let Some(visuals) = new_visuals { - ui.ctx().set_visuals(visuals); + let theme_preference = ui.ctx().options(|opt| opt.theme_preference); + if let Some(theme_preference) = theme_preference.small_combobox(ui) { + ui.ctx().set_theme(theme_preference); } } diff --git a/scripts/build_demo_web.sh b/scripts/build_demo_web.sh index 3bc33d225c77..13bc4914a973 100755 --- a/scripts/build_demo_web.sh +++ b/scripts/build_demo_web.sh @@ -87,7 +87,6 @@ echo "Building rust…" (cd crates/$CRATE_NAME && cargo build \ ${BUILD_FLAGS} \ - --quiet \ --lib \ --target wasm32-unknown-unknown \ --no-default-features \