[css3-flexbox] flex distribution

The short algorithm I gave you before doesn't quite work. I think this one does:


1.      Reset all flexible sizes to their preferred size

2.      Find free space by subtracting sum of item sizes from available space.

3.      Distribute free space proportional to flex

4.      Fix min/max violations

a.       Adjust each flexible item for min/max.

b.      If the size has changed, it is a violation.

c.       The violation may be positive (min violation) or negative (max violation). Accumulate the difference.

5.      If the sum of all violations is

a.       Zero: we are done

b.      Positive:

                                                              i.      Freeze items with max violations.

                                                            ii.      Go to step 1

c.       Negative

                                                              i.      Freeze items with min violations

                                                            ii.      Go to step 1

It may or may not be shorter than yours but it seems it is less work and it definitely terminates...
Alex

Received on Tuesday, 31 January 2012 05:35:32 UTC