Expand description
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 bevy_sprite::text2d::update_text2d_layout system (in a 2d world space context)
passes it into TextPipeline::update_text_layout_info, which:
- updates a
Layoutfrom theTextSpans, generating newFontAtlases if necessary. - iterates over each glyph in the
Layoutto create aPositionedGlyph, retrieving glyphs from the cache, or rasterizing to aFontAtlasif necessary. PositionedGlyphs are stored in aTextLayoutInfo, which contains all the information that downstream systems need for rendering.
Modules§
- prelude
- The text prelude.
Structs§
- Computed
Text Block - Computed information for a text block.
- Editable
Text - A plain-text text input field.
- Editable
Text Filter - Sets a per-character filter for this text input. Insert and paste edits are ignored if the filter rejects any character.
- Editable
Text Generation - Wrapper around a
parley::Generation. Used to track whenTextLayoutInfois stale and needs reupdating. The initialGenerationof thePlainEditoris not equal to the defaultGenerationvalue, so theTextLayoutInfowill always be given an initial update. - Editable
Text Systems - System set where
EditableText::pending_editsare applied. - Font
- An
Assetthat contains the data for a loaded font, if loaded as an asset. - Font
Atlas - Rasterized glyphs are cached, stored in, and retrieved from, a
FontAtlas. - Font
Atlas Key - Identifies the font atlases for a particular font in
FontAtlasSet - Font
Atlas Set - Set of rasterized fonts stored in
FontAtlases. - FontCx
- A font database and cache, used for font family resolution and text layout.
- Font
Feature Tag - An OpenType font feature tag.
- Font
Features - OpenType features for .otf fonts that support them.
- Font
Features Builder - A builder for
FontFeatures. - Font
Loader - An
AssetLoaderforFonts, for use by theAssetServer - Font
Variation Tag - An OpenType font variation tag.
- Font
Variations - OpenType font variations for variable fonts that support them.
- Font
Variations Builder - A builder for
FontVariations. - Font
Weight - How thick or bold the strokes of a font appear.
- Font
Width - The visual width of a font as a ratio of its normal width, typically 0.5 to 2.0.
<https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass> - Glyph
Atlas Info - Information about a glyph in an atlas.
- Glyph
Atlas Location - The location of a glyph in an atlas, and how it should be positioned when placed.
- Glyph
Cache Key - Key identifying a glyph
- Layout
Cx - Text layout context
- Positioned
Glyph - A glyph of a font, typically representing a single character, positioned in screen space.
- Preedit
Cursor - A selection within IME preedit text, expressed as byte offsets from the start of the preedit.
- RemSize
- Base value used to resolve
Remunits for font sizes. - RunGeometry
- Geometry of a text run used to render text decorations like background colors, strikethrough, and underline.
A run in
bevy_textis a contiguous sequence of glyphs on a line that share the same text attributes like font, font size, and line height. - ScaleCx
- Text scaler context
- Strikethrough
- A text entity with this component is drawn with strikethrough.
- Strikethrough
Color - Color for the text’s strikethrough. If this component is not present, its
TextColorwill be used. - Text2d
Update Systems - System set in
PostUpdatewhere all 2d text update systems are executed. - Text
Background Color - The background color of the text for this section.
- Text
Bounds - The maximum width and height of text. The text will wrap according to the specified size.
- Text
Brush - Per-section metadata attached to shaped text runs.
- Text
Color - The color of the text for this section.
- Text
Cursor Style - Controls text cursor appearance.
- Text
Edit Change - Triggered after applying all pending
TextEdits to theEditableTextbyapply_text_edits. - Text
Entity - A sub-entity of a
ComputedTextBlock. - Text
Font TextFontdetermines the style of a text span within aComputedTextBlock, specifically the font face, the font size, the line height, and the antialiasing method.- Text
Font Template - Text
Iter Scratch - Scratch buffer used to store intermediate state when iterating over text spans.
- Text
Layout - Component with text format settings for a block of text.
- Text
Layout Info - Render information for a corresponding text block.
- Text
Measure Info - Size information for a corresponding
ComputedTextBlockcomponent. - Text
Pipeline - The
TextPipelineis used to layout and render text blocks (seeText/Text2d). - Text
Plugin - Adds text rendering support to an app.
- Text
Reader - System parameter for reading text spans in a text block.
- Text
Span - A span of text in a tree of spans.
- Text
Span Iter - Iterator returned by
TextReader::iter. - Text
Writer - System parameter for reading and writing text spans in a text block.
- Underline
- Add to a text entity to draw its text with underline.
- Underline
Color - Color for the text’s underline. If this component is not present, its
TextColorwill be used.
Enums§
- Font
Hinting - Font hinting strategy, which controls the rasterization for fonts.
- Font
Loader Error - Possible errors that can be produced by
FontLoader - Font
Size - The vertical height of rasterized glyphs in the font atlas in pixels.
- Font
Smoothing - Determines which antialiasing method to use when rendering text. By default, text is rendered with grayscale antialiasing, but this can be changed to achieve a pixelated look.
- Font
Source - Determines how the font face for a text sections is selected.
- Font
Source Template - Font
Style - The slant style of a font face: normal, italic, or oblique.
- Justify
- Describes the horizontal alignment of multiple lines of text relative to each other.
- Letter
Spacing - Specifies the space between each letter of text for
TextandText2d - Line
Break - Determines how lines will be broken when preventing text from running out of bounds.
- Line
Height - Specifies the height of each line of text for
TextandText2d - Text
Edit - Deferred text input edit and navigation actions applied by the
apply_text_editssystem. - Text
Error - Errors related to the textsystem
Constants§
- DEFAULT_
FONT_ DATA - The raw data for the default font used by
bevy_text
Traits§
- Text
Section - Helper trait for using the
TextReaderandTextWritersystem params.
Functions§
- add_
glyph_ to_ atlas - Adds the given subpixel-offset glyph to the given font atlases
- apply_
text_ edits - Applies pending text edit actions to all
EditableTextwidgets. - detect_
text_ needs_ rerender - System that detects changes to text blocks and sets
ComputedTextBlock::should_rerender. - get_
glyph_ atlas_ info - Generates the
GlyphAtlasInfofor the given subpixel-offset glyph. - get_
outlined_ glyph_ texture - Get the texture of the glyph as a rendered image, and its offset
- load_
font_ assets_ into_ font_ collection - Add new font assets to the internal font collection, and set any associated
TextFont’s changed. If any fonts are removed, the font collection is completely rebuilt, the generic families are remapped, and allTextFonts are set changed. - resolve_
font_ source - Resolve a
TextFont’sFontSourceto a font family.