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
3
#include "
MayaFlux/Portal/Forma/Target.hpp
"
4
#include "
MayaFlux/Portal/Text/TextRun.hpp
"
5
6
namespace
MayaFlux::Portal::Forma::internal
{
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
*/
27
class
TextSlice
{
28
public
:
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,
39
Kinesis::AABB2D
bounds
,
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.
50
void
set_bounds
(
Kinesis::AABB2D
bounds
);
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
65
private:
66
[[nodiscard]]
bool
alive
() const;
67
68
TextSlice
(
FormaTarget
target, Kinesis::AABB2D
bounds
, Text::PressParams params);
69
70
FormaTarget
m_target
;
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
Target.hpp
TextRun.hpp
MayaFlux::Portal::Forma::FormaTarget
Where an element's geometry and texture are written.
Definition
Target.hpp:22
MayaFlux::Portal::Forma::internal::TextSlice::m_bounds
Kinesis::AABB2D m_bounds
Definition
TextSlice.hpp:71
MayaFlux::Portal::Forma::internal::TextSlice::run
const Text::TextRun & run() const noexcept
Definition
TextSlice.hpp:56
MayaFlux::Portal::Forma::internal::TextSlice::m_run
Text::TextRun m_run
Definition
TextSlice.hpp:72
MayaFlux::Portal::Forma::internal::TextSlice::m_target
FormaTarget m_target
Definition
TextSlice.hpp:70
MayaFlux::Portal::Forma::internal::TextSlice::make
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
MayaFlux::Portal::Forma::internal::TextSlice::set_bounds
void set_bounds(Kinesis::AABB2D bounds)
Move the text to a new region.
Definition
TextSlice.cpp:73
MayaFlux::Portal::Forma::internal::TextSlice::m_bound_image
std::shared_ptr< Core::VKImage > m_bound_image
Definition
TextSlice.hpp:74
MayaFlux::Portal::Forma::internal::TextSlice::m_tail
std::vector< Kakshya::MeshVertex > m_tail
Definition
TextSlice.hpp:73
MayaFlux::Portal::Forma::internal::TextSlice::set_tail
void set_tail(std::vector< Kakshya::MeshVertex > tail)
Replace the extra vertices drawn after the glyphs, such as a caret.
Definition
TextSlice.cpp:79
MayaFlux::Portal::Forma::internal::TextSlice::refresh
void refresh()
Write the current state to the target. No-op once the target is gone.
Definition
TextSlice.cpp:99
MayaFlux::Portal::Forma::internal::TextSlice::bounds
Kinesis::AABB2D bounds() const noexcept
Definition
TextSlice.hpp:57
MayaFlux::Portal::Forma::internal::TextSlice::run
Text::TextRun & run() noexcept
Definition
TextSlice.hpp:55
MayaFlux::Portal::Forma::internal::TextSlice::alive
bool alive() const
Definition
TextSlice.cpp:90
MayaFlux::Portal::Forma::internal::TextSlice::assign
void assign(std::string_view text, Text::PressParams params)
Replace text and parameters together.
Definition
TextSlice.cpp:67
MayaFlux::Portal::Forma::internal::TextSlice::map
Text::GlyphMap map() const noexcept
Layout pixels to NDC for the current bounds.
Definition
TextSlice.cpp:85
MayaFlux::Portal::Forma::internal::TextSlice::set
void set(std::string_view text)
Replace the text.
Definition
TextSlice.cpp:61
MayaFlux::Portal::Forma::internal::TextSlice
Text drawn as glyph quads into one FormaTarget.
Definition
TextSlice.hpp:27
MayaFlux::Portal::Text::TextRun
One string laid out as glyph quads, ready to draw as vertices.
Definition
TextRun.hpp:27
MayaFlux::Portal::Forma::internal
Definition
Element.hpp:15
std
Definition
BufferUtils.hpp:235
MayaFlux::Kinesis::AABB2D
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition
Bounds.hpp:63
MayaFlux::Portal::Text::GlyphMap
Linear map from layout pixels to whatever space the vertices are drawn in.
Definition
GlyphMesh.hpp:21
MayaFlux::Portal::Text::PressParams
Construction parameters for press().
Definition
InkPress.hpp:65
src
MayaFlux
Portal
Forma
Internal
TextSlice.hpp
Generated by
1.9.8