MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextSlice.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8/**
9 * @class TextSlice
10 * @brief Text drawn as glyph quads into one FormaTarget.
11 *
12 * Owns a Text::TextRun and writes its vertices, an optional tail of extra
13 * vertices after them, and the atlas image binding to the target. The
14 * target's buffer must be created with a texture slot at index 0 (the atlas
15 * is bound there). Layout pixels map onto the bounds with
16 * Text::GlyphMap::fit against the run's extent, so a caller that sets
17 * render_bounds to the pixel size of the bounds, at least one line high, gets
18 * one layout pixel per screen pixel; shorter bounds squeeze the text to fit.
19 *
20 * Every change rewrites the target's whole geometry. When an atlas image is
21 * replaced, because the atlas grew or was swapped, every live slice drawing
22 * from that atlas is written again, so no text is left on stale UVs. A slice
23 * whose target has been removed is left alone.
24 *
25 * Always held through shared_ptr, made with make().
26 */
27class TextSlice {
28public:
29 /**
30 * @brief Draw @p text in @p bounds on @p target.
31 *
32 * @param target Where the vertices go.
33 * @param bounds NDC region the run's render_bounds are fitted onto.
34 * @param params Colour, spans, background, render_bounds and atlas.
35 * @param text UTF-8 text.
36 */
37 [[nodiscard]] static std::shared_ptr<TextSlice> make(
38 FormaTarget target,
40 Text::PressParams params,
41 std::string_view text);
42
43 /// @brief Replace the text.
44 void set(std::string_view text);
45
46 /// @brief Replace text and parameters together.
47 void assign(std::string_view text, Text::PressParams params);
48
49 /// @brief Move the text to a new region.
51
52 /// @brief Replace the extra vertices drawn after the glyphs, such as a caret.
53 void set_tail(std::vector<Kakshya::MeshVertex> tail);
54
55 [[nodiscard]] Text::TextRun& run() noexcept { return m_run; }
56 [[nodiscard]] const Text::TextRun& run() const noexcept { return m_run; }
57 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept { return m_bounds; }
58
59 /// @brief Layout pixels to NDC for the current bounds.
60 [[nodiscard]] Text::GlyphMap map() const noexcept;
61
62 /// @brief Write the current state to the target. No-op once the target is gone.
63 void refresh();
64
65private:
66 [[nodiscard]] bool alive() const;
67
68 TextSlice(FormaTarget target, Kinesis::AABB2D bounds, Text::PressParams params);
69
71 Kinesis::AABB2D m_bounds;
72 Text::TextRun m_run;
73 std::vector<Kakshya::MeshVertex> m_tail;
74 std::shared_ptr<Core::VKImage> m_bound_image;
75};
76
77} // namespace MayaFlux::Portal::Forma::internal
Where an element's geometry and texture are written.
Definition Target.hpp:22
const Text::TextRun & run() const noexcept
Definition TextSlice.hpp:56
static std::shared_ptr< TextSlice > make(FormaTarget target, Kinesis::AABB2D bounds, Text::PressParams params, std::string_view text)
Draw text in bounds on target.
Definition TextSlice.cpp:49
void set_bounds(Kinesis::AABB2D bounds)
Move the text to a new region.
Definition TextSlice.cpp:73
std::shared_ptr< Core::VKImage > m_bound_image
Definition TextSlice.hpp:74
std::vector< Kakshya::MeshVertex > m_tail
Definition TextSlice.hpp:73
void set_tail(std::vector< Kakshya::MeshVertex > tail)
Replace the extra vertices drawn after the glyphs, such as a caret.
Definition TextSlice.cpp:79
void refresh()
Write the current state to the target. No-op once the target is gone.
Definition TextSlice.cpp:99
Kinesis::AABB2D bounds() const noexcept
Definition TextSlice.hpp:57
void assign(std::string_view text, Text::PressParams params)
Replace text and parameters together.
Definition TextSlice.cpp:67
Text::GlyphMap map() const noexcept
Layout pixels to NDC for the current bounds.
Definition TextSlice.cpp:85
void set(std::string_view text)
Replace the text.
Definition TextSlice.cpp:61
Text drawn as glyph quads into one FormaTarget.
Definition TextSlice.hpp:27
One string laid out as glyph quads, ready to draw as vertices.
Definition TextRun.hpp:27
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
Linear map from layout pixels to whatever space the vertices are drawn in.
Definition GlyphMesh.hpp:21
Construction parameters for press().
Definition InkPress.hpp:65