VariableListMath class
Pure variable-height scroll-windowing math for a measured VirtualListElement (BCL only, unit-tested on CI). The uniform-height sibling is VirtualListMath; this one drives a list whose rows have DIFFERENT heights (wrapping chat bubbles), so the renderer maintains a per-index height model and a cumulative-offset array instead of multiplying by one fixed row height. Row Count is bounded (≤ a couple hundred), so rebuilding the whole prefix-sum each time a measurement lands is cheap and keeps the model trivially correct.
public static class VariableListMathPublic Members
Section titled “Public Members”| name | description |
|---|---|
| static BuildOffsets(…) | Rebuild the cumulative top-edge offsets. offsets MUST have length ≥ count + 1; on return offsets[i] is the distance from the content top to row i’s TOP edge, and offsets[count] is the total content height (also the return value). A row uses its measured height when measured[i] is true, else the shared estimate — so an un-shown row contributes an approximate height that refines the moment it is first measured. Negative heights are floored to 0 (a not-yet-laid-out row never shrinks the content). |
| static FindRowById(…) | The data index whose rowId equals id, searched outward from guess (clamped into the list) up to radius rows each way, nearest first. −1 when not found — the row is gone (front-trimmed) or moved further than the radius. Bounded: at most 2·radius+1 rowId calls, so a remap event never costs a full scan of the list. |
| static FirstIndex(…) | First (topmost) logical row to render given the vertical scroll offset (px from the content top) and the cumulative offsets (as filled by BuildOffsets). Returns the first row whose BOTTOM edge (offsets[i+1]) is past scrollY — i.e. the first at-least-partially-visible row — then clamps the window [first, first+poolSize) so it never runs past the end: first ≤ count − poolSize, so scrolling to the bottom always renders the FINAL poolSize rows (the newest). count ≤ poolSize ⇒ 0 (everything fits the pool). |
| static MaxScroll(…) | The maximum scroll offset: how far the content can move up before its bottom aligns with the viewport bottom. 0 when the content is shorter than the viewport (nothing to scroll). Drives both the stick-to-bottom pin and the “is the user currently at the bottom?” test. |
| static StableSlotRow(…) | StableSlots mapping: the data index pool slot slot shows when the window starts at first. Row l lives in slot l % poolSize, so the window [first, first+poolSize) covers every slot exactly once and a row keeps its slot while it stays in the window. Use it in the row Funcs instead of first + slot. poolSize ≤ 0 ⇒ first + slot (the plain mapping). |
| static TopVisibleIndex(…) | The topmost row at least partly under the viewport top: the first row whose BOTTOM edge (offsets[i+1]) is past scrollY, WITHOUT FirstIndex’s pool clamp (which pins the window to the final rows near the bottom, so its result can sit ABOVE the viewport). Walks from from (pass the window’s first row — the answer is never above it — to keep it O(window)); a from that is already past the view top walks back. −1 when count ≤ 0; a scroll past the content end returns the last row. |
See Also
Section titled “See Also”- namespace Stellar.Abstractions.Services