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: Hslae.g. --accent.
foreground: Hslae.g. --accent-foreground.
hover_mix: f32Weight of foreground in the *-hover mix. 0.10 for the status and
accent roles, 0.04 for default.
Implementations§
Source§impl RoleColor
impl RoleColor
Sourcepub fn new(color: Hsla, foreground: Hsla) -> Self
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.
Sourcepub fn with_hover_mix(self, hover_mix: f32) -> Self
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.
Sourcepub fn with_hover(self, hover: Hsla) -> Self
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.
Sourcepub fn hover_override(&self) -> Option<Hsla>
pub fn hover_override(&self) -> Option<Hsla>
The explicit *-hover, when one was named.
Sourcepub fn with_soft_mix(self, soft: f32, soft_hover: f32) -> Self
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).
Sourcepub fn with_soft_foreground_mix(self, color: f32, foreground: f32) -> Self
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%)
Sourcepub fn with_vibrant_palette(self, vibrant: bool) -> Self
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.
Sourcepub fn is_vibrant_palette(&self) -> bool
pub fn is_vibrant_palette(&self) -> bool
Whether this role resolves its soft foreground with the vibrant weights.
Sourcepub fn with_soft_foreground_role(self) -> Self
pub fn with_soft_foreground_role(self) -> Self
--default-soft-foreground: var(--default-foreground)
Sourcepub fn hover(&self) -> Hsla
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.
Sourcepub fn soft(&self) -> Hsla
pub fn soft(&self) -> Hsla
--color-accent-soft: color-mix(in oklab, var(--accent) 15%, transparent)
Sourcepub fn soft_hover(&self) -> Hsla
pub fn soft_hover(&self) -> Hsla
--color-accent-soft-hover: color-mix(in oklab, var(--accent) 20%, transparent)
Sourcepub fn soft_foreground(&self, page_foreground: Hsla) -> Hsla
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.
Sourcepub fn with_alpha(&self, alpha: f32) -> Hsla
pub fn with_alpha(&self, alpha: f32) -> Hsla
Returns the role color with the given alpha.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RoleColor
impl RefUnwindSafe for RoleColor
impl Send for RoleColor
impl Sync for RoleColor
impl Unpin for RoleColor
impl UnsafeUnpin for RoleColor
impl UnwindSafe for RoleColor
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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