Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
    pub background: Color,
    pub label: Color,
    pub secondary_label: Color,
    pub accent: Color,
    pub separator: Color,
    pub row_highlight: Color,
    pub row_font: Font,
    pub header_font: Font,
    pub row_height: f32,
    pub corner_radius: f32,
    pub padding: Insets,
    pub column_gap: f32,
}
Expand description

The full visual theme. Every semantic Color resolves against one of these, and spacing/radius/row-height are tunable so a consumer can fully restyle.

Fields§

§background: Color

Popup background fill.

§label: Color

Primary text color.

§secondary_label: Color

De-emphasized text color.

§accent: Color

Accent color (selection, checkmarks).

§separator: Color

Separator / hairline color.

§row_highlight: Color

Row background when hovered/selected.

§row_font: Font

Default row font.

§header_font: Font

Section-header font.

§row_height: f32

Default row height in logical points.

§corner_radius: f32

Corner radius of the popup panel in logical points. (The hover highlight uses its own fixed selection radius, independent of this value.)

§padding: Insets

Inner padding of the popup.

§column_gap: f32

Horizontal gap between leading icon, segments, and trailing column.

Implementations§

Source§

impl Theme

Source

pub fn light() -> Self

The default light theme.

Source

pub fn dark() -> Self

The default dark theme.

Examples found in repository?
examples/usagio_menu.rs (line 255)
253fn demo_theme_resolution() {
254    // A consumer can resolve semantic colors against any theme with no GUI.
255    let dark = Theme::dark();
256    let label = dark.resolve(Color::Label);
257    let red = dark.resolve(Color::SystemRed);
258    println!(
259        "theme resolution (dark): Label -> rgba({},{},{},{}), SystemRed -> rgba({},{},{},{})",
260        label.r, label.g, label.b, label.a, red.r, red.g, red.b, red.a,
261    );
262}
Source

pub fn native() -> Self

The native light theme: light() with a translucent background so OS vibrancy shows through.

The platform present path composites the raster surface over a native effect backdrop (NSVisualEffectView on macOS, DWM acrylic on Windows) using per-pixel alpha (spec 10-rendering-layout.md §11, locked decision #6); every other field stays the same as light(). The alpha here is a fixed ~82% (209 / 255), approximating the macOS vibrancy material.

Source

pub fn native_dark() -> Self

The native dark theme: dark() with a translucent background so OS vibrancy shows through.

See native() for the mechanism. The alpha here is a fixed ~80% (204 / 255), a reasonable approximation of the macOS dark menu vibrancy material.

Source

pub fn macos(dark: bool) -> Theme

The macOS menu theme (Big Sur+ NSMenu): translucent vibrancy background, tight rows, ~6pt corner radius, SF at the OS menu size. The platform backend injects the live accent, label/separator colors (NSColor), and the SF face + point size on top; these are the native-accurate defaults.

Metrics are the named MACOS_* reference constants (each documents its native NSMenu source); values still needing a pixel-accurate capture are flagged DEVICE-VERIFY(0.10.8) at their definition.

Source

pub fn windows(dark: bool) -> Theme

The Windows 11 menu-flyout theme: acrylic (translucent) background, generously padded rows, 8pt rounded corners, Segoe UI at the OS size. The Windows backend injects the live accent (DwmGetColorizationColor), menu text/graytext colors (GetSysColor), and the Segoe UI face + size.

DEVICE-VERIFY: metrics matched to the Win11 flyout by eye; nudge here.

Source

pub fn gnome(dark: bool) -> Theme

The GNOME/Adwaita menu theme (GTK4 popover): a flat, opaque surface (Linux/X11 has no vibrancy backdrop), 12pt rounded corners, roomy rows, Adwaita colors. The Linux backend injects the live accent and, where the desktop exposes it, the UI font; menu text colors are Adwaita constants (GNOME does not expose them over gsettings).

DEVICE-VERIFY: metrics matched to the Adwaita popover by eye; nudge here.

Source

pub fn for_family(family: OsFamily, dark: bool) -> Theme

The native base theme for an OsFamily in the given mode. Dispatches to macos / windows / gnome.

Source

pub fn make_opaque(&mut self)

Force the background fully opaque (alpha 255), preserving its RGB. Used when the user has disabled OS transparency/vibrancy so the menu is solid instead of translucent-over-nothing.

Source

pub fn resolve(&self, color: Color) -> Rgba

Resolve a (possibly semantic) Color into a concrete Rgba.

Literal Rgba colors pass through unchanged. Semantic roles map to the matching theme field (or a fixed fallback for the system palette and for the accent when it hasn’t been populated from the OS).

Examples found in repository?
examples/usagio_menu.rs (line 256)
253fn demo_theme_resolution() {
254    // A consumer can resolve semantic colors against any theme with no GUI.
255    let dark = Theme::dark();
256    let label = dark.resolve(Color::Label);
257    let red = dark.resolve(Color::SystemRed);
258    println!(
259        "theme resolution (dark): Label -> rgba({},{},{},{}), SystemRed -> rgba({},{},{},{})",
260        label.r, label.g, label.b, label.a, red.r, red.g, red.b, red.a,
261    );
262}

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 Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. 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> AutoreleaseSafe for T
where T: ?Sized,

Source§

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

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<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<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> 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.