@@ -319,16 +319,27 @@ solve o0 r0 (LayoutForest cs) =
319319 -> [(a, Constraint)]
320320 -> [(a, Int)]
321321 computeSizes available constraints =
322+ -- The minimum amount of space we need. Calculated by adding up all of
323+ -- the fixed size items and all the minimum sizes of stretchable items
322324 let minTotal = sum $ ffor constraints $ \case
323325 (_, Constraint_Fixed n) -> n
324326 (_, Constraint_Min n) -> n
327+ -- The leftover space is the area we can allow stretchable items to
328+ -- expand into
325329 leftover = max 0 (available - minTotal)
330+ -- The number of stretchable items that will try to share some of the
331+ -- leftover space
326332 numStretch = length $ filter (isMin . snd) constraints
333+ -- Space to allocate to the stretchable items (this is the same for all
334+ -- items and there may still be additional leftover space that will have
335+ -- to be unevenly distributed)
327336 szStretch = floor $ leftover % max numStretch 1
337+ -- Remainder of available space after even distribution. This extra space
338+ -- will be distributed to as many stretchable widgets as possible.
328339 adjustment = max 0 $ available - minTotal - szStretch * numStretch
329340 in snd $ mapAccumL (\adj (a, c) -> case c of
330341 Constraint_Fixed n -> (adj, (a, n))
331− Constraint_Min n -> (0, (a, n + szStretch + adj))) adjustment constraints
342+ Constraint_Min n -> (max 0 (adj-1), (a, n + szStretch + signum adj))) adjustment constraints
332343 isMin (Constraint_Min _) = True
333344 isMin _ = False
334345