Skip to main content

Module font_picker

Module font_picker 

Source
Expand description

FontPicker — a drop-in font-family selector.

A ComboBox preset that lists every installed font family and lets the user pick one, in the tradition of Qt’s QFontComboBox, GTK’s FontChooser, and UIKit’s UIFontPickerViewController. It

  • self-populates from the app’s shared typesetter (ctx.app_state::<SharedTypesetter>()families()), so no font list is passed in;
  • previews each font: every row shows the family name in a legible system font next to a tiny sample rendered in that font (FontPreviewMode::NameThenSample, the default), and the closed trigger shows the selected family in its own typeface;
  • is searchable (type to filter hundreds of fonts) and filterable by spacing (FontSpacingFilter) and by writing system ([WritingSystem]);
  • binds the choice to a Signal<Option<String>> (the family name), which plugs straight into TextStyle.family / RichTextEditor::set_font_family.
let family: Signal<Option<String>> = Signal::new(None);
VStack::new()
    .child(TextWidget::new(tr!(font())).style(TextStyleRole::BodyBold))
    .child(FontPicker::new(family.clone())
        .on_select(|name, _ctx| editor.set_font_family(name)));

§Writing-system detection is off-thread

Classifying which scripts a font covers parses its OS/2 table, i.e. reads the font file — hundreds of reads for a full system. The picker therefore builds the coverage index on a background thread the first time it mounts and polls readiness on the frame tick; until the index is ready the writing-system filter shows the unfiltered list and samples fall back to a Latin default. Spacing (monospaced / proportional) filtering is instant (it uses only font metadata, no bytes).

Only family selection is offered, matching Qt’s QFontComboBox. Face / weight / size selection belongs to a larger font dialog and is out of scope.

Structs§

FontMeta
Per-family metadata for headless testing / restricted font sets via FontPicker::families_with_meta. In a real app this data comes from the shared typesetter instead.
FontPicker
A font-family selector built on ComboBox. See the module docs.

Enums§

FontPreviewMode
How each row — and the closed trigger — previews a font.
FontSpacingFilter
Spacing filter, mirroring the monospaced / proportional axis of Qt’s QFontComboBox::FontFilters. Cheap — it reads only font metadata.