pub struct ScopedTheme { /* private fields */ }Expand description
A theme drawn in one part of a window without being installed: a
theme’s tokens, their kit and egui’s style for them, applied to a
child Ui (ScopedTheme::show). While it draws, Tokens::of
and Kit::of give its tokens and kit, so egui-pop’s widgets and
custom painting follow it as egui’s do; the rest of the window keeps
the installed theme. A theme editor’s preview, a themed island, a
theme picker’s thumbnails.
Popups follow it too. egui builds the Ui of a popup, a tooltip or
a window from the context’s style, not from the Ui that opened it,
so while the scope draws, egui’s context style is the scoped theme’s
as well (put back when it ends, even after a panic): a combo box’s
list, a tooltip, a context menu or a menu opened inside it, egui’s
or egui-pop’s, is drawn in the scoped theme. A popup drawn later, out
of the scope (egui-pop’s menus::popup_at), records the scope it was
opened in and draws within it (ScopedTheme::within).
What stays the installed theme’s: fonts (egui’s font definitions are
global, rebuilt with the atlas), egui’s light or dark mode
(ctx.theme()), and what is drawn outside the scope. A change to the
context’s style made while the scope draws is undone when it ends:
install themes between frames, as install_tokens says. Build it
once per theme and keep it (compiling the kit has a cost), never per
frame.
use egui_pop_core::theme::{self, ScopedTheme, ThemeSpec, Themes, Tokens};
let ctx = egui::Context::default();
theme::install(&ctx, &ThemeSpec::new("pop-dark"));
let light = ScopedTheme::new(&ctx, Tokens::new(Themes::default().resolve(&ThemeSpec::new("pop-light"))));
ctx.run_ui(Default::default(), |ui| {
light.show(ui, |ui| {
assert!(!Tokens::of(ui.ctx()).dark_mode());
assert!(!ui.visuals().dark_mode);
// What a popup opened here is built from.
assert!(!ui.ctx().global_style().visuals.dark_mode);
});
assert!(Tokens::of(ui.ctx()).dark_mode());
assert!(ui.ctx().global_style().visuals.dark_mode);
})
.textures_delta
.clear();Implementations§
Source§impl ScopedTheme
impl ScopedTheme
Sourcepub fn new(ctx: &Context, tokens: Tokens) -> ScopedTheme
pub fn new(ctx: &Context, tokens: Tokens) -> ScopedTheme
A theme to draw scoped, its kit compiled with the shapes
registered in ctx (kits’ handlers).
pub fn tokens(&self) -> &Arc<Tokens>
pub fn kit(&self) -> &Arc<Kit>
Sourcepub fn current(ctx: &Context) -> Option<ScopedTheme>
pub fn current(ctx: &Context) -> Option<ScopedTheme>
The scoped theme drawing now, if any.
Sourcepub fn show<R>(&self, ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R
pub fn show<R>(&self, ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R
Draws add in a child Ui with this theme: egui’s style for it,
and Tokens::of and Kit::of giving its tokens and kit until
add returns, as ScopedTheme::within does for the popups
opened in it (scopes nest; the previous one comes back, even when
add panics).
Sourcepub fn within<R>(&self, ctx: &Context, f: impl FnOnce() -> R) -> R
pub fn within<R>(&self, ctx: &Context, f: impl FnOnce() -> R) -> R
Runs f with this theme as the context’s, without a Ui of its
own: Tokens::of and Kit::of give its tokens and kit, and
egui’s context style (what egui builds popups, tooltips, menus
and windows from) is its style. Everything comes back when f
returns, even when it panics. For a popup drawn after the scope
that opened it has ended: record ScopedTheme::current when it
opens, and draw it within.
Trait Implementations§
Source§impl Clone for ScopedTheme
impl Clone for ScopedTheme
Source§fn clone(&self) -> ScopedTheme
fn clone(&self) -> ScopedTheme
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ScopedTheme
impl !RefUnwindSafe for ScopedTheme
impl Send for ScopedTheme
impl Sync for ScopedTheme
impl Unpin for ScopedTheme
impl UnsafeUnpin for ScopedTheme
impl !UnwindSafe for ScopedTheme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.