Skip to main content

Module layout

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. index is the offset in that row (0..=len). x/top/bottom give the caret bar geometry.
Layout
The result of laying out a whole field.

Enums§

BoxKind
What a laid-out box paints.

Constants§

BASE_SIZE

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 at y = 0).
layout_wrapped
Lay out an expression no wider than max_width where 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 contains py if any, else the globally nearest gap by Euclidean distance to the gap’s vertical extent.