Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3118fd9
Added variants to `FontSource` representing generic font families.
ickshonpe Jan 5, 2026
c179b3d
update pipeline
ickshonpe Jan 5, 2026
c504530
After he new font families changes `update_buffer` now leaks font IDs…
ickshonpe Jan 5, 2026
f4436ad
Add migration guide, and fixed font in text example.
ickshonpe Jan 5, 2026
ff3501f
delete unused
ickshonpe Jan 5, 2026
c1c67a5
Add `load_font_assets_into_fontdb_system` to the text2d tests schedule.
ickshonpe Jan 5, 2026
fb3aba8
Try to fix text2d test setup
ickshonpe Jan 5, 2026
40183df
Fixed text2d tests
ickshonpe Jan 5, 2026
88d6c29
Added explanation how the font family is chosen if the font file is a…
ickshonpe Jan 5, 2026
140f0fb
Merge branch 'fix-font-id-leak' into generic-font-families
ickshonpe Jan 5, 2026
3052c13
Merge branch 'main' into generic-font-families
ickshonpe Jan 6, 2026
8842107
Removed changes to text example
ickshonpe Jan 6, 2026
ecad430
Merge branch 'main' into generic-font-families
ickshonpe Jan 8, 2026
ad0f601
Removed redundant comment
ickshonpe Jan 8, 2026
4d9f6b3
Merge branch 'main' into generic-font-families
ickshonpe Jan 13, 2026
e0d0d6a
added generic_font_families example
ickshonpe Jan 13, 2026
3e90b67
reverted text example changes
ickshonpe Jan 13, 2026
152dfcc
Cleaned up example
ickshonpe Jan 13, 2026
3bd1e7f
Merge branch 'main' into generic-font-families
ickshonpe Jan 13, 2026
633917d
Improved the example
ickshonpe Jan 14, 2026
c214049
Merge branch 'generic-font-families' of https://github.com/ickshonpe/…
ickshonpe Jan 14, 2026
5d6829a
Updated and expanded the doc comments.
ickshonpe Jan 14, 2026
1f1ae68
Added `as_family` helper function to `FontSource`
ickshonpe Jan 14, 2026
f3563ea
Added `resolve_font_source` method to `CosmicFontSystem` which looks …
ickshonpe Jan 14, 2026
d36e5ff
Renamed `resolve_font_source` to `get_family`
ickshonpe Jan 14, 2026
1f9e2d2
Updated example
ickshonpe Jan 14, 2026
e1b945f
more doc comments
ickshonpe Jan 14, 2026
15dc9f0
Cleanup doc example
ickshonpe Jan 14, 2026
75f740d
Added import to FontSource doc example
ickshonpe Jan 14, 2026
32308eb
Added example to release note.
ickshonpe Jan 14, 2026
cc35eeb
Removed unused import
ickshonpe Jan 14, 2026
6f17de9
Unwrapped family name in FontSource doc test
ickshonpe Jan 14, 2026
9ae6abf
fixed doctest import
ickshonpe Jan 14, 2026
e965518
another doc test fix
ickshonpe Jan 14, 2026
5319905
another, another doc test fix
ickshonpe Jan 14, 2026
553c4ae
Fix doctest again
ickshonpe Jan 14, 2026
831f0d7
Update examples/ui/generic_font_families.rs
ickshonpe Jan 15, 2026
f55950a
Rewrote description again.
ickshonpe Jan 15, 2026
8eff600
Added motivation paragraph.
ickshonpe Jan 15, 2026
fa14f94
Merge branch 'main' into generic-font-families
ickshonpe Jan 15, 2026
d38e3a1
Fixed release note's example code
ickshonpe Jan 15, 2026
f76dc81
Merge branch 'generic-font-families' of https://github.com/ickshonpe/…
ickshonpe Jan 15, 2026
2ef99fa
Improved release note text..
ickshonpe Jan 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,18 @@ description = "Demonstrates how to display text with strikethrough and underline
category = "UI (User Interface)"
wasm = true

[[example]]
name = "generic_font_families"
path = "examples/ui/generic_font_families.rs"
# Causes an ICE on docs.rs
doc-scrape-examples = false

[package.metadata.example.generic_font_families]
name = "Generic Font Families"
description = "Demonstrates how to use generic font families"
category = "UI (User Interface)"
wasm = true

[[example]]
name = "text"
path = "examples/ui/text.rs"
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ impl TextPipeline {
Family::Name(font.family_name.as_str())
}
FontSource::Family(family) => Family::Name(family.as_str()),
FontSource::Serif => Family::Serif,
FontSource::SansSerif => Family::SansSerif,
FontSource::Cursive => Family::Cursive,
FontSource::Fantasy => Family::Fantasy,
FontSource::Monospace => Family::Monospace,
};

// Save spans that aren't zero-sized.
Expand Down
25 changes: 25 additions & 0 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ pub enum FontSource {
Handle(Handle<Font>),
/// Resolve the font by family name using the font database.
Family(SmolStr),
/// Fonts with serifs — small decorative strokes at the ends of letterforms.
///
/// Serif fonts are typically used for long passages of text and represent
/// a more traditional or formal typographic style.
Serif,
/// Fonts without serifs.
///
/// Sans-serif fonts generally have low stroke contrast and plain stroke
/// endings, making them common for UI text and on-screen reading.
SansSerif,
/// Fonts that use a cursive or handwritten style.
///
/// Glyphs often resemble connected or flowing pen or brush strokes rather
/// than printed letterforms.
Cursive,
/// Decorative or expressive fonts.
///
/// Fantasy fonts are primarily intended for display purposes and may
/// prioritize visual style over readability.
Fantasy,
/// Fonts in which all glyphs have the same fixed advance width.
///
/// Monospace fonts are commonly used for code, tabular data, and text
/// where vertical alignment is important.
Monospace,
}

impl Default for FontSource {
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ Example | Description
[Font Atlas Debug](../examples/ui/font_atlas_debug.rs) | Illustrates how FontAtlases are populated (used to optimize text rendering internally)
[Font Queries](../examples/ui/font_query.rs) | Demonstrates font querying
[Font Weights](../examples/ui/font_weights.rs) | Demonstrates how to use font weights.
[Generic Font Families](../examples/ui/generic_font_families.rs) | Demonstrates how to use generic font families
[Ghost Nodes](../examples/ui/ghost_nodes.rs) | Demonstrates the use of Ghost Nodes to skip entities in the UI layout hierarchy
[Gradients](../examples/ui/gradients.rs) | An example demonstrating gradients
[Overflow](../examples/ui/overflow.rs) | Simple example demonstrating overflow behavior
Expand Down
52 changes: 52 additions & 0 deletions examples/ui/generic_font_families.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! This example demonstrates generic font families
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! This example demonstrates generic font families
//! This example demonstrates generic font families,
//! which look up a matching font from installed fonts on the user's device.
//!
//! This is used as a fallback in case a specific selected font is available,
//! ensuring that the provided font approximately matches the needs
//! of a given piece of text.
//!
//! This feature is most useful for non-game applications;
//! most games instead choose to simply bundle their required fonts
//! to ensure a unified visual look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not quite right, generic font families can be used without loading system fonts, and they are probably best used in conjunction with fallback fonts, but they aren't the fallbacks themselves.

Agonising, but after mashing this up with a bit I wrote, it seems like it's okay now.


use bevy::{prelude::*, text::CosmicFontSystem};

fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins).add_systems(Startup, setup);

app.world_mut()
.resource_mut::<CosmicFontSystem>()
.db_mut()
.load_system_fonts();

app.run();
}

fn setup(mut commands: Commands) {
// UI camera
commands.spawn(Camera2d);

commands.spawn((
Node {
flex_direction: FlexDirection::Column,
left: px(250),
top: px(250),
row_gap: px(10.),
..Default::default()
},
children![
(
Text::new("generic sans serif font"),
TextFont::from(FontSource::SansSerif).with_font_size(30.)
),
(
Text::new("generic serif font"),
TextFont::from(FontSource::Serif).with_font_size(30.)
),
(
Text::new("generic fantasy font"),
TextFont::from(FontSource::Fantasy).with_font_size(30.)
),
(
Text::new("generic cursive font"),
TextFont::from(FontSource::Cursive).with_font_size(30.)
),
(
Text::new("generic monospace font"),
TextFont::from(FontSource::Monospace).with_font_size(30.)
)
],
));
}
7 changes: 7 additions & 0 deletions release-content/release-notes/generic_font_families.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Generic Font Families"
authors: ["@ickshonpe"]
pull_requests: []
---

Support for generic font families has been added through new `FontSource` variants: `Serif`, `SansSerif`, `Cursive`, `Fantasy`, and `Monospace`.