Add `Context::style_mut` (#3359)
This commit is contained in:
parent
dbf9b79d06
commit
6870d141d7
|
|
@ -1049,17 +1049,24 @@ impl Context {
|
||||||
self.options(|opt| opt.style.clone())
|
self.options(|opt| opt.style.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Style`] used by all new windows, panels etc.
|
/// Mutate the [`Style`] used by all subsequent windows, panels etc.
|
||||||
///
|
|
||||||
/// You can also use [`Ui::style_mut`] to change the style of a single [`Ui`].
|
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```
|
/// ```
|
||||||
/// # let mut ctx = egui::Context::default();
|
/// # let mut ctx = egui::Context::default();
|
||||||
/// let mut style: egui::Style = (*ctx.style()).clone();
|
/// ctx.style_mut(|style| {
|
||||||
/// style.spacing.item_spacing = egui::vec2(10.0, 20.0);
|
/// style.spacing.item_spacing = egui::vec2(10.0, 20.0);
|
||||||
/// ctx.set_style(style);
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
|
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<Arc<Style>>) {
|
pub fn set_style(&self, style: impl Into<Arc<Style>>) {
|
||||||
self.options_mut(|opt| opt.style = style.into());
|
self.options_mut(|opt| opt.style = style.into());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue