Skip to content

Font lists#24378

Open
ickshonpe wants to merge 25 commits into
bevyengine:mainfrom
ickshonpe:font-lists
Open

Font lists#24378
ickshonpe wants to merge 25 commits into
bevyengine:mainfrom
ickshonpe:font-lists

Conversation

@ickshonpe
Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe commented May 21, 2026

Objective

Add FontSource variants to support ordered lists of fonts.

Solution

The changes are mostly just boilerplate implementing the API. The lists are just handed off to Parley to resolve.

  • New FontSource variants String and List. bevy_text uses the first available font in the list.
    • FontSource::Names takes a string in CSS font family format.
    • FontSource::List takes a vector of family names and generic font families.
  • FontSource::Family has been renamed to FontSource::Named, to better imply it takes a string and to match the corresponding Names variant.
  • New FontSource::Generic(GenericFontFamily) enum replaces the individual variants for each generic family. Included short form constructors such as FontSource::serif() to be used instead of FontSource::Generic(GenericFontFamily::Serif).
  • Updated the font queries in update_editable_text_content_size.
  • New FontItem and GenericFontFamily enums, these just exist to be Bevy friendly types that are mapped internally to Parley's FontFamilyName and GenericFamily types.
  • New testbed_ui scene for testing: FontLists.

Limitations

  • Ideally text layouts would only be regenerated when the selected font changes. That is, suppose you have a list of "Times New Roman, Fira Sans" and only "Fira Sans" is present, so "Fira Sans" is selected. If you then change the list to "Times New Roman, Fira Sans, Gabriola", "Fira Sans" still takes precedence so the text shouldn't need an update, but with this PR it updates on any changes to the list and the entire text is regenerated.

  • The update_editable_text_content_size function is a bit unpleasant now but I'm not sure if there's a nicer alternative to what it does. Maybe needs more support from Parley.

  • FontSource::List doesn't allow assets handles as items in the font list. This is possible to add, but IMO we should move away from referring to fonts using asset handles.

Testing

testbed_ui's new FontLists scene can be used for testing.

cargo run --example testbed_ui -- fontlists
font_lists

The first available font from the list (going downwards) is used to display each list. The Gabriola font isn't included with Bevy, so it's skipped.

With the "system_font_discovery" feature enabled, the Gabriola font (if present on your system) is used:

cargo run --example testbed_ui --features="system_font_discovery" -- fontlists
font_lists_discovery

@github-actions
Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24378

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@kfc35 kfc35 added C-Feature A new feature, making something new possible A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 21, 2026
@ickshonpe ickshonpe added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24378

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

2 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24378

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@github-actions
Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24378

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

ickshonpe added 4 commits May 22, 2026 15:04
…he loaded collection, instead of the asset path. Store the changed family ids and asset paths, and set the any TextFonts that refer to them as changed.
@github-actions
Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24378

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@ickshonpe ickshonpe added the M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants