pub struct Tokens { /* private fields */ }Expand description
One origin’s declared tokens, in declaration order. Built with the
chaining constructors and handed to crate::Core::set_tokens whole;
each call replaces the caller’s table.
Implementations§
Source§impl Tokens
impl Tokens
pub fn new() -> Self
Sourcepub fn color(self, name: impl Into<String>, c: Color) -> Self
pub fn color(self, name: impl Into<String>, c: Color) -> Self
A colour with one value for both bases.
Sourcepub fn color_themed(
self,
name: impl Into<String>,
light: Color,
dark: Color,
) -> Self
pub fn color_themed( self, name: impl Into<String>, light: Color, dark: Color, ) -> Self
A colour with a value per base.
pub fn color_token(self, name: impl Into<String>, token: ColorToken) -> Self
Sourcepub fn derive(
self,
name: impl Into<String>,
from: &str,
ops: impl IntoIterator<Item = ColorOp>,
) -> Self
pub fn derive( self, name: impl Into<String>, from: &str, ops: impl IntoIterator<Item = ColorOp>, ) -> Self
A colour computed from another: from is a colour
token already in this table or a theme role, and ops the steps
applied to it in order, each colour operand likewise a name
declared before this one. A source that resolves to nothing —
undeclared, a length, this token itself, or one declared after it
— drops the declaration and is reported by Tokens::unresolved;
the core raises unknown-token for each when the table is set. An
empty chain is an alias.
Sourcepub fn length(self, name: impl Into<String>, px: f32) -> Self
pub fn length(self, name: impl Into<String>, px: f32) -> Self
A length in logical px, before env.scale.
Sourcepub fn id(&self, name: &str) -> Option<TokenRef>
pub fn id(&self, name: &str) -> Option<TokenRef>
The reference a declared name resolves to in this table alone — what a Rust app holds instead of the name.
pub fn color_id(&self, name: &str) -> Option<TokenRef>
pub fn length_id(&self, name: &str) -> Option<TokenRef>
Sourcepub fn colors(&self) -> &[(String, ColorToken)]
pub fn colors(&self) -> &[(String, ColorToken)]
The colours, in declaration order.
Sourcepub fn unresolved(&self) -> &[Unresolved]
pub fn unresolved(&self) -> &[Unresolved]
The derived tokens this declaration dropped, with the source that did not resolve.
pub fn is_empty(&self) -> bool
Sourcepub fn resolve_color(&self, i: u16, theme: &Theme) -> Color
pub fn resolve_color(&self, i: u16, theme: &Theme) -> Color
The colour token at i under theme: a value’s half, or a
derived token’s recipe folded over its source’s — recursing
through a derived source, which is always an earlier index. A
derived colour comes back rounded to eight bits a channel, so it is
exactly what a reader gets through 0xRRGGBBAA.
Sourcepub fn halves(&self, i: u16, theme: &Theme) -> (Color, Color)
pub fn halves(&self, i: u16, theme: &Theme) -> (Color, Color)
Both halves of the colour token at i, the light first: a value’s
as declared; a derived token’s computed under theme for the half
in effect and under a theme of the other appearance with the same
accent for the other — what the devtools show beside the swatch.