Text
micro::text represents multiline text with pre-calculated layout. It parses a
string into lines (split on \n), resolves glyphs from a font, and caches
dimensions for efficient repeated rendering.
Construction
text(font fnt, std::string_view str);
The string is split on newline characters. Each line has its glyphs resolved from the font and dimensions calculated. Unknown characters are silently skipped.
// Single line:
micro::text label{fnt, "Health: 100"};
// Multiple lines:
micro::text dialog{fnt, "Welcome, traveler.\nWhat brings you here?"};
// Empty lines are preserved:
micro::text spaced{fnt, "Line 1\n\nLine 3"};
Rendering
// Pre-created text (efficient for static UI):
micro::text title{fnt, "Game Title"};
rend.draw(title, {160.f, 20.f});
// Multi-line with centered lines:
micro::text dialog{fnt, "Line 1\nLine 2\nLine 3"};
rend.draw(dialog, {100.f, 50.f}, text_options{}.align(align::center).scale(2.f));
// Or use renderer::draw directly for temporary text:
rend.draw(fnt, "Score: 42", {10.f, 10.f});
The pos argument always represents the top-left corner of the text block's bounding box.
Alignment options adjust how individual lines are positioned within that box.
See Renderer → Text for drawing details and Text options for alignment, scaling, and tinting.
Dimensions
[[nodiscard]] constexpr int width() const noexcept;
[[nodiscard]] constexpr int height() const noexcept;
Returns the bounding box dimensions at scale 1×: - Width: The width of the widest line - Height: The sum of all line heights
micro::text title{fnt, "Game Title"};
float centered_x = (320.f - title.width()) / 2.f;
rend.draw(title, {centered_x, 20.f});
Font access
[[nodiscard]] constexpr const font& font() const noexcept;
Returns the font used by this text block:
const auto& atlas = txt.font().atlas();
Performance
Pre-creating text objects is recommended for static or frequently rendered text
(UI elements, dialog boxes, etc.) to avoid per-frame construction overhead.
For one-off or dynamic text (damage numbers, debug output), use the convenience
method renderer::draw(font, string_view, ...) — it constructs a temporary text
internally.