Skip to main content

Module text_box

Module text_box 

Source
Expand description

Drawing and geometry for free-floating Text annotations. box_rect is shared between the boundary drawing here and the shape’s gui_rect hit-test in widget.

Structs§

ShownText
A text box’s text as it is drawn: wrapped at its box’s width and elided past TEXT_BOX_MAX_ROWS.

Enums§

BoxWidth
How wide a text box is.

Constants§

BOX_ROUNDING 🔒
Corner rounding of the annotation’s boundary, matching draw_box_outline.
ELLIPSIS 🔒
TEXT_BOX_MAX_COLUMNS
The widest a text box’s text runs before it wraps, in columns of its font.
TEXT_BOX_MAX_ROWS
The most rows a text box shows. The rows past it are elided from the drawing; the document keeps them.
TEXT_INSET 🔒
Horizontal/vertical inset of the text from its anchor. The anchor dot sits at the top-left corner; the text starts just inside it so the two don’t overlap.

Functions§

box_rect
The text box’s on-canvas rect from a given anchor. Prefers the cached size (measured from a real galley when the text was last edited) and only falls back to the text_bbox estimate when no measurement exists yet (a freshly created box, or one saved before extents were). anchor is passed in rather than read from the box so callers can shift it during a drag.
column_cap 🔒
TEXT_BOX_MAX_COLUMNS columns of the title font.
draw_anchor
Draw the solid anchor dot shown while a text box is moved. The Renderer trait exposes circle (not circle_filled); a NONE stroke makes it a filled dot.
draw_boundary
Draw the soft card framing a box’s text in rect: a faint fill plus a thin neutral outline. Drawn before the text so the fill sits behind it.
draw_text
Draw the annotation’s top-left-aligned text at anchor as a box width wide shows it, matching the in-place editor’s wrap.
elided 🔒
text, laid out in rows, cut to the first TEXT_BOX_MAX_ROWS of them. The last row kept ends in an ellipsis, losing the glyphs that would leave it no room for one. A Row holds one glyph per character, less the newline that ends it.
measure_box_size
Measure text as a box width wide shows it and return the box extent in whole grid cells — the shown text’s laid-out size plus the inset padding, rounded up so the box always encloses the text. A box with a width of its own keeps it, and only its height follows the text.
text_bbox 🔒
Estimate a text block’s on-canvas bounding box from its top-left anchor. gui_rect has no painter to lay out a galley, so we approximate from the title font’s size. The estimate stands only until the box is first measured, so a slightly padded one is good enough.
text_origin
Where a box anchored at anchor draws its text’s top-left corner.
widest_cells 🔒