Skip to content

Commit

Permalink
Set theme from toggle buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jul 20, 2024
1 parent 816e263 commit 99969a6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/egui/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,21 @@ 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);
if visuals.dark_mode {
ui.ctx().set_theme(Theme::Dark)
} else {
ui.ctx().set_theme(Theme::Light)
}
}
}

/// Show larger buttons for switching between light and dark mode (globally).
pub fn global_dark_light_mode_buttons(ui: &mut Ui) {
let mut visuals = ui.ctx().style().visuals.clone();
visuals.light_dark_radio_buttons(ui);
ui.ctx().set_visuals(visuals);
if visuals.dark_mode {
ui.ctx().set_theme(Theme::Dark)
} else {
ui.ctx().set_theme(Theme::Light)
}
}

0 comments on commit 99969a6

Please sign in to comment.