Expand description
IconText — a label that draws catalogued characters as real SVG images,
inline with the surrounding text.
§Why
The app used to draw its icons as characters, from an icon font. A TrueType
glyph can only be ONE colour, so multi-colour artwork meant stacking several
private-use glyphs at one origin and painting each a different colour. This
widget removed that ceiling — a character is drawn from its SVG source
(crate::icons), so an icon carries as many colours as its artwork does —
and with every icon site drawing this way, the font itself is gone. An icon
character is now only ever a KEY into the catalog.
§Drop-in
IconTextUi::icon_label takes exactly what egui::Ui::label takes and
returns exactly what it returns, so converting a call site is a one-token
edit — ui.label(x) becomes ui.icon_label(x). Text with no catalogued
character takes a fast path that IS a plain Label, so converting a site
that never shows an icon changes nothing about how it lays out.
Styling survives the split. The text is resolved to one egui::text::LayoutJob
first, then sliced at icon characters, so every run keeps the exact
egui::TextFormat it was given — .strong(), .weak(), .small(),
.color(…), an explicit .font(…), all of it. Each icon is sized from the
font of the run it sits in and tinted with that run’s colour, so an icon in a
.small() label is small and an icon in a red label is red.
§Layout
Segments are emitted into a wrapping horizontal layout, so a line of text
with icons in it wraps like ordinary text rather than overflowing. egui’s
Label cooperates: in a wrapped horizontal layout it starts on the current
row after the previous widget and continues below.
§Image loader
Drawing an SVG needs egui_extras’ image loader on the context. This widget
installs it itself, the first time it actually has an icon to draw, rather
than making every shell remember to — a host that forgot would show blank
gaps where icons should be, with no error. install_image_loaders skips
loaders already present, so the call is idempotent, and the no-icon fast
path never reaches it.
Structs§
- Icon
Text - A label whose catalogued characters are drawn as SVG images inline with the
text. See the module docs; construct with
IconText::newor, at an existingui.labelcall site,IconTextUi::icon_label.
Traits§
- Icon
Text Ui ui.label(…)→ui.icon_label(…): the drop-in seam. Implemented foregui::Ui, so it is in scope wherever this trait is imported.
Functions§
- glyph
- ONE catalogued glyph drawn on its own, in
color— for a status badge or any other place a bare glyph was previously a colouredRichText.Nonewhen the string is not a single catalogued character. - icon_
button - A
egui::Buttonwhose label’s leading catalogued glyph is drawn as artwork instead of as a character — the button counterpart ofIconTextUi::icon_label, for the small✎/✕/▶buttons scattered through the panels. - icon_
button_ colored - The same, in an explicit colour:
colorpaints BOTH the artwork and the text, for a destructive action that has to read red.Noneleaves the button its ambient colours, which is what lets monochrome artwork follow hover and disabled state. - image
- The
Imagefor a catalogued icon, sized toheightpoints and its own aspect. Shared by every site that draws artwork instead of a font glyph — this widget, toolbar buttons, tree rows and palette rows — so one icon is the same size and comes from the same texture wherever it appears. - selectable_
icon_ label - A
selectable_labelwhose leading catalogued glyph is drawn as artwork — for the list rows that lead with an icon (the add-feature palette, the file browser). Falls back to a plainselectable_labelwhen there is no leading icon, so converting a row that turns out to have none changes nothing. - split_
caption - The same split, for a caller that must MEASURE a caption the way
icon_buttonwill draw it: the leading icon (if any) and the remaining text. A caption with no leading icon comes back whole.