Module layout
Expand description
Recursive 2D box layout for the math model.
Lays the MathExpr tree out into a flat list of positioned
Box2des with exact glyph metrics from TextRenderer, plus the gap
geometry the caret and hit-testing need. Layout is pure: it reads the
model + a renderer (for measuring) and produces positions; it never
mutates the model.
Coordinates are local to the field’s content origin (0, 0); the caller
translates by the field’s on-screen rect.
Every size here is content: glyphs are measured and painted at exactly
the size the geometry (bars, radicals, delimiters, script offsets) is
built from, never grown again by the reader’s text scale, so a caller
that scales an expression scales all of it together. layout_wrapped
breaks a long expression before its top-level operators.
Structs§
- Box2d
- One positioned, paintable box.
- Gap
- A caret-insertable gap inside one laid-out row.
indexis the offset in that row (0..=len).x/top/bottomgive the caret bar geometry. - Layout
- The result of laying out a whole field.
Enums§
- BoxKind
- What a laid-out box paints.
Constants§
Functions§
- layout
- Lay out a whole expression at the field origin. The fragment’s baseline is
already at local
y = ascent; boxes/gaps are emitted directly in content coords (top of the row aty = 0). - layout_
wrapped - Lay out an expression no wider than
max_widthwhere it can be: a line that would run over breaks before a top-level relation or binary operator, and the continuation lines are indented by one em. Gaps keep their row indices, so a caret still lands where it did. - math_
display_ char - Noto Sans Math encodes mathematical italic letters as their semantic Unicode math alphabet. Keep the source tree plain while selecting those presentation glyphs for single-letter variables.
- measure_
atom - Full horizontal advance of one mathematical atom, including its TeX-style binary/relation spacing. Editors use this when mapping external geometry.
- nearest_
gap - Find the gap nearest a click point
(px, py)(content-local). Picks the row whose vertical band containspyif any, else the globally nearest gap by Euclidean distance to the gap’s vertical extent.