FW: [css3-flexbox] flex distribution

I wonder if there will be cases when at different iterations free space will change sign. I think it is possible, and it can be nasty.

It maybe a good idea to add a step that will determine if free space is overall positive, and use flexibility of that sign for the rest of algorithm.

Like this:

0.       determine sign of flexibility

a.       add sizes of all items,  *adjusted for min/max*

b.      if sum of preferred sizes is less than available space, use positive flexibility, otherwise use negative flexibility
for the rest of the algorithm use flexibility with the same sign, as determined here

From: Alex Mogilevsky [mailto:alexmog@microsoft.com]
Sent: Monday, January 30, 2012 9:35 PM
To: Tab Atkins Jr.
Cc: www-style@w3.org
Subject: [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:50:58 UTC