1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! `LayoutEngine` trait — the stable seam between inkferro and layout backends.
//!
//! See `mod.rs` for the measure-seam and rounding rationale.
use Size;
use AvailableSpace;
/// A measure function for a leaf node.
///
/// Signature mirrors the closure shape that taffy 0.10's
/// `compute_layout_with_measure` accepts (see `taffy_tree.rs:912-913`):
///
/// ```text
/// FnMut(known_dimensions, available_space) -> Size<f32>
/// ```
///
/// We drop the `NodeId` and `Style` parameters that taffy passes to the closure
/// because the measure function is keyed by dom id in the registry; the closure
/// captures whatever state it needs (M1-4 will capture a text-width table).
///
/// `Send` is not required: taffy imposes no thread-safety bound on the measure
/// function, and the M3 napi layer calls render on the JS main thread by design.
/// Re-add `+ Send` when a real thread crossing appears.
pub type MeasureFn = dyn FnMut + 'static;
/// The computed position and size of a node in terminal cells.
///
/// Coordinates are relative to the node's parent (same contract as yoga's
/// `getComputedLeft` / `getComputedTop` used by ink's renderer —
/// `render-node-to-output.ts:129-130`).
///
/// * `x`, `y` — signed to accommodate negative values from margins.
/// * `width`, `height` — unsigned; terminal columns/rows cannot be negative.
/// Stable interface over a layout backend.
///
/// The only required implementation is [`TaffyEngine`]. ADR-1 requires this
/// trait so a yoga-ffi backend can be swapped in if taffy diverges >10% on the
/// conformance corpus.
///
/// # Error handling
/// Methods that can encounter an unknown id return `Result<_, String>`. The
/// string carries a human-readable diagnostic; the caller (RT layer) will
/// convert it to a JS exception in M3. `computed` returns `Option` because
/// rendering an unknown id is not fatal — the renderer skips absent nodes.