11 constexpr uint32_t k_tab_width = 4;
54 "TextRun: no atlas available, call set_default_font first");
71 const float line =
current ?
static_cast<float>(
current->line_height()) : 0.F;
92 std::vector<Kakshya::MeshVertex>
out;
95 const glm::vec2
a = map({ 0.F, 0.F });
96 const glm::vec2
b = map(
extent());
98 { .min = glm::min(
a,
b), .max = glm::max(
a,
b) },
100 out.insert(
out.end(), quad.begin(), quad.end());
104 out.insert(
out.end(), glyphs.begin(), glyphs.end());
122 const float top = pen.
y - ascender;
124 .min = { pen.
x, top },
125 .max = { pen.
x + width_px, top +
static_cast<float>(
current.line_height()) },
#define MF_ERROR(comp, ctx,...)
std::vector< float > * out
uint32_t line_height() const
Line advance in pixels for this atlas's pixel_size.
uint32_t ascender() const
Ascender in pixels for this atlas's pixel_size.
uint32_t atlas_size() const
Atlas texture dimension (width == height == atlas_size).
Rasterizes and packs glyphs from a FontFace into a TextureContainer.
glm::vec2 extent() const
Size in pixels the run is drawn at.
const PressParams & params() const noexcept
const std::string & text() const noexcept
float content_height() const
Height in pixels the text occupies, from the top of the first line to the bottom of the last.
std::vector< Kakshya::MeshVertex > vertices(const GlyphMap &map, uint32_t slot)
Vertices for the background, if any, then every glyph.
size_t index_at(glm::vec2 px)
Byte offset of the codepoint boundary nearest a layout pixel.
GlyphAtlas * atlas() const
The atlas the run draws from: params().atlas, else the default.
bool stale() const
True when the atlas the layout was built against has since been replaced or has grown,...
void assign(std::string_view text, PressParams params)
Replace text and parameters together, laying out once.
TextRun(PressParams params={})
void set(std::string_view text)
Replace the text and lay it out.
void set_params(PressParams params)
Replace the parameters and lay the current text out again.
Kinesis::AABB2D caret(size_t byte_offset, float width_px)
Pixel rectangle of a caret at a byte offset of the text.
const GlyphAtlas * m_atlas
GlyphAtlas * get_default_glyph_atlas() const
Return the default GlyphAtlas, or nullptr if set_default_font() has not been called successfully.
static TypeFaceFoundry & instance()
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.
std::array< Kakshya::MeshVertex, 6 > textured_mesh_rect(Kinesis::AABB2D region, float weight, glm::vec3 color)
Generate a UV-mapped TRIANGLE_LIST quad (6 vertices, 2 triangles) from an AABB2D, as Kakshya::MeshVer...
void move(EditableText &s, int n)
Move the cursor by n codepoints.
PenPosition x_at(std::string_view text, GlyphAtlas &atlas, size_t byte_offset, float pen_x, float pen_y, uint32_t wrap_w, uint32_t tab_width)
Pen position immediately before byte_offset, in lay_out()'s space.
std::vector< Kakshya::MeshVertex > glyph_vertices(std::span< const GlyphQuad > quads, glm::vec4 color, std::span< const StyleSpan > spans, const GlyphMap &map, uint32_t slot)
Triangle list vertices for glyph quads, six per quad.
LayoutResult lay_out(std::string_view text, GlyphAtlas &atlas, float pen_x, float pen_y, uint32_t wrap_w, uint32_t tab_width)
Lay out a UTF-8 string into a sequence of screen-space quads.
size_t index_at(std::string_view text, const LayoutResult &layout, GlyphAtlas &atlas, float x, float y, float pen_x, float pen_y, uint32_t wrap_w, uint32_t tab_width)
Byte offset of the codepoint boundary nearest a screen-space point.
Axis-aligned bounding rectangle in a 2D coordinate space.
Linear map from layout pixels to whatever space the vertices are drawn in.
std::vector< GlyphQuad > quads
Pen coordinates returned by x_at(), in the same space as GlyphQuad.
GlyphAtlas * atlas
Glyph atlas to use. Null selects the TypeFaceFoundry default at call time.
glm::vec4 color
RGBA color applied to all glyphs not covered by a span in spans.
std::vector< StyleSpan > spans
Optional per-byte-range color overrides. Empty applies color uniformly.
glm::uvec2 render_bounds
Hard render bounds in pixels.
glm::vec4 background
RGBA fill composited beneath every glyph.
Construction parameters for press().