W3C home > Mailing lists > Public > www-style@w3.org > January 2012

[css3-flexbox] flex distribution

From: Alex Mogilevsky <alexmog@microsoft.com>
Date: Tue, 31 Jan 2012 05:34:49 +0000
To: Tab Atkins Jr. <jackalmage@gmail.com>
CC: "www-style@w3.org" <www-style@w3.org>
Message-ID: <D51C9E849DDD0D4EA38C2E539856928412E24FDB@TK5EX14MBXC218.redmond.corp.microsoft.com>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:49 GMT