ui/symbol.rs#
Source: lib/ui/symbol.rs
symbol -- multi-colour vector symbols (device pictures for diagrams and palettes): vicon's
layers with palette roles and stroke widths, parsed once, drawn as vectors or rasterised
once per size and palette and blitted
Symbol::parse(art, vb) -> Symbol art: SVG path layers separated by '|' on a vb[0] x
vb[1] grid (tools/vsym.py writes them from SVG files)
sym.paint(g, x, y, scale, &pal) every layer, the grid's (0, 0) at x, y (the draw
context's coordinates, like Dc::fill), scale = px
per grid unit
sym.raster(g, w, &pal) -> Surface the symbol w px wide in a PARGB surface
sym.height(w) -> px the height of the symbol drawn w px wide
SymPalette { c: [u32; 10] } the colours of the roles SYM_INK .. SYM_HI
SymPalette::from_theme(ui, tint) light, dark or high contrast from the theme's tokens;
tint = the category colour 0xRRGGBB (its light value)
SymPalette::light / dark(text, bg, tint), contrast(ui) the three schemes
pal.powered_off() LEDs and screens dark (a device without power)
SymbolCache::new() rasters of up to 256 (symbol, width, palette)
cache.draw(g, id, &sym, x, y, w, &pal, opacity) the symbol w px wide at x, y: the
cached raster blitted, wider than 256 px the
vectors; opacity 0..255 (power off: 115 = 45 %)
cache.get(g, id, &sym, w, &pal) -> Option<Rc<Surface>> the raster itself
Layer prefixes (vicon.rs's syntax extended, so its art stays valid): F filled (non-zero
rule), E filled (even-odd), neither = stroked with round caps and joins; #n palette role
0..9 (default 0, an 'A' layer 4); S<w> stroke width in grid units (default 1.5; at least
0.8 px when drawn). Layers paint in order. Roles: 0 ink (outlines), 1 body, 2 body shade,
3 screen, 4 category tint, 5 ports and dark parts, 6 ok, 7 warn, 8 crit (status LEDs),
9 highlight. Light and dark themes swap the palette only.
The cache key is (id, width, palette hash) with the palette compared too; `id` is the
caller's number for the symbol. Rasters are drawn at whole pixels, so x, y of draw are
integers; paint takes fractional positions (a zoomed diagram).
SYM_INK: u8 = 0 // outlines
SYM_BODY: u8 = 1 // the device's body
SYM_SHADE: u8 = 2 // a body part in shadow (sides, bezels, recesses)
SYM_SCREEN: u8 = 3 // displays
SYM_TINT: u8 = 4 // the category colour (one band per symbol)
SYM_PORT: u8 = 5 // ports, grilles, dark parts
SYM_OK: u8 = 6 // status LEDs
SYM_WARN: u8 = 7
SYM_CRIT: u8 = 8
SYM_HI: u8 = 9 // highlight (light details)
SYM_ROLES: usize = 10
/// the widest symbol SymbolCache rasterises (px); wider ones are drawn as vectors
SYM_CACHE_MAX_W: i32 = 256
struct Symbola parsed multi-colour symbol (see the module comment)vb: [f32; 2]-- the grid: width and height in grid units
impl Symbol
fn parse(art: &str, vb: [f32; 2]) -> Symbolparse the layers once; layers whose path data does not parse are left outfn layers(&self) -> usizethe number of layers that parsedfn height(&self, w: i32) -> i32the height in px of the symbol drawn w px widefn paint(&self, g: &mut Gfx, x: f32, y: f32, scale: f32, pal: &SymPalette)draw every layer with the grid's (0, 0) at x, y (draw context coordinates) andscalepx per grid unit; the draw colour is keptfn raster(&self, g: &mut Gfx, w: i32, pal: &SymPalette) -> Surfacethe symbol w px wide in a new PARGB surface (height(w) px high)struct SymPalettethe colours of a symbol's roles (straight 0xAARRGGBB, index = SYM_* role)c: [u32; SYM_ROLES]
impl SymPalette
fn from_theme(ui: &Ui, tint: u32) -> SymPalettethe palette of the current theme: high contrast, dark or light; tint = the category colour 0xRRGGBB as it looks in the light themefn light(text: u32, bg: u32, tint: u32) -> SymPalettethe light scheme from the text and window colours (opaque): slate outlines, near-white bodies, pale steel screensfn dark(text: u32, bg: u32, tint: u32) -> SymPalettethe dark scheme: light grey outlines, bodies a step above the window, dark screens, the tint lighter and greyerfn contrast(ui: &Ui) -> SymPalettehigh contrast: outlines and ports in the text colour, every fill in the window colour, the tint band in the highlight (accent) colour, LEDs in the status coloursfn powered_off(&self) -> SymPalettea device without power: status LEDs dark, screens offfn hash(&self) -> u32FNV-1a of the colours (the cache key)struct SymbolCacherasters of symbols per (id, width, palette), the least recently used one dropped beyond 256
impl SymbolCache
fn new() -> SymbolCachefn len(&self) -> usizethe number of rasters keptfn is_empty(&self) -> boolfn clear(&mut self)drop every rasterfn get(&mut self, g: &mut Gfx, id: u32, sym: &Symbol, w: i32, pal: &SymPalette) -> Option<Rc<Surface>>the raster of symbolidw px wide in this palette, made on the first call; None for widths outside 1..=SYM_CACHE_MAX_Wfn draw(&mut self, g: &mut Gfx, id: u32, sym: &Symbol, x: i32, y: i32, w: i32, pal: &SymPalette, opacity: u32)draw symbolidw px wide with its top-left corner at x, y (draw context coordinates) at opacity 0..255: the cached raster, wider than SYM_CACHE_MAX_W the vectors (through a raster when translucent)