Skip to main content

RoleColor

Struct RoleColor 

Source
pub struct RoleColor {
    pub color: Hsla,
    pub foreground: Hsla,
    pub hover_mix: f32,
    /* private fields */
}
Expand description

A semantic color role (accent, default, success, warning, danger).

v3 removed numbered scales; a role carries only its base value and readable foreground, and every other shade is derived.

Fields§

§color: Hsla

e.g. --accent.

§foreground: Hsla

e.g. --accent-foreground.

§hover_mix: f32

Weight of foreground in the *-hover mix. 0.10 for the status and accent roles, 0.04 for default.

Implementations§

Source§

impl RoleColor

Source

pub fn new(color: Hsla, foreground: Hsla) -> Self

Creates a role from its base color and on-color foreground, with the default hover, soft and soft-foreground mixes.

Source

pub fn with_hover_mix(self, hover_mix: f32) -> Self

default mixes only 4% of its foreground on hover.

Ignored once RoleColor::with_hover has named the shade outright.

Source

pub fn with_hover(self, hover: Hsla) -> Self

Replaces the derived *-hover shade with an explicit colour.

This is the role-level hook: every component that hovers this role — a Variant::Primary button, a select trigger, a menu row — reads RoleColor::hover, so naming it here makes the whole surface correct by construction rather than one call site at a time. It is the alternative to registering a named component recipe carrying a crate::ComponentColor::Literal and converting each site to it, which leaves any newly written site on the derived shade.

Leaves *-soft-hover alone: that shade is an alpha of the role over transparent and does not mix the foreground in.

Source

pub fn hover_override(&self) -> Option<Hsla>

The explicit *-hover, when one was named.

Source

pub fn with_soft_mix(self, soft: f32, soft_hover: f32) -> Self

Sets the shares of the role color in --role-soft and --role-soft-hover (default sits at 50/60, the rest at 15/20 in light and 12/16 in dark for the cooler roles).

Source

pub fn with_soft_foreground_mix(self, color: f32, foreground: f32) -> Self

--role-soft-foreground: color-mix(in oklab, var(--role) C%, var(--foreground) F%)

Source

pub fn with_vibrant_palette(self, vibrant: bool) -> Self

Opts this role into [data-vibrant-palette="true"]. Set through crate::ThemeBuilder::vibrant_palette, which fans the flag out over every role at once, the way the attribute selector does.

Source

pub fn is_vibrant_palette(&self) -> bool

Whether this role resolves its soft foreground with the vibrant weights.

Source

pub fn with_soft_foreground_role(self) -> Self

--default-soft-foreground: var(--default-foreground)

Source

pub fn hover(&self) -> Hsla

--color-accent-hover: color-mix(in oklab, var(--accent) 90%, var(--accent-foreground) 10%)

RoleColor::with_hover replaces this derivation with a named colour.

Source

pub fn soft(&self) -> Hsla

--color-accent-soft: color-mix(in oklab, var(--accent) 15%, transparent)

Source

pub fn soft_hover(&self) -> Hsla

--color-accent-soft-hover: color-mix(in oklab, var(--accent) 20%, transparent)

Source

pub fn soft_foreground(&self, page_foreground: Hsla) -> Hsla

--color-accent-soft-foreground: color-mix(in oklab, var(--accent) 70%, var(--foreground) 30%)

The mixing roles blend against the page foreground, so pass the live ThemeColors::foreground — a ThemeBuilder::foreground override then flows through without rebuilding the theme.

Source

pub fn with_alpha(&self, alpha: f32) -> Hsla

Returns the role color with the given alpha.

Trait Implementations§

Source§

impl Clone for RoleColor

Source§

fn clone(&self) -> Self

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 Copy for RoleColor

Source§

impl Debug for RoleColor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more