TextMesh Class
Manages text content and caches layout data for efficient rendering. More...
Declaration
Public Constructors Index
| TextMesh (std::string text, const float fontScale, const helios::engine::core::data::FontId fontId) noexcept | |
Public Member Functions Index
| const helios::math::aabbf & | localAABB (FontResourceProvider &fontResourceProvider) const noexcept |
|
Returns the local-space axis-aligned bounding box. More... | |
| std::span< helios::math::vec4f > | vertices (FontResourceProvider &fontResourceProvider) const noexcept |
|
Returns the vertex data for rendering. More... | |
| void | setText (std::string text) noexcept |
|
Updates the text string. More... | |
| std::string_view | text () const noexcept |
|
Returns the current text string. More... | |
| void | setFontScale (const float scale) noexcept |
|
Sets the font scale factor. More... | |
| float | fontScale () const noexcept |
|
Returns the current font scale factor. More... | |
| bool | needsUpdate () const noexcept |
|
Checks if the cached layout needs recomputation. More... | |
| helios::engine::core::data::FontId | fontId () const noexcept |
|
Returns the font identifier. More... | |
Private Member Functions Index
| void | updateCache (FontResourceProvider &fontResourceProvider) const |
|
Updates the cached layout if needed. More... | |
Private Member Attributes Index
| helios::engine::core::data::FontId | fontId_ |
|
Font identifier for glyph lookup. More... | |
| std::string | text_ |
|
The text string to render. More... | |
| bool | needsUpdate_ = true |
|
Flag indicating whether the cached layout needs recomputation. More... | |
| TextLayout | textLayout_ |
|
Cached layout data (AABB and vertices). More... | |
| TypeSetter | typeSetter_ |
|
TypeSetter instance for computing text layout. More... | |
| float | fontScale_ = 1.0f |
|
The scale factor for the font. More... | |
Description
Manages text content and caches layout data for efficient rendering.
`TextMesh` encapsulates a text string along with its font and provides lazy computation of vertex data and bounding boxes. The layout is computed on-demand and cached until the text content changes.
## Caching Strategy
- Layout computation is deferred until `vertices()` or `localAABB()` is called.
- The cache is invalidated when `setText()` is called.
- The `TypeSetter` is used internally to compute glyph positions.
## Usage
```cpp TextMesh mesh("Score: 0", FontId{1});
// Access vertices for rendering (triggers layout if needed) auto verts = mesh.vertices(fontProvider);
// Update text (invalidates cache) mesh.setText("Score: 100"); ```
- See Also
- See Also
- See Also
Definition at line 62 of file TextMesh.ixx.
Public Constructors
TextMesh()
| inline explicit noexcept |
Constructs a TextMesh with the given text and font.
- Parameters
-
text The text string to render.
fontScale The scale of the font, relative to the pixelHeight it was loaded with.
fontId The font identifier for glyph lookup.
Definition at line 119 of file TextMesh.ixx.
Public Member Functions
fontId()
| inline nodiscard noexcept |
Returns the font identifier.
- Returns
The font ID used for glyph lookup.
Definition at line 217 of file TextMesh.ixx.
Referenced by TextMesh.
fontScale()
| inline nodiscard noexcept |
Returns the current font scale factor.
- Returns
The scale factor relative to the font's pixel height.
Definition at line 199 of file TextMesh.ixx.
Referenced by TextMesh.
localAABB()
| inline nodiscard noexcept |
Returns the local-space axis-aligned bounding box.
Triggers layout computation if the cache is invalid.
- Parameters
-
fontResourceProvider Provider for glyph data.
- Returns
Reference to the cached AABB.
Definition at line 139 of file TextMesh.ixx.
needsUpdate()
| inline noexcept |
Checks if the cached layout needs recomputation.
- Returns
True if the layout is invalid and needs to be recomputed.
Definition at line 208 of file TextMesh.ixx.
setFontScale()
| inline noexcept |
Sets the font scale factor.
Invalidates the cached layout, which will be recomputed on the next call to `vertices()` or `localAABB()`.
- Parameters
-
scale The new scale factor relative to the font's pixel height.
Definition at line 189 of file TextMesh.ixx.
setText()
| inline noexcept |
Updates the text string.
Invalidates the cached layout, which will be recomputed on the next call to `vertices()` or `localAABB()`.
- Parameters
-
text The new text to render.
Definition at line 167 of file TextMesh.ixx.
Reference text.
text()
| inline nodiscard noexcept |
vertices()
| inline nodiscard noexcept |
Returns the vertex data for rendering.
Each glyph is represented as 6 vertices (2 triangles). Triggers layout computation if the cache is invalid.
- Parameters
-
fontResourceProvider Provider for glyph data.
- Returns
A span of vertex data (x, y, texU, texV per vertex).
Definition at line 154 of file TextMesh.ixx.
Private Member Functions
updateCache()
| inline |
Updates the cached layout if needed.
- Parameters
-
fontResourceProvider Provider for glyph data.
Definition at line 99 of file TextMesh.ixx.
Private Member Attributes
fontId_
|
Font identifier for glyph lookup.
Definition at line 67 of file TextMesh.ixx.
fontScale_
|
The scale factor for the font.
Definition at line 92 of file TextMesh.ixx.
needsUpdate_
| mutable |
Flag indicating whether the cached layout needs recomputation.
Definition at line 77 of file TextMesh.ixx.
text_
|
textLayout_
| mutable |
Cached layout data (AABB and vertices).
Definition at line 82 of file TextMesh.ixx.
typeSetter_
| mutable |
TypeSetter instance for computing text layout.
Definition at line 87 of file TextMesh.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.