Add ctx.set_visuals()
This commit is contained in:
parent
a19fd7b780
commit
af3195f086
5 changed files with 16 additions and 4 deletions
|
@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
* `egui::popup::popup_below_widget`: show a popup area below another widget.
|
* `egui::popup::popup_below_widget`: show a popup area below another widget.
|
||||||
* Add `Slider::clamp_to_range(bool)`: if set, clamp the incoming and outgoing values to the slider range.
|
* Add `Slider::clamp_to_range(bool)`: if set, clamp the incoming and outgoing values to the slider range.
|
||||||
* Add: `ui.spacing()`, `ui.spacing_mut()`, `ui.visuals()`, `ui.visuals_mut()`.
|
* Add: `ui.spacing()`, `ui.spacing_mut()`, `ui.visuals()`, `ui.visuals_mut()`.
|
||||||
|
* Add: `ctx.set_visuals()`.
|
||||||
|
|
||||||
### Changed 🔧
|
### Changed 🔧
|
||||||
|
|
||||||
|
|
|
@ -462,6 +462,17 @@ impl Context {
|
||||||
self.memory().options.style = style.into();
|
self.memory().options.style = style.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The [`Visuals`] used by all new windows, panels etc.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```
|
||||||
|
/// # let mut ctx = egui::CtxRef::default();
|
||||||
|
/// ctx.set_visuals(egui::Visuals::light()); // Switch to light mode
|
||||||
|
/// ```
|
||||||
|
pub fn set_visuals(&self, visuals: crate::Visuals) {
|
||||||
|
std::sync::Arc::make_mut(&mut self.memory().options.style).visuals = visuals;
|
||||||
|
}
|
||||||
|
|
||||||
/// The number of physical pixels for each logical point.
|
/// The number of physical pixels for each logical point.
|
||||||
pub fn pixels_per_point(&self) -> f32 {
|
pub fn pixels_per_point(&self) -> f32 {
|
||||||
self.input.pixels_per_point()
|
self.input.pixels_per_point()
|
||||||
|
|
|
@ -126,7 +126,7 @@ pub use {
|
||||||
painter::Painter,
|
painter::Painter,
|
||||||
response::Response,
|
response::Response,
|
||||||
sense::Sense,
|
sense::Sense,
|
||||||
style::Style,
|
style::{Style, Visuals},
|
||||||
ui::Ui,
|
ui::Ui,
|
||||||
widgets::*,
|
widgets::*,
|
||||||
};
|
};
|
||||||
|
|
|
@ -122,13 +122,13 @@ impl Ui {
|
||||||
|
|
||||||
/// Short for `&self.style().visuals`
|
/// Short for `&self.style().visuals`
|
||||||
/// visuals options for this `Ui` and its children.
|
/// visuals options for this `Ui` and its children.
|
||||||
pub fn visuals(&self) -> &crate::style::Visuals {
|
pub fn visuals(&self) -> &crate::Visuals {
|
||||||
&self.style.visuals
|
&self.style.visuals
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutably borrow internal `visuals`.
|
/// Mutably borrow internal `visuals`.
|
||||||
/// Changes apply to this `Ui` and its subsequent children.
|
/// Changes apply to this `Ui` and its subsequent children.
|
||||||
pub fn visuals_mut(&mut self) -> &mut crate::style::Visuals {
|
pub fn visuals_mut(&mut self) -> &mut crate::Visuals {
|
||||||
&mut self.style_mut().visuals
|
&mut self.style_mut().visuals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ fn dark_light_mode_switch(ui: &mut egui::Ui) {
|
||||||
let style: egui::Style = (*ui.ctx().style()).clone();
|
let style: egui::Style = (*ui.ctx().style()).clone();
|
||||||
let new_visuals = style.visuals.light_dark_small_toggle_button(ui);
|
let new_visuals = style.visuals.light_dark_small_toggle_button(ui);
|
||||||
if let Some(visuals) = new_visuals {
|
if let Some(visuals) = new_visuals {
|
||||||
ui.ctx().set_style(egui::Style { visuals, ..style });
|
ui.ctx().set_visuals(visuals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue