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

◆ caret()

Kinesis::AABB2D MayaFlux::Portal::Text::TextRun::caret ( size_t  byte_offset,
float  width_px 
)

Pixel rectangle of a caret at a byte offset of the text.

Spans one line height on the line the offset falls on, in layout pixels with y down, so min.y is the top.

Parameters
byte_offsetCodepoint boundary in the text.
width_pxCaret width in pixels.

Definition at line 108 of file TextRun.cpp.

109{
110 if (stale()) {
111 lay_out_text();
112 }
113 if (!m_atlas) {
114 return {};
115 }
116
117 const auto ascender = static_cast<float>(m_atlas->ascender());
118 GlyphAtlas& current = *atlas();
119 const PenPosition pen = x_at(
120 m_text, current, byte_offset, 0.F, ascender, m_params.render_bounds.x, k_tab_width);
121
122 const float top = pen.y - ascender;
123 return {
124 .min = { pen.x, top },
125 .max = { pen.x + width_px, top + static_cast<float>(current.line_height()) },
126 };
127}
glm::vec2 current
uint32_t ascender() const
Ascender in pixels for this atlas's pixel_size.
GlyphAtlas * atlas() const
The atlas the run draws from: params().atlas, else the default.
Definition TextRun.cpp:38
bool stale() const
True when the atlas the layout was built against has since been replaced or has grown,...
Definition TextRun.cpp:43
const GlyphAtlas * m_atlas
Definition TextRun.hpp:105
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.
glm::uvec2 render_bounds
Hard render bounds in pixels.
Definition InkPress.hpp:88

References MayaFlux::Portal::Text::GlyphAtlas::ascender(), atlas(), current, lay_out_text(), m_atlas, m_params, m_text, MayaFlux::Portal::Text::PressParams::render_bounds, stale(), MayaFlux::Portal::Text::PenPosition::x, MayaFlux::Portal::Text::x_at(), and MayaFlux::Portal::Text::PenPosition::y.

+ Here is the call graph for this function: