pub struct Theme { /* private fields */ }Expand description
The accent tokens derived from a Brand, for light and dark mode.
Build it with Theme::from_brand; Theme::css is the stylesheet,
Theme::tokens and Theme::dark_tokens the values as data.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn from_brand(brand: &Brand) -> Result<Self, ContrastError>
pub fn from_brand(brand: &Brand) -> Result<Self, ContrastError>
Derives the kit’s accent tokens from brand.
Text colours must reach 4.5:1 on the kit’s background and surface in both colour schemes, the label on the accent 3:1. The brand colour itself is kept; only the text variants move in lightness. When that is not enough, the error carries the nearest colour that works.
use renox::theme::{Brand, Theme};
assert!(Theme::from_brand(&Brand::new("#1E3A5F")).is_ok());
assert!(Theme::from_brand(&Brand::new("#FFF59D")).is_err());§Errors
ContrastError for a malformed colour or one that cannot reach
readable contrast.
Sourcepub fn css(&self) -> &str
pub fn css(&self) -> &str
The stylesheet: a :root block for light mode and the kit’s two dark
selectors (prefers-color-scheme: dark and [data-theme="dark"]).
Load it after the kit’s CSS.
Sourcepub fn hash(&self) -> &str
pub fn hash(&self) -> &str
A short content hash of Theme::css (16 hex digits), the key of the
theme’s cacheable stylesheet URL.
Sourcepub fn tokens(&self) -> BTreeMap<&'static str, String>
pub fn tokens(&self) -> BTreeMap<&'static str, String>
The derived tokens for light mode, such as --rx-accent => #0f766e.
Sourcepub fn dark_tokens(&self) -> BTreeMap<&'static str, String>
pub fn dark_tokens(&self) -> BTreeMap<&'static str, String>
The derived tokens for dark mode.
Trait Implementations§
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> 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,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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