9 std::vector<std::weak_ptr<TextSlice>>& live_slices()
11 static std::vector<std::weak_ptr<TextSlice>> slices;
17 static bool active =
false;
21 void reflow_others(
const TextSlice* origin,
const Text::GlyphAtlas* atlas)
28 auto& slices = live_slices();
29 std::erase_if(slices, [](
const auto& slice) {
return slice.expired(); });
30 for (
const auto& weak : slices) {
31 if (
auto slice = weak.lock();
43 : m_target(
std::move(target))
45 , m_run(
std::move(params))
53 std::string_view text)
55 auto slice = std::shared_ptr<TextSlice>(
new TextSlice(std::move(target),
bounds, std::move(params)));
56 live_slices().push_back(slice);
102 if (!atlas || !
alive()) {
107 vertices.insert(vertices.end(),
m_tail.begin(),
m_tail.end());
121 reflow_others(
this, atlas);
std::shared_ptr< NetworkGeometryBuffer > buffer
static std::shared_ptr< TextSlice > make(FormaTarget target, Kinesis::AABB2D bounds, Text::PressParams params, std::string_view text)
Draw text in bounds on target.
void set_bounds(Kinesis::AABB2D bounds)
Move the text to a new region.
std::shared_ptr< Core::VKImage > m_bound_image
std::vector< Kakshya::MeshVertex > m_tail
void set_tail(std::vector< Kakshya::MeshVertex > tail)
Replace the extra vertices drawn after the glyphs, such as a caret.
void refresh()
Write the current state to the target. No-op once the target is gone.
TextSlice(FormaTarget target, Kinesis::AABB2D bounds, Text::PressParams params)
Kinesis::AABB2D bounds() const noexcept
void assign(std::string_view text, Text::PressParams params)
Replace text and parameters together.
Text::GlyphMap map() const noexcept
Layout pixels to NDC for the current bounds.
void set(std::string_view text)
Replace the text.
Text drawn as glyph quads into one FormaTarget.
std::shared_ptr< Core::VKImage > sync(GlyphAtlas &atlas)
Bring the image up to date with atlas.
Rasterizes and packs glyphs from a FontFace into a TextureContainer.
glm::vec2 extent() const
Size in pixels the run is drawn at.
std::vector< Kakshya::MeshVertex > vertices(const GlyphMap &map, uint32_t slot)
Vertices for the background, if any, then every glyph.
GlyphAtlas * atlas() const
The atlas the run draws from: params().atlas, else the default.
void assign(std::string_view text, PressParams params)
Replace text and parameters together, laying out once.
void set(std::string_view text)
Replace the text and lay it out.
std::vector< double > slice(std::span< const double > data, double start_ratio, double end_ratio)
Extract a contiguous slice by ratio, returning a new vector.
Axis-aligned bounding rectangle in a 2D coordinate space.
static GlyphMap fit(Kinesis::AABB2D region, glm::vec2 source_px) noexcept
Map layout pixels [0, source_px] onto region, y flipped.
Linear map from layout pixels to whatever space the vertices are drawn in.
Construction parameters for press().