Commit Graph

96 Commits

Author SHA1 Message Date
Emil Sjölander
57874a1a9e Revert "Correctly size cross axis when measuring flex basis" 2016-07-13 10:42:03 +01:00
Emil Sjolander
ca34ff4446 Correctly size cross axis when measuring flex basis 2016-07-08 16:05:21 +01:00
Emil Sjolander
a1f36b53f5 Use AT_MOST measurespec when onyl max dimension is defined 2016-07-02 11:22:57 +01:00
Emil Sjolander
7b0c008300 Improve heuristic for cache re-use 2016-06-09 10:33:00 -04:00
Emil Sjolander
2a816bf5a7 Measure with exact measurement when stretch is defined 2016-06-08 14:00:31 -04:00
Emil Sjolander
c06752e052 Remove whitespace on empty lines etc. 2016-06-03 22:19:03 +01:00
Adam Comella
16f43dac87 Skip measurement when there's no available vertical space
We already did this optimization when there wasn't any
available horizontal space. Now we're covering the
vertical space case as well.

This optimization assumes that, for a node with a
measure function, if there isn't any available
horizontal or vertical space, then we don't need to
measure the node and can assume that the node is 0x0.
2016-05-25 10:53:15 -07:00
Adam Comella
8177bfe702 Heuristics for skipping calls to the measure function
Introduced heuristics that enable css-layout to avoid
calling measure functions under a number of conditions.
This enables us to save time by skipping unnecessary
measurements.
2016-05-18 13:40:34 -07:00
Adam Comella
8779d942ea Fix positioning of items with min/max width/height
We found a case where a flexible item with a max width that was supposed
to be centered was positioned in the wrong location.

The problem was with our 2 pass approach for sizing flexible items with
a min/max width/height. Items sized in the first pass were being double
counted when calculating the remainingFreeSpace. Specifically, their
sizes were being subtracted from remainingFreeSpace in both the first
and second passes.

I also noticed a second unrelated bug. We weren't correctly calculating
deltaFreeSpace in the first pass. When calculating deltaFreeSpace, we
need to take into account the flex basis like we do in the second pass.
Consequently, in the first pass I changed this:
  deltaFreeSpace -= boundMainSize;

To this:
  deltaFreeSpace -= boundMainSize - childFlexBasis;

The problem there was that we'd end up double counting childFlexBasis
in the remainingFreeSpace.
2016-05-11 00:29:40 -07:00
Adam Comella
f3dd51ab97 Alter layout engine to conform closer to W3C spec
The primary goals of this change are:
  - Better conformance to the W3C flexbox standard (https://www.w3.org/TR/css-flexbox-1/)
    and a clear articulation of the areas where it deviates from the spec.
  - Support for flex-shrink.
  - Conformance with layout effects of "overflow: hidden".

Specifically, here are the limitations of this implementation as compared to the W3C
flexbox standard (this is also documented in Layout.js):
  - Display property is always assumed to be 'flex' except for Text nodes, which
    are assumed to be 'inline-flex'.
  - The 'zIndex' property (or any form of z ordering) is not supported. Nodes are
    stacked in document order.
  - The 'order' property is not supported. The order of flex items is always defined
    by document order.
  - The 'visibility' property is always assumed to be 'visible'. Values of 'collapse'
    and 'hidden' are not supported.
  - The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The
    rarely-used 'wrap-reverse' is not supported.
  - Rather than allowing arbitrary combinations of flexGrow, flexShrink and
    flexBasis, this algorithm supports only the three most common combinations:
      - flex: 0 is equiavlent to flex: 0 0 auto
      - flex: n (where n is a positive value) is equivalent to flex: n 0 0
      - flex: -1 (or any negative value) is equivalent to flex: 0 1 auto
  - Margins cannot be specified as 'auto'. They must be specified in terms of pixel
    values, and the default value is 0.
  - The 'baseline' value is not supported for alignItems and alignSelf properties.
  - Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be
    specified as pixel values, not as percentages.
  - There is no support for calculation of dimensions based on intrinsic aspect ratios
    (e.g. images).
  - There is no support for forced breaks.
  - It does not support vertical inline directions (top-to-bottom or bottom-to-top text).

And here is how the implementation deviates from the standard (this is also documented in
Layout.js):
  - Section 4.5 of the spec indicates that all flex items have a default minimum
    main size. For text blocks, for example, this is the width of the widest word.
    Calculating the minimum width is expensive, so we forego it and assume a default
    minimum main size of 0.
  - Min/Max sizes in the main axis are not honored when resolving flexible lengths.
  - The spec indicates that the default value for 'flexDirection' is 'row', but
    the algorithm below assumes a default of 'column'.
2016-04-26 19:45:58 -07:00
Emil Sjolander
7bd6b2b7dd Add support for measure mode 2016-04-01 11:01:16 +01:00
Pieter De Baets
5b56be412c Correct skipLayout condition in Layout.c
Fixes #155
2016-03-30 12:11:49 +01:00
Pieter De Baets
b157ab4a00 Reset child position/sizes before calculating layout 2016-03-29 11:05:53 +01:00
Alex Bogomazov
425345aa8d Redo layout of 'stretch' aligned items for correct positioning of nested
items

Fixes facebook/css-layout#83, facebook/css-layout#100,
facebook/css-layout#127.
2016-02-26 00:43:58 +03:00
Emil Sjolander
c9094f94d0 Check layout instead of style before setting height and width to whatever is set in layout 2016-01-06 15:07:41 +00:00
Martin Kralik
f2aa5ba604 passing height to the measure function
This diff:
* adds height as another parameter passed to the measure function, computed the same way width is
* adds tests for this extension, which has involved adding a new measure function to all of js, c, java and c# tests
2015-12-14 15:00:13 +00:00
Colin Eberhardt
e4c93e8c59 Updated to use eslint from fbjs-scripts 2015-10-07 21:52:22 +01:00
Christopher Chedeau
e280a577ae Fix width being ignored when has a value of 0
8f6a96adbc added a test in isDimDefined that checks if `value > 0.0`, but unfortunately, it did not faithfully port the JavaScript version which is `value >= 0.0`. Sadly, no test covered this so it went unnoticed.
2015-09-25 13:10:21 -07:00
Lucas Rocha
765ff8463e Add fast path for simple stack layouts
Change the initial line loop to opportunistically position children in
the in container with simple stacking params i.e. vertical/horizontal
stacking on non-flexible STRETCH/FLEX_START aligned. This allows us to
skip the main and cross axis loops (Loop C and D, respectively)
partially and even completely in many common scenarios.

In my benchamrks, this gives us about ~15% performance win in many
setups.
2015-09-10 11:19:28 +01:00
Lucas Rocha
909c14117f Fix dimension check for STRETCH children
The correct check is on the layout state, no the style.
2015-09-10 11:19:28 +01:00
Lucas Rocha
9a149c83ff Avoid extra work when justifyContent is FLEX_START
Remaining space and between space only need to be updated when
justifyContent is not FLEX_START.
2015-09-10 11:19:28 +01:00
Lucas Rocha
2321165d53 Move condition to the non-redundant block
No need to check for RELATIVE position when position type is ABSOLUTE
and dimension is set.
2015-09-08 15:34:51 +01:00
Lucas Rocha
d1a49a4f0b Reduce search range of flexible children
We were traversing all children to only perform calculations/changes to
flexible children in order to avoid new allocations during layout. This
diff ensures we only visit flexible children during layout calculations
if any are present. We accomplish this by keeping a private linked list
of flexible children.
2015-09-08 15:34:51 +01:00
Lucas Rocha
793220faf8 Skip final loop on absolute children, if possible
There's no need to go through all absolute children at the end of the
layout calculation if the node at hand doesn't have any. This also
ensures only absolutely positioned children are traversed in the final
loop.
2015-09-08 15:34:51 +01:00
Lucas Rocha
996f2a03d5 Merge pre-fill loop into main line loop
There's no need to go through all children before starting the main line loop
as we'll visit all children in the former loop anyway. This diff merges the
pre-fill loop into the main line one to avoid an extraneous traversal on the
node's children.
2015-09-08 15:34:27 +01:00
Lucas Rocha
877a2838a6 Skip trailing position loop, if possible
There's no need to set the trailing position on left-to-right layouts
as the nodes will already have what we need (x, y, width, and height).
This means we still have an extra cost for reversed layout directions
but they are not as common as LTR ones.
2015-09-08 15:33:26 +01:00
Lucas Rocha
1ab785b7a3 Inline immutable values in layout algorithm
Store immutable values from the node being laid out to avoid unnecessary
method invocations during layout calculation. This gives us a 3%-5%
performance boost in my benchmarks on Android.
2015-09-08 15:15:52 +01:00
Pierre Renaux
fee4d39367 feat(Gruntfile.js): Added package-c task which creates a unified single header css-layout.h for use in C code ; 2015-08-13 16:56:41 +08:00
Lucas Rocha
524b44200a Expose the resolved direction in the node's layout 2015-05-20 11:35:01 +01:00
Pierre Renaux
019fc9b88c Merge remote-tracking branch 'upstream/master' 2015-05-17 21:54:30 +08:00
Lucas Rocha
03dfe7bb17 Implement (padding|border|margin)-(start|end) support 2015-05-14 17:43:33 +01:00
Christopher Chedeau
c3a2ddcce7 Merge pull request #84 from lukasreichart/master
If the measure function is defined: only return from execution of lay…
2015-05-14 08:48:04 -07:00
Nick Lockwood
9175721f07 Removed space before -- for consistency with code style. 2015-05-12 10:10:39 +01:00
Nick Lockwood
bf1d7eacfd Fixed spacing for wrapped elements 2015-05-12 09:54:02 +01:00
Lucas Rocha
36a46673f9 Support ROW_REVERSE, COLUMN_REVERSE and RTL direction 2015-05-11 11:24:21 +01:00
Lukas Reichart
fca176109d If the measure function is defined: only return from execution of layoutNode, when the node has no children. 2015-05-10 17:46:48 +02:00
Pierre Renaux
a91566d6db [src/Layout.c & Layout-test-utils.c]: Don't define fmaxf/fminf if we're building with VC12+, its already declared from then on ; 2015-05-10 00:20:29 +08:00
Pierre Renaux
09f0c12a8f [src/Layout.js]: Cleaner line loop in <Loop E> (alignContent layout) ; 2015-05-10 00:20:29 +08:00
Pierre Renaux
14e264f5be Made relevant JS tests transpile to C ; [src/Layout.c]: print_css_node_rec(): print alignContent ; [src/Layout-test-utils.c]: add_failed_test(): Sets failed_test->next to NULL, otherwise the test crashes if there's one and only one failure ; Added type casts so that it can be compiled as C++ by MSVC on Windows ; [Makefile]: Added c_test_msvc target when running in Windows so that the test executable can be built and debugged with Visual Studio on Windows ; 2015-05-10 00:20:28 +08:00
Pierre Renaux
c7fbf44474 'alignContent' defaults to 'flex-start' instead of 'stretch' ; 2015-05-10 00:19:30 +08:00
Pierre Renaux
cc5f772bff Style fixes ; 2015-05-10 00:19:29 +08:00
Pierre Renaux
998fa1d6ba [Issue facebook/css-layout#78]: Implemented alignContent ; 2015-05-10 00:19:27 +08:00
Christopher Chedeau
3203e86155 Merge pull request #70 from tadeuzagallo/remove-dead-code
Remove unused code pointed by Xcode
2015-05-05 08:10:04 -07:00
Pierre Renaux
ee5e8c1722 [Layout.c/h]: Minor modifications so that the Microsoft compiler can compile the file as C++ directly ; 2015-05-05 18:07:06 +08:00
Andrew Rasmussen
86c39b5e4f Revert "Ensure that flex children adopt their parent's cross-axis min dimension."
This reverts commit b8316413b3.

This was causing issues for existing components built with React
Native.. we need to investigate more in the future.
2015-05-01 12:16:47 -07:00
Andrew Rasmussen
5f52e947cb Fix layout for absolutely positioned nodes with absolutely positioned parents that have border and/or padding 2015-04-30 14:40:39 -07:00
Tadeu Zagallo
aad5efe938 Remove unused code pointed by Xcode 2015-04-24 16:45:49 +01:00
Russell Keith-Magee
b8316413b3 Ensure that flex children adopt their parent's cross-axis min dimension. 2015-04-07 10:52:15 +08:00
Russell Keith-Magee
2b6844f00a Simplified logic distributing flex space. 2015-03-31 18:58:56 +08:00
Russell Keith-Magee
c523b7c404 Added support for min/max width and height constraints. 2015-03-31 17:32:54 +08:00