pub struct ThemeBuilder { /* private fields */ }Expand description
The design-token vocabulary: the Theme bundle plus its
component token tables, flat-re-exported from frust-theme so app code
never names that crate directly. A root component reads the active theme via
use_context::<Theme>(); a widget reads it during paint/layout via
PaintCtx::theme_as/LayoutCtx::theme_as (or Theme::from_paint_ctx).
Includes the glass material tokens — this crate ships the opaque recipe, and a design system authors its own translucent one over the same types:
use frust::GlassScale;
let glass = GlassScale::opaque_material();
assert_eq!(glass.chrome.blur_radius_intent, 0.0);
assert!(glass.control.is_opaque());Also the composable-theming surface:
ThemeBuilder (defineTheme/copyWith analog), the no-lock-in typed
extension slot (ThemeExtensions) plus its first consumer
StatusPalette/StatusColors (success/warning/info), and the motion
vocabulary (MotionDurations/EasingSet) — all flat-re-exported so an
app (or a design-system plugin) authors a theme against frust::* alone.
A layered builder over a Theme baseline — see the module docs for the
full precedence order. Every method takes/returns Self by value so calls
chain (Theme::builder(base).colors_dark(..).map_shape(..).build()).
Implementations§
Source§impl ThemeBuilder
impl ThemeBuilder
Sourcepub fn new(base: Theme) -> ThemeBuilder
pub fn new(base: Theme) -> ThemeBuilder
Start a builder from base — typically
Theme::neutral or a design system’s
own baseline, but any already-built Theme works (e.g. re-deriving
one theme from another).
Sourcepub fn colors_light(self, scheme: ColorScheme) -> ThemeBuilder
pub fn colors_light(self, scheme: ColorScheme) -> ThemeBuilder
Whole-group swap: replace the light ColorScheme outright.
Sourcepub fn map_colors_light(
self,
f: impl FnOnce(ColorScheme) -> ColorScheme,
) -> ThemeBuilder
pub fn map_colors_light( self, f: impl FnOnce(ColorScheme) -> ColorScheme, ) -> ThemeBuilder
Per-token closure edit: hand the current light ColorScheme to f,
keeping whatever fields it doesn’t overwrite (Rust struct-update ..
ergonomics).
Sourcepub fn colors_dark(self, scheme: ColorScheme) -> ThemeBuilder
pub fn colors_dark(self, scheme: ColorScheme) -> ThemeBuilder
Whole-group swap: replace the dark ColorScheme outright.
Sourcepub fn map_colors_dark(
self,
f: impl FnOnce(ColorScheme) -> ColorScheme,
) -> ThemeBuilder
pub fn map_colors_dark( self, f: impl FnOnce(ColorScheme) -> ColorScheme, ) -> ThemeBuilder
Per-token closure edit: hand the current dark ColorScheme to f.
Sourcepub fn type_scale(self, scale: TypeScale) -> ThemeBuilder
pub fn type_scale(self, scale: TypeScale) -> ThemeBuilder
Whole-group swap: replace the TypeScale outright.
Sourcepub fn map_type_scale(
self,
f: impl FnOnce(TypeScale) -> TypeScale,
) -> ThemeBuilder
pub fn map_type_scale( self, f: impl FnOnce(TypeScale) -> TypeScale, ) -> ThemeBuilder
Per-token closure edit: hand the current TypeScale to f.
Sourcepub fn shape(self, shape: ShapeScale) -> ThemeBuilder
pub fn shape(self, shape: ShapeScale) -> ThemeBuilder
Whole-group swap: replace the ShapeScale outright.
Sourcepub fn map_shape(self, f: impl FnOnce(ShapeScale) -> ShapeScale) -> ThemeBuilder
pub fn map_shape(self, f: impl FnOnce(ShapeScale) -> ShapeScale) -> ThemeBuilder
Per-token closure edit: hand the current ShapeScale to f.
Sourcepub fn elevation(self, elevation: Elevation) -> ThemeBuilder
pub fn elevation(self, elevation: Elevation) -> ThemeBuilder
Whole-group swap: replace the Elevation table outright.
Sourcepub fn map_elevation(
self,
f: impl FnOnce(Elevation) -> Elevation,
) -> ThemeBuilder
pub fn map_elevation( self, f: impl FnOnce(Elevation) -> Elevation, ) -> ThemeBuilder
Per-token closure edit: hand the current Elevation table to f.
Sourcepub fn motion(self, motion: MotionScheme) -> ThemeBuilder
pub fn motion(self, motion: MotionScheme) -> ThemeBuilder
Whole-group swap: replace the MotionScheme outright.
Sourcepub fn map_motion(
self,
f: impl FnOnce(MotionScheme) -> MotionScheme,
) -> ThemeBuilder
pub fn map_motion( self, f: impl FnOnce(MotionScheme) -> MotionScheme, ) -> ThemeBuilder
Per-token closure edit: hand the current MotionScheme to f.
Sourcepub fn glass(self, glass: GlassScale) -> ThemeBuilder
pub fn glass(self, glass: GlassScale) -> ThemeBuilder
Whole-group swap: replace the GlassScale outright.
Sourcepub fn map_glass(self, f: impl FnOnce(GlassScale) -> GlassScale) -> ThemeBuilder
pub fn map_glass(self, f: impl FnOnce(GlassScale) -> GlassScale) -> ThemeBuilder
Per-token closure edit: hand the current GlassScale to f.
Sourcepub fn brightness(self, brightness: Brightness) -> ThemeBuilder
pub fn brightness(self, brightness: Brightness) -> ThemeBuilder
Set the active Brightness (which of light/dark Theme::scheme
selects).
Sourcepub fn design_language(self, design_language: DesignLanguage) -> ThemeBuilder
pub fn design_language(self, design_language: DesignLanguage) -> ThemeBuilder
Set the DesignLanguage tag. Purely a tag (see
crate::theme::DesignLanguage’s docs) — this does not itself swap
any token group; pair it with the whole-group swaps above when
actually changing baselines.
Sourcepub fn extension<T>(self, ext: T) -> ThemeBuilder
pub fn extension<T>(self, ext: T) -> ThemeBuilder
Insert or replace a typed extension (see crate::extensions) —
replace-by-TypeId, same semantics as
ThemeExtensions::insert.
Trait Implementations§
Source§impl Clone for ThemeBuilder
impl Clone for ThemeBuilder
Source§fn clone(&self) -> ThemeBuilder
fn clone(&self) -> ThemeBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ThemeBuilder
impl !UnwindSafe for ThemeBuilder
impl Freeze for ThemeBuilder
impl Send for ThemeBuilder
impl Sync for ThemeBuilder
impl Unpin for ThemeBuilder
impl UnsafeUnpin for ThemeBuilder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.