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

FW: [css3-flexbox] flex distribution

From: Alex Mogilevsky <alexmog@microsoft.com>
Date: Tue, 31 Jan 2012 05:49:53 +0000
To: Tab Atkins Jr. <jackalmage@gmail.com>
CC: "www-style@w3.org" <www-style@w3.org>
Message-ID: <D51C9E849DDD0D4EA38C2E539856928412E27467@TK5EX14MBXC218.redmond.corp.microsoft.com>
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...
Received on Tuesday, 31 January 2012 05:50:58 UTC

This archive was generated by hypermail 2.4.0 : Monday, 23 January 2023 02:14:09 UTC