pub struct Themes { /* private fields */ }Expand description
The themes known: the built-in ones and any added.
Implementations§
Source§impl Themes
impl Themes
Sourcepub fn add(&mut self, theme: TokenFile) -> Option<TokenFile>
pub fn add(&mut self, theme: TokenFile) -> Option<TokenFile>
Adds a theme, or replaces the one of the same name (returned).
Sourcepub fn add_text(
&mut self,
name: &str,
text: &str,
) -> Result<Vec<Warning>, Error>
pub fn add_text( &mut self, name: &str, text: &str, ) -> Result<Vec<Warning>, Error>
Reads a theme file (YAML or JSON, TokenFile::parse) and adds it
under name, loaded over its base theme (Themes::check_file).
Only a file that cannot be read at all is an error; what was read
otherwise than written comes back as warnings.
A file carrying its counterpart (COUNTERPART_EXTENSION) adds
it too, under its own name and through the same rule; a
counterpart that cannot be read is a warning, the file’s own
variant added alone.
Sourcepub fn add_path(
&mut self,
name: &str,
path: &Path,
) -> Result<Vec<Warning>, Error>
pub fn add_path( &mut self, name: &str, path: &Path, ) -> Result<Vec<Warning>, Error>
Reads a theme file from disk (a user’s theme) and adds it under
name, as Themes::add_text does. Its YAML goes through the
default cache (crate::cache): read again unchanged, it is not
parsed again, and the loading rule still runs, so its warnings
are the same on a hit.
Sourcepub fn add_path_with(
&mut self,
name: &str,
path: &Path,
cache: &Cache,
) -> Result<Vec<Warning>, Error>
pub fn add_path_with( &mut self, name: &str, path: &Path, cache: &Cache, ) -> Result<Vec<Warning>, Error>
Themes::add_path through a given cache. An entry that cannot
be written is a Warning::NotCached: the file is read all the
same.
Sourcepub fn check_file(&self, file: TokenFile) -> (TokenFile, Vec<Warning>)
pub fn check_file(&self, file: TokenFile) -> (TokenFile, Vec<Warning>)
Loads a theme file over its base theme (its $extends, else
FALLBACK_THEME), the rule every theme file goes through: the
file is brought to the current contract (TokenFile::upgrade),
a seed that cannot be read (crate::palette::SEEDS_EXTENSION)
is left out, then a token whose value does not load (an unreadable value, an
alias to nothing or in a cycle, another type than the base’s or
the contract’s) is left out, so the base theme’s value stays. A
token the base does not have is kept as the file’s own (a
palette, an extension’s component); under a group of the
contract, with a term no token of the base uses, it is reported
as a likely typo. Nothing here fails: each such thing is a
Warning. A base not known yet leaves the tokens unchecked.
Sourcepub fn set_density(&mut self, density: Density, overlay: TokenFile)
pub fn set_density(&mut self, density: Density, overlay: TokenFile)
Replaces a density’s overlay.
pub fn get(&self, name: &str) -> Option<&TokenFile>
Sourcepub fn counterpart_of(&self, name: &str) -> Option<&str>
pub fn counterpart_of(&self, name: &str) -> Option<&str>
The other variant of a theme, as the token files say
(VARIANT_OF_EXTENSION): the theme its own file names, else the
first theme (by name) naming it. Only a known theme other than
itself counts.
Sourcepub fn counterpart(&self, spec: &ThemeSpec) -> Option<String>
pub fn counterpart(&self, spec: &ThemeSpec) -> Option<String>
The counterpart a spec asks for (ThemeSpec::counterpart): a
known theme other than the base, or none.
Sourcepub fn resolve_counterpart(&self, spec: &ThemeSpec) -> Option<ResolvedTokens>
pub fn resolve_counterpart(&self, spec: &ThemeSpec) -> Option<ResolvedTokens>
Resolves a spec’s counterpart, if it has one
(Themes::counterpart), with the spec’s density, accent,
reduced motion and overrides, or the counterpart’s own overrides
(ThemeSpec::counterpart_variant).
Sourcepub fn accents(&self, base: &str) -> Vec<String>
pub fn accents(&self, base: &str) -> Vec<String>
The colour scales of a base theme usable as an accent.
Sourcepub fn resolve(&self, spec: &ThemeSpec) -> ResolvedTokens
pub fn resolve(&self, spec: &ThemeSpec) -> ResolvedTokens
Resolves a spec. Never fails: problems are reported in the result,
and every contract token that has one takes the built-in
pop-dark value.