From 6870d141d7b3c26f12bc7bf8b0ed2d0d472e6edb Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 18 Sep 2023 21:07:44 +0200 Subject: [PATCH] Add `Context::style_mut` (#3359) --- crates/egui/src/context.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index c3c99b2a5b6..f4e520cea6d 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1049,17 +1049,24 @@ impl Context { self.options(|opt| opt.style.clone()) } - /// The [`Style`] used by all new windows, panels etc. - /// - /// You can also use [`Ui::style_mut`] to change the style of a single [`Ui`]. + /// Mutate the [`Style`] used by all subsequent windows, panels etc. /// /// Example: /// ``` /// # let mut ctx = egui::Context::default(); - /// let mut style: egui::Style = (*ctx.style()).clone(); - /// style.spacing.item_spacing = egui::vec2(10.0, 20.0); - /// ctx.set_style(style); + /// ctx.style_mut(|style| { + /// style.spacing.item_spacing = egui::vec2(10.0, 20.0); + /// }); /// ``` + pub fn style_mut(&self, mutate_style: impl FnOnce(&mut Style)) { + self.options_mut(|opt| mutate_style(std::sync::Arc::make_mut(&mut opt.style))); + } + + /// The [`Style`] used by all new windows, panels etc. + /// + /// You can also change this using [`Self::style_mut]` + /// + /// You can use [`Ui::style_mut`] to change the style of a single [`Ui`]. pub fn set_style(&self, style: impl Into>) { self.options_mut(|opt| opt.style = style.into()); }