Skip to main content

Module kit

Module kit 

Source
Expand description

Kits as packages (docs/kit-packages.md): a folder holding a kit’s tokens, its fonts and its licence, read at run time or embedded in the binary.

Experimental: may change in any release (docs/stability.md).
underline-tabs/
  kit.yaml            a DTCG token file, like a theme (`$extends`, tokens);
                      `kit.json` is read too
  *.tokens.yaml       optional: more tokens, one file per component
                      (`.tokens.json` is read too)
  fonts/*.ttf|otf     optional: faces for the families the tokens name
  LICENSE             optional: the kit's licence (and its fonts')
  icons/              reserved: not read yet

kit.yaml is a theme: its name is the folder’s, unless its manifest ($extensions."org.egui-pop.kit") gives one, and it extends pop-dark unless it says otherwise. A face’s family and weight come from its file name (Inter-SemiBold.ttf is Inter at 600), or from the manifest when given:

$extends: "pop-dark"
$extensions:
  org.egui-pop.kit:
    name: "brand"
    label: "Brand"
    fonts:
      - {file: "JetBrainsMono-Regular.ttf", family: "JetBrains Mono", weight: 400}

A kit may hold both variants of its look, light and dark: the manifest’s counterpart gives the other variant’s name, label and tokens (a token tree, with its own $extends). It becomes a theme of its own, each naming the other as its counterpart (crate::VARIANT_OF_EXTENSION), so the light, dark or system setting switches between them. kit.yaml’s own tokens are its variant’s only; the other token files (*.tokens.yaml) and the faces serve both.

$extends: "pop-dark"
$extensions:
  org.egui-pop.kit:
    name: "brand-dark"
    label: "Brand Dark"
    counterpart:
      name: "brand-light"
      label: "Brand Light"
      tokens:
        $extends: "pop-light"
        surface: {panel: {$type: "color", $value: "#fafafa"}}
surface: {panel: {$type: "color", $value: "#101010"}}

Reading a kit never fails: what is wrong (bad YAML or JSON, a term outside the vocabulary, a font file missing) is in KitData::problems, and the kit is still usable with fallbacks (a kit whose kit.yaml cannot be read is pop-dark under the kit’s name).

let kit = egui_pop_tokens::kit::KitData::from_text(
    "underline",
    r#"
    tab:
      shape: {$type: "string", $value: "underline"}
    "#,
);
assert!(egui_pop_tokens::kit::check(&kit).is_empty());
let mut themes = egui_pop_tokens::Themes::default();
themes.add_kit(&kit);
assert!(themes.get("underline").is_some());

Structs§

Embedded
What kit! embeds: the folder’s files, named as in the folder.
KitData
A kit’s data: its tokens (a theme), its faces and its licence, with what was wrong reading them. A kit with code adds its handlers around it (egui_pop_core::kit::KitSource).
KitFont
A face a kit ships, for the families its tokens name.
KitInfo
A kit as a theme picker shows it.
KitVariant
A kit’s other variant (KitData::counterpart): the manifest’s counterpart, with the kit’s other token files merged in.

Enums§

Origin
Where a kit was read from.
Problem
What is wrong with a kit. The kit is usable anyway: each problem says what is done instead.

Constants§

COMPONENT_TERMS
The terms that do not change with the state (component.term), with their type.
DISTINCT_GLYPHS
Glyph roles that must keep shapes of their own (glyph.<role>), so that colour never carries a state alone: no two roles of a pair may name the same icon. The LEDs off, on, warning and error differ from each other, a busy LED from all but the on one (it pulses, or shows a still ring under reduced motion), and the four named flags from each other. check reports a kit breaking it, and egui-pop draws its own shapes for those roles.
KIT_EXTENSION
Where a kit’s manifest lives in kit.yaml’s root $extensions.
KIT_FILE
The file every kit folder has.
KIT_FILES
The names a kit folder’s KIT_FILE may have, the first found read.
STATES
The six states (docs/kit.md), in the order their boxes apply.
STATE_TERMS
The terms a state gives (component.state.term), with their type.
TOKEN_FILE_ENDINGS
The endings of a kit’s other token files.
TONES
The tones a component may give (component.tone.<tone>.<term> and component.tone.<tone>.<state>.<term>).
USER_KITS_DIR
The folder under an application’s configuration directory where the user’s kits are found (discover).

Functions§

check
Every problem of a kit: reading it, and resolving its theme over the built-in ones. An application’s tests call it on the kits it embeds, since kit! checks nothing when compiling:
discover
The kits found in a folder: each sub-folder holding a kit.yaml, by name (anything else is not a kit and is skipped). An application’s user kits are in <config>/kits (USER_KITS_DIR); a folder that does not exist has none.
discover_with
discover through a given cache (KitData::load_with).
kit_file
A kit folder’s KIT_FILE, under the first of KIT_FILES found.
same_glyphs
The pairs of DISTINCT_GLYPHS naming the same icon in a resolved theme, with that icon’s name.

Type Aliases§

Bytes
A font file’s bytes: embedded in the binary or read at run time.