Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
Show 15 fields pub dark: bool, pub overlay_manager: OverlayManager, pub image_tint_recommended: bool, pub kind: ThemeKind, pub colors: ThemeColors, pub visuals: ThemeVisuals, pub typography: Typography, pub spacing: ThemeSpacing, pub window_frame: Frame, pub frame1: Frame, pub frame2: Frame, pub corner_radius: u8, pub inner_margin: i8, pub outer_margin: i8, pub button_padding: Vec2,
}
Expand description

Complete look: colors, typography, frames, and widget visuals.

Theme is Clone. Theme::install takes &mut self (the elegance path records a key on self). Clone before install if you need to keep an unmodified copy:

let mut theme = Theme::new(ThemeKind::TokyoNight);
theme.install(&ctx);

Fields§

§dark: bool

True if the theme is dark

§overlay_manager: OverlayManager

Tracks open windows so OverlayManager::paint_overlay can dim the canvas.

§image_tint_recommended: bool

True if a tint is recomended to be applied to images to soften the contrast between the image and the background

This is usually true for themes with very dark background

§kind: ThemeKind

Which built-in palette this theme was constructed from.

§colors: ThemeColors

Semantic color slots.

§visuals: ThemeVisuals

Per-widget chrome (button, label, combo, text edit, frames).

§typography: Typography

Font sizes used by this crate’s widgets and the demo.

§spacing: ThemeSpacing

Layout rhythm (gaps between siblings and groups).

Widget chrome padding stays on Theme::inner_margin / Theme::button_padding. Apps should pick a step from this scale instead of one-off 4.0 / 12.0 / 16.0 literals.

§window_frame: Frame

Used for Frame not native windows

§frame1: Frame

Base container frame for major UI sections.

§frame2: Frame

Frame for nested elements, like individual list items.

§corner_radius: u8

Corner radius for widgets

§inner_margin: i8

Inner margin for widgets

§outer_margin: i8

Outer margin for widgets

§button_padding: Vec2

Padding inside buttons

Must use this from egui::Ui::spacing_mut to change the padding

Implementations§

Source§

impl Theme

Source

pub fn new(kind: ThemeKind) -> Self

Construct a built-in theme.

Source

pub fn style(&self) -> Style

Stock egui::Style for this kind (widgets, selection, window fill).

Source

pub fn frame1_visuals(&self) -> FrameVisuals

Frame 1 visuals from ThemeVisuals.

Source

pub fn frame2_visuals(&self) -> FrameVisuals

Frame 2 visuals from ThemeVisuals.

Source

pub fn button_visuals(&self) -> ButtonVisuals

Button visuals from ThemeVisuals.

Source

pub fn label_visuals(&self) -> LabelVisuals

Label visuals from ThemeVisuals (same shape as button visuals).

Source

pub fn combo_box_visuals(&self) -> ComboBoxVisuals

Combo-box visuals from ThemeVisuals.

Source

pub fn text_edit_visuals(&self) -> TextEditVisuals

Text-edit visuals from ThemeVisuals.

Source

pub fn button_visuals_from_ctx(ctx: &Context) -> Option<ButtonVisuals>

Widget visuals stored by Theme::install, if any.

Widgets resolve in this order: self.visuals → context → egui::Style.

Source

pub fn label_visuals_from_ctx(ctx: &Context) -> Option<LabelVisuals>

Same as Self::button_visuals_from_ctx for labels.

Source

pub fn combo_box_visuals_from_ctx(ctx: &Context) -> Option<ComboBoxVisuals>

Same as Self::button_visuals_from_ctx for combo boxes.

Source

pub fn text_edit_visuals_from_ctx(ctx: &Context) -> Option<TextEditVisuals>

Same as Self::button_visuals_from_ctx for text edits.

Source

pub fn install(&mut self, ctx: &Context)

Install this theme into the given egui context.

Widgets then pick up their visuals from ctx automatically.

Source

pub fn current(ctx: &Context) -> Theme

Read the current theme from the context if it exists, otherwise return the default theme

Source

pub fn remap_derived_frames(&mut self, old: &ThemeColors)

Keep derived frame colors in sync with a palette change.

Only updates a color if it still matches the previous palette slot (e.g. frame1.fill == old.widget_bg). Custom colors and structural frame properties (margins, rounding, shadow offsets) are left alone.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Eq for Theme

Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.