MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ x_at()

MAYAFLUX_API PenPosition MayaFlux::Portal::Text::x_at ( std::string_view  text,
GlyphAtlas &  atlas,
size_t  byte_offset,
float  pen_x = 0.F,
float  pen_y = 0.F,
uint32_t  wrap_w = 0,
uint32_t  tab_width = 4 
)

Pen position immediately before byte_offset, in lay_out()'s space.

Re-lays-out the text up to byte_offset (clamped to text.size()) with the same pen origin, wrap_w, and tab_width the caller used to produce the original layout, and returns the resulting final_pen_x/final_pen_y. Wrap decisions before a given offset only depend on codepoints before it, so this reproduces the exact pen position lay_out() would have held at that point in the original call - including on a space, tab, newline, wrapped line start, or the very end of the text, none of which index_at()'s quad-based sibling has a quad to answer from.

This re-walks the prefix on every call rather than caching intermediate pen positions; fine for interactive caret placement, not meant for a tight per-frame loop over long text.

Parameters
textSource UTF-8 string to re-lay-out a prefix of.
atlasGlyphAtlas to query (same one the original layout used).
byte_offsetCodepoint-boundary byte offset to resolve.
pen_xPen origin x, matching the original lay_out() call.
pen_yPen origin y, matching the original lay_out() call.
wrap_wWrap column, matching the original lay_out() call.
tab_widthTab stop width, matching the original lay_out() call.
Returns
Pen position immediately before byte_offset.

Definition at line 345 of file TypeSetter.cpp.

353{
354 const size_t clamped = std::min(byte_offset, text.size());
355 const LayoutResult prefix = lay_out(text.substr(0, clamped), atlas, pen_x, pen_y, wrap_w, tab_width);
356 return { .x = prefix.final_pen_x, .y = prefix.final_pen_y };
357}
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.
Result of lay_out(), carrying the quads and the final pen position.

References MayaFlux::Portal::Text::LayoutResult::final_pen_x, MayaFlux::Portal::Text::LayoutResult::final_pen_y, and lay_out().

Referenced by MayaFlux::Portal::Text::TextRun::caret(), and index_at().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: