Expand description
Host-registered vector icons — small, theme-aware line art that widgets can name by id instead of carrying draw code or bitmaps.
§Why this exists
Schema types such as EditorKind are
cheap-to-clone data: they travel through property snapshots, get
compared, and cross crate boundaries many times per frame. An editor
that wants to show icons therefore names them with strings
("boolean.combine") and the host registers the artwork once at
startup through register_icon. The renderer looks the id up at
paint time and falls back to text when nothing is registered, so a
missing icon degrades instead of blanking the control.
§Shape of an icon
A VectorIcon is a square view_box plus an ordered list of
filled IconPaths — painter’s algorithm, first path at the back.
Each path stores already-flattened closed contours, so painting is
nothing but move_to / line_to / fill on any DrawCtx: no
closures, no captured state, and the geometry is inspectable from
tests. Contours are produced from ordinary SVG path data by
path_data::parse_path, which lets a host paste the d attribute
of hand-authored artwork in verbatim.
§Colour roles
Fills are IconColor roles, not colours, and resolve at paint
time: IconColor::Ink becomes the caller’s ink colour (the theme
text colour, so outlines follow light/dark themes), while
IconColor::Literal passes through untouched for colours that
encode state rather than chrome. This mirrors MatterCAD’s
GrayToColor recolouring rule, where a desaturated grey is chrome
and anything saturated is meaning.
§Coordinates
Icon space is SVG space: origin top-left, +Y downward, 0..view_box
on both axes. agg-gui is Y-up, so VectorIcon::paint flips Y while
mapping into the destination rect. Authoring stays copy-paste
compatible with SVG; nothing downstream has to think about it.
Re-exports§
pub use path_data::parse_path;pub use path_data::IconPathError;
Modules§
- path_
data - SVG path-data parser for
VectorIcon.
Structs§
- Icon
Path - One filled sub-shape of an icon: a set of closed contours in icon
space, a colour role, and the fill rule that combines the contours
(
EvenOddis how SVG artwork punches a hole through a ring). - Vector
Icon - A resolution-independent icon: a square
view_boxand the filled paths inside it, back to front.
Enums§
- Icon
Color - One fill colour of an icon, resolved when the icon is painted.
Functions§
- icon
- Look up a registered icon.
Nonemeans “nothing registered under this id” — callers are expected to fall back to something visible (text) rather than painting nothing. - icon_
from_ svg_ paths - Convenience for hosts: build an icon from
(path data, colour role, fill rule)triples in painter order. - icon_
ids - Every registered id, unordered. Diagnostics and tests.
- register_
icon - Register
iconunderid, replacing any previous registration. - register_
svg_ icon - Register
iconunderid, replacing any icon already registered there. Sugar overregister_iconfor the build-then-register flow.