34 releases

new 0.15.0-rc.3 Nov 5, 2024
0.14.2 Sep 6, 2024
0.14.0 Jul 4, 2024
0.13.1 Mar 18, 2024
0.3.0 Nov 3, 2020

#2159 in Game dev

Download history 17542/week @ 2024-07-18 19865/week @ 2024-07-25 18036/week @ 2024-08-01 22199/week @ 2024-08-08 20460/week @ 2024-08-15 21340/week @ 2024-08-22 19502/week @ 2024-08-29 20337/week @ 2024-09-05 15505/week @ 2024-09-12 18535/week @ 2024-09-19 17445/week @ 2024-09-26 14229/week @ 2024-10-03 12286/week @ 2024-10-10 13520/week @ 2024-10-17 14831/week @ 2024-10-24 15302/week @ 2024-10-31

57,589 downloads per month
Used in 216 crates (9 directly)

MIT/Apache

6.5MB
120K SLoC

Bevy Text

License Crates.io Downloads Docs Discord


lib.rs:

This crate provides the tools for positioning and rendering text in Bevy.

Font

Fonts contain information for drawing glyphs, which are shapes that typically represent a single character, but in some cases part of a "character" (grapheme clusters) or more than one character (ligatures).

A font face is part of a font family, and is distinguished by its style (e.g. italic), its weight (e.g. bold) and its stretch (e.g. condensed).

In Bevy, Fonts are loaded by the FontLoader as assets.

TextPipeline

The TextPipeline resource does all of the heavy lifting for rendering text.

UI Text is first measured by creating a TextMeasureInfo in TextPipeline::create_text_measure, which is called by the measure_text_system system of bevy_ui.

Note that text measurement is only relevant in a UI context.

With the actual text bounds defined, the bevy_ui::widget::text::text_system system (in a UI context) or text2d::update_text2d_layout system (in a 2d world space context) passes it into TextPipeline::queue_text, which:

  1. updates a Buffer from the TextSpans, generating new FontAtlasSets if necessary.
  2. iterates over each glyph in the Buffer to create a PositionedGlyph, retrieving glyphs from the cache, or rasterizing to a FontAtlas if necessary.
  3. PositionedGlyphs are stored in a TextLayoutInfo, which contains all the information that downstream systems need for rendering.

Dependencies

~39–71MB
~1.5M SLoC