Skip to main content

TextMesh Class

Manages text content and caches layout data for efficient rendering. More...

Declaration

class helios::rendering::text::TextMesh { ... }

Public Constructors Index

TextMesh (std::string text, const float fontScale, const helios::engine::core::data::FontId fontId) noexcept

Constructs a TextMesh with the given text and font. More...

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...

voidsetText (std::string text) noexcept

Updates the text string. More...

std::string_viewtext () const noexcept

Returns the current text string. More...

voidsetFontScale (const float scale) noexcept

Sets the font scale factor. More...

floatfontScale () const noexcept

Returns the current font scale factor. More...

boolneedsUpdate () const noexcept

Checks if the cached layout needs recomputation. More...

helios::engine::core::data::FontIdfontId () const noexcept

Returns the font identifier. More...

Private Member Functions Index

voidupdateCache (FontResourceProvider &fontResourceProvider) const

Updates the cached layout if needed. More...

Private Member Attributes Index

helios::engine::core::data::FontIdfontId_

Font identifier for glyph lookup. More...

std::stringtext_

The text string to render. More...

boolneedsUpdate_ = true

Flag indicating whether the cached layout needs recomputation. More...

TextLayouttextLayout_

Cached layout data (AABB and vertices). More...

TypeSettertypeSetter_

TypeSetter instance for computing text layout. More...

floatfontScale_ = 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

TypeSetter

See Also

TextRenderable

See Also

FontResourceProvider

Definition at line 62 of file TextMesh.ixx.

Public Constructors

TextMesh()

helios::rendering::text::TextMesh::TextMesh (std::string text, const float fontScale, const helios::engine::core::data::FontId fontId)
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.

119 explicit TextMesh(
120 std::string text,
121 const float fontScale,
123 ) noexcept
124 :
125 text_(std::move(text)),
126 fontScale_(fontScale),
127 fontId_(fontId) {}

References fontId, fontScale and text.

Public Member Functions

fontId()

helios::engine::core::data::FontId helios::rendering::text::TextMesh::fontId ()
inline nodiscard noexcept

Returns the font identifier.

Returns

The font ID used for glyph lookup.

Definition at line 217 of file TextMesh.ixx.

217 [[nodiscard]] helios::engine::core::data::FontId fontId() const noexcept {
218 return fontId_;
219 }

Referenced by TextMesh.

fontScale()

float helios::rendering::text::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.

199 [[nodiscard]] float fontScale() const noexcept {
200 return fontScale_;
201 }

Referenced by TextMesh.

localAABB()

const helios::math::aabbf & helios::rendering::text::TextMesh::localAABB (FontResourceProvider & fontResourceProvider)
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.

139 [[nodiscard]] const helios::math::aabbf& localAABB(FontResourceProvider& fontResourceProvider) const noexcept {
140 updateCache(fontResourceProvider);
141 return textLayout_.aabb;
142 }

needsUpdate()

bool helios::rendering::text::TextMesh::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.

208 bool needsUpdate() const noexcept {
209 return needsUpdate_;
210 }

setFontScale()

void helios::rendering::text::TextMesh::setFontScale (const float scale)
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.

189 void setFontScale(const float scale) noexcept {
190 fontScale_ = scale;
191 needsUpdate_ = true;
192 }

setText()

void helios::rendering::text::TextMesh::setText (std::string text)
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.

167 void setText(std::string text) noexcept {
168 text_ = std::move(text);
169 needsUpdate_ = true;
170 }

Reference text.

text()

std::string_view helios::rendering::text::TextMesh::text ()
inline nodiscard noexcept

Returns the current text string.

Returns

View of the text string.

Definition at line 177 of file TextMesh.ixx.

177 [[nodiscard]] std::string_view text() const noexcept {
178 return text_;
179 }

Referenced by setText and TextMesh.

vertices()

std::span< helios::math::vec4f > helios::rendering::text::TextMesh::vertices (FontResourceProvider & fontResourceProvider)
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.

154 [[nodiscard]] std::span<helios::math::vec4f> vertices(FontResourceProvider& fontResourceProvider) const noexcept {
155 updateCache(fontResourceProvider);
156 return textLayout_.vertices;
157 }

Private Member Functions

updateCache()

void helios::rendering::text::TextMesh::updateCache (FontResourceProvider & fontResourceProvider)
inline

Updates the cached layout if needed.

Parameters
fontResourceProvider

Provider for glyph data.

Definition at line 99 of file TextMesh.ixx.

99 void updateCache(FontResourceProvider& fontResourceProvider) const {
100
101 if (!needsUpdate_) {
102 return;
103 }
104
105 textLayout_ = typeSetter_.layout(text_, fontScale_, fontId_, fontResourceProvider);
106
107 needsUpdate_ = false;
108 }

Private Member Attributes

fontId_

helios::engine::core::data::FontId helios::rendering::text::TextMesh::fontId_

Font identifier for glyph lookup.

Definition at line 67 of file TextMesh.ixx.

fontScale_

float helios::rendering::text::TextMesh::fontScale_ = 1.0f

The scale factor for the font.

Definition at line 92 of file TextMesh.ixx.

92 float fontScale_ = 1.0f;

needsUpdate_

bool helios::rendering::text::TextMesh::needsUpdate_ = true
mutable

Flag indicating whether the cached layout needs recomputation.

Definition at line 77 of file TextMesh.ixx.

77 mutable bool needsUpdate_ = true;

text_

std::string helios::rendering::text::TextMesh::text_

The text string to render.

Definition at line 72 of file TextMesh.ixx.

72 std::string text_;

textLayout_

TextLayout helios::rendering::text::TextMesh::textLayout_
mutable

Cached layout data (AABB and vertices).

Definition at line 82 of file TextMesh.ixx.

82 mutable TextLayout textLayout_;

typeSetter_

TypeSetter helios::rendering::text::TextMesh::typeSetter_
mutable

TypeSetter instance for computing text layout.

Definition at line 87 of file TextMesh.ixx.

87 mutable TypeSetter typeSetter_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.