Skip to main content

Module fonts

Module fonts 

Source
Expand description

Text fonts from the theme: the families named by font.family.ui and font.family.mono, at several weights.

Each name of a token’s list is looked for in order:

  1. faces the application registered (register): bytes it embeds or reads from disk;
  2. the system’s fonts by family name (feature system-fonts, or the faces given by set_system_faces);
  3. the faces bundled by name: egui-pop’s own pair with the bundled-fonts feature (bundled: Inter, JetBrains Mono NL), then egui’s (Ubuntu is egui’s Ubuntu-Light, Hack its Hack). A bundled face is reached by its name only when the system has no family of that name, as platforms resolve a font stack.

The first found is the primary, the others its fallbacks, and egui’s bundled fonts always come last so text never vanishes. A generic name (sans-serif, serif, system-ui; monospace, ui-monospace) stands for the bundled fonts: egui-pop’s pair with bundled-fonts (Inter for the proportional names, JetBrains Mono NL for the monospace ones, at every weight), else egui’s own faces. The built-in themes name only generic families, so the default pair is egui-pop’s with the feature and egui’s without it. A name found nowhere is a problem in the Report (ADR 0003), never replaced in silence; the report says where each name was found (Report::resolved: Ubuntu → bundled Ubuntu-Light).

egui’s FontId has no weight: each weight of WEIGHTS is an egui family of its own, family(role, weight), and font_id gives the FontId to draw with (font_at at a Step of the theme’s size scale). A variable face (a wght axis) serves every weight its axis covers, set on the face (FontTweak::coords); a static face serves its own weight, and a weight a family lacks takes its nearest one, said in the report. egui’s Proportional and Monospace families are the regular weight of ui and mono, so egui’s own widgets follow the theme too.

Where a role’s glyphs sit in their row is the theme’s too (font.baseline-offset.ui, font.baseline-offset.mono, a share of the size, 0 by default): every face of the role’s chain, egui’s fallbacks included, is drawn that much lower (FontTweak::y_offset_factor), under a key of its own (BaselineOffsets). It moves the glyphs, not the row: the layout keeps its sizes.

install_with_offsets runs with the theme (theme::install_tokens); it replaces egui’s font definitions only when the families, their offsets or the registered faces changed (one slow frame: egui rebuilds its atlas).

Any family can also be drawn by name, outside the theme’s roles, as a specimen (a picker drawing each name in its own face, a page comparing fonts); families lists the families there are, with their Origin.

A face is previewed before it is applied through the preview families (set_preview): every install defines them, so they never vanish while a preview draws (egui panics on an unknown family). They draw the role’s families as installed, or the list a preview gives; with_preview draws a Ui in them, the rest of the application keeping the theme’s fonts.

The system’s fonts come from fontdb (feature system-fonts), unless faces are given in their place (set_system_faces: tests, or an application finding fonts its own way).

Modules§

bundled
The fonts egui-pop bundles (feature bundled-fonts, on by default): Inter for interface text, JetBrains Mono NL (without ligatures) for values and code, subset to Latin, Greek and Cyrillic. They are under the SIL Open Font License 1.1, whose text ships with them (the crate’s fonts/ folder). The generic family names draw them, and a theme or a user may name them.

Structs§

BaselineOffsets
How far each role’s glyphs are drawn below their place, a share of the text’s size (font.baseline-offset.ui, font.baseline-offset.mono): 0.1 at 14 points moves them 1.4 points down, a negative share moves them up. The text’s row keeps its height; only the glyphs move, as egui’s FontTweak::y_offset_factor does. 0 for both by default.
Face
A font face the application gives: its family name (as a theme names it), its weight and the bytes of a .ttf or .otf file.
FamilyInfo
A family there is to draw with: its name (as a theme names it), where its faces come from and whether it is monospace.
FontFile
A font file a user added: where it is, and the family and weight its tables give. What settings keep (paths, not bytes): the file is read again when registered (register_files).
InstalledFace
A face drawing a role’s text, as installed: the family the theme names it by (None for egui’s bundled faces behind the theme’s), and its file.
NumberFont
How a value is drawn at a size: the font, and whether its digits are laid in cells (a proportional face asked for numbers).
Report
What install did: the face each family starts with, and what it could not do.
Resolved
Where a family name was found by an install: so a theme author sees Ubuntu → bundled Ubuntu-Light where the system has no Ubuntu.
Weight
A font weight, as CSS and OpenType number them (100 to 900).

Enums§

Numeric
How values line their digits up (font.numeric): egui applies no OpenType feature, so tabular figures (tnum) cannot be asked of a face whose default digits are proportional.
Origin
Where a face comes from.
Role
Which text a family is for.
Step
A step of the theme’s size scale (font.size.xs to font.size.xl).

Constants§

WEIGHTS
The weights each family is installed at.

Functions§

collector
The fonts collector of the debug bridge (among the core ones): what the theme asked, the faces registered with their origin, each egui family’s chain, the sizes, the atlas; and check, the chars of a text no face of a family covers. Read after the first frame (egui has no fonts before).
families
The families a theme or a user may name: the bundled ones (egui-pop’s with bundled-fonts, then egui’s), the faces registered (the application’s, then the user’s files), then the system’s (feature system-fonts), each once. A name in several places is listed at its first place with the origin the install finds it at (origin_of): a registered face before the system’s, the system’s before egui’s.
family
The egui family of a role at a weight (pop.ui.700); a weight not in WEIGHTS gives the nearest installed one.
font_at
The font to draw a role’s text at a weight and a step of the theme’s size scale (font_id at the step’s size).
font_id
The font to draw a role’s text at a weight and a size (points).
install
Installs the families named by the theme’s tokens, with the registered faces, unless they are already installed. In use from the next pass. The icon font (icon::install) is kept, and so are the baseline offsets installed last (install_with_offsets; none at first).
install_with_offsets
install, each role’s glyphs drawn offsets of their size lower (BaselineOffsets): what the theme’s font.baseline-offset.* tokens give.
installed_faces
The faces drawing a role’s regular text, as installed last, in order: the theme’s families found (registered, egui’s or the system’s), then egui’s bundled faces behind them. For a renderer outside egui (an SVG rasteriser, a PDF writer) to draw the same text as the screen. None before the first install.
installed_families
The families installed last: font.family.ui and font.family.mono as asked.
is_generic
Whether a name is a generic one (sans-serif, serif, monospace, system-ui, ui-monospace): it stands for the bundled fonts (egui-pop’s with bundled-fonts, else egui’s), so it is always found. A list ending with one always draws.
number_font
How values are drawn at size (the size of the text around them), from font.numeric and the installed faces: the monospace family at the size matching the interface text’s x-height, or the interface family (its digits in cells when they are not tabular).
number_galley
number_job laid out.
number_job
A value’s text laid out so its digits line up with the values above and below it (number_font): what sliders, readouts and tables of numbers draw. In cells, each digit is its own section, right-aligned in a cell as wide as the face’s widest digit.
origin_of
Where the family a theme names would be found, in the order the install looks (install): registered, then the system’s, then the bundled faces (egui-pop’s, then egui’s); Some(Origin::Bundled) for a generic name (sans-serif), None for a name found nowhere on this machine (its list’s next name draws).
preview
What a role’s preview draws (set_preview): None for the role’s families as installed.
preview_family
The egui family drawing a role’s preview at a weight (set_preview); None until egui’s fonts in use have it (before the first install’s pass).
previewing
Whether a Ui drawing now is in with_preview.
register
Registers a face for the families a theme names; installed with the next theme install. A face of the same family and weight is replaced.
register_files
Registers the faces of font files a user added (paths, as settings keep them), installed with the next theme install or install: each file is read again, checked and registered under its family and weight. A file that cannot be read or parsed is reported, and the face registered before for it, if any, stays.
registered
The faces registered, in order: the application’s and the user’s files.
reinstall
Installs the families again with the faces registered since (after register_files), keeping the families installed; the atlas is rebuilt once, from the next pass. Nothing happens when nothing changed.
report
The last install’s report.
sample_label
A label drawing text in font, the chars no face of its family covers (uncovered) drawn as boxes in the text’s colour.
set_preview
Previews a role’s families before they are applied: the preview families (preview_family, drawn by with_preview) draw the faces found for names in priority order, the role’s families as installed behind them (so a name found nowhere draws the role’s families, never nothing), or the role’s families alone with None. The theme’s own families are untouched. Installed again at once when it changes (one slow frame, from the next pass); every install defines the preview families, so a theme switched while a preview is shown keeps it.
set_system_faces
Gives the system’s fonts in this context in place of those system-fonts finds (tests, so what is drawn never depends on the machine; or an application finding fonts its own way): the faces, their family as a theme names it. None goes back to the system’s. Installed with the next theme install, or at once with reinstall.
shown_font_id
The font a role’s text draws at a weight and a size where it is drawn: the preview family inside with_preview (once egui has it), else font_id.
specimen
The egui family drawing a family by its name at a weight, outside the theme’s roles: a face registered, egui’s or the system’s, egui’s bundled fonts behind it. None until it is installed: the first ask installs the fonts again (one slow frame, from the next pass) and asks for a repaint; draw with another font meanwhile. A name found nowhere draws egui’s bundled fonts, and is said in the Report.
uncovered
The chars of text no face of font’s family covers, each once, in order (whitespace and control chars aside): what egui draws as a box, or panics on under MissingGlyphPolicy::Panic (kittest’s default). Empty before egui’s first pass (no fonts yet).
with_preview
Draws add in a child Ui in the preview families (set_preview): its text styles draw the interface preview (the monospace style, the monospace one), and inside it shown_font_id and the text roles of crate::ui give the preview families too. What draws with an explicit FontId keeps the theme’s fonts. Scopes nest; the previous state comes back when add returns, even when it panics.