How it works
The four steps of a calculation: place, check the boundary, flip, stick.
A calculation runs in four steps. The library reads the sizes and positions, places the item, checks the boundary and, if needed, changes the placement. It never moves the element itself.
The four steps
-
Place. Each element has a reference point, set with
itemAtandtargetAt. The library moves the item so that both points meet, including the offsets. The result ismoveBy. -
Check the boundary. The library measures the distance from the new position to each edge of the
boundary. An edge that the item crosses is listed in
distance.overflow. -
Flip. If an edge overflows and
flipis set, the library calculates the flipped placement. If it has no overflow, the library uses it. Otherwise it chooses, per axis, the placement with less overflow. Flip needs a target. -
Stick. If
stickis set, the library moves the item along the edges you chose so that it stays inside the boundary.
The result of calculate() reflects all four
steps. calcVariant() stops after step 2 and
tests one placement only.
What the model does not cover
The steps use the sizes and positions the library read last. They do not follow later changes by themselves. Call
calculate() again after a scroll or a resize. See
Placement and collisions for the rules of each step and
Limits for what is not handled.