LayoutSolver
Turns a list of Constraints into one integer size per segment.
This is the "how many cells does each segment get" half of Layout; where those cells sit on the axis (spacing, Flex offsets, clamping to the rectangle) is Layout's own job. The split is what lets either half be read without skimming the other.
The solver is a pure function of (constraints, available) and holds no state, so it is safe to call from any thread.
The algorithm is three steps:
- every constraint states its fixed demand, and those are handed out first;
- whatever is left over is shared among the constraints that grow (
Fillby weight,MinandMaxwith weight one), honoringMaxcaps and re-distributing what a cap refuses; - if nothing grew and the constraints between them claim the whole axis proportionally, the cells lost to integer division are handed back so the segments fill the container exactly.
Two constraints are resolved before those steps run. Auto becomes the Length the caller's measure function answers for that segment, or a Fill(1) when it answers None (or when the caller had nothing to measure with). Bounded is solved as its base and then checked: a segment that came out below its floor or above its ceiling is frozen at that bound as a fixed demand and the whole axis is solved again for the others, until no bound is violated. Each round freezes at least one segment, so there are at most as many rounds as bounded constraints.
Applications reach this through Layout.split and rarely call solve directly; it is public because how a toolkit decides sizes is the part users most need to be able to read, and a private object documents it to nobody.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
LayoutSolver.type