Skip to main content

Module vector_icon

Module vector_icon 

Source
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§

IconPath
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 (EvenOdd is how SVG artwork punches a hole through a ring).
VectorIcon
A resolution-independent icon: a square view_box and the filled paths inside it, back to front.

Enums§

IconColor
One fill colour of an icon, resolved when the icon is painted.

Functions§

icon
Look up a registered icon. None means “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 icon under id, replacing any previous registration.
register_svg_icon
Register icon under id, replacing any icon already registered there. Sugar over register_icon for the build-then-register flow.