Merge pull request #14 from vjeux/default_stretch

Make align-items: stretch the default
This commit is contained in:
Andy Street
2014-10-08 09:55:12 -07:00
8 changed files with 40 additions and 20 deletions

View File

@@ -61,8 +61,7 @@ div, span {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-self: stretch; align-items: stretch;
align-items: flex-start;
justify-content: flex-start; justify-content: flex-start;
flex-shrink: 0; flex-shrink: 0;
} }

View File

@@ -21,8 +21,8 @@ var layoutTestUtils = (function() {
display: -webkit-flex; display: -webkit-flex;
flex-direction: column; flex-direction: column;
-webkit-flex-direction: column; -webkit-flex-direction: column;
align-items: flex-start; align-items: stretch;
-webkit-align-items: flex-start; -webkit-align-items: stretch;
justify-content: flex-start; justify-content: flex-start;
-webkit-justify-content: flex-start; -webkit-justify-content: flex-start;
flex-shrink: 0; flex-shrink: 0;
@@ -72,6 +72,7 @@ var layoutTestUtils = (function() {
} }
fillNodes(rootNode); fillNodes(rootNode);
rootNode.style.alignSelf = 'flex-start';
realComputeLayout(rootNode); realComputeLayout(rootNode);
return extractNodes(rootNode); return extractNodes(rootNode);
} }

View File

@@ -18,7 +18,7 @@ static bool eq(float a, float b) {
} }
void init_css_node(css_node_t *node) { void init_css_node(css_node_t *node) {
node->style.align_items = CSS_ALIGN_FLEX_START; node->style.align_items = CSS_ALIGN_STRETCH;
// Some of the fields default to undefined and not 0 // Some of the fields default to undefined and not 0
node->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED; node->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED;

View File

@@ -76,7 +76,7 @@ var computeLayout = (function() {
if ('alignItems' in node.style) { if ('alignItems' in node.style) {
return node.style.alignItems; return node.style.alignItems;
} }
return 'flex-start'; return 'stretch';
} }
function getFlexDirection(node) { function getFlexDirection(node) {

View File

@@ -2729,11 +2729,13 @@ int main()
css_node_t *root_node = new_test_css_node(); css_node_t *root_node = new_test_css_node();
{ {
css_node_t *node_0 = root_node; css_node_t *node_0 = root_node;
node_0->style.align_self = CSS_ALIGN_FLEX_START;
node_0->style.dimensions[CSS_WIDTH] = 100; node_0->style.dimensions[CSS_WIDTH] = 100;
init_css_node_children(node_0, 1); init_css_node_children(node_0, 1);
{ {
css_node_t *node_1; css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0); node_1 = node_0->get_child(node_0->context, 0);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1->measure = measure; node_1->measure = measure;
node_1->context = "loooooooooong with space"; node_1->context = "loooooooooong with space";
} }
@@ -2764,6 +2766,7 @@ int main()
css_node_t *root_node = new_test_css_node(); css_node_t *root_node = new_test_css_node();
{ {
css_node_t *node_0 = root_node; css_node_t *node_0 = root_node;
node_0->style.align_self = CSS_ALIGN_FLEX_START;
node_0->style.dimensions[CSS_WIDTH] = 100; node_0->style.dimensions[CSS_WIDTH] = 100;
node_0->style.padding[CSS_LEFT] = 10; node_0->style.padding[CSS_LEFT] = 10;
node_0->style.padding[CSS_TOP] = 10; node_0->style.padding[CSS_TOP] = 10;
@@ -2773,6 +2776,7 @@ int main()
{ {
css_node_t *node_1; css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0); node_1 = node_0->get_child(node_0->context, 0);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1->style.margin[CSS_LEFT] = 10; node_1->style.margin[CSS_LEFT] = 10;
node_1->style.margin[CSS_TOP] = 10; node_1->style.margin[CSS_TOP] = 10;
node_1->style.margin[CSS_RIGHT] = 10; node_1->style.margin[CSS_RIGHT] = 10;
@@ -3044,14 +3048,17 @@ int main()
css_node_t *root_node = new_test_css_node(); css_node_t *root_node = new_test_css_node();
{ {
css_node_t *node_0 = root_node; css_node_t *node_0 = root_node;
node_0->style.align_self = CSS_ALIGN_FLEX_START;
node_0->style.dimensions[CSS_WIDTH] = 100; node_0->style.dimensions[CSS_WIDTH] = 100;
node_0->style.dimensions[CSS_HEIGHT] = 100; node_0->style.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_0, 2); init_css_node_children(node_0, 2);
{ {
css_node_t *node_1; css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0); node_1 = node_0->get_child(node_0->context, 0);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1->style.flex = 2.5; node_1->style.flex = 2.5;
node_1 = node_0->get_child(node_0->context, 1); node_1 = node_0->get_child(node_0->context, 1);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1->style.flex = 7.5; node_1->style.flex = 7.5;
} }
} }
@@ -3086,13 +3093,16 @@ int main()
css_node_t *root_node = new_test_css_node(); css_node_t *root_node = new_test_css_node();
{ {
css_node_t *node_0 = root_node; css_node_t *node_0 = root_node;
node_0->style.align_self = CSS_ALIGN_FLEX_START;
node_0->style.dimensions[CSS_WIDTH] = 100; node_0->style.dimensions[CSS_WIDTH] = 100;
node_0->style.dimensions[CSS_HEIGHT] = 100; node_0->style.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_0, 2); init_css_node_children(node_0, 2);
{ {
css_node_t *node_1; css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0); node_1 = node_0->get_child(node_0->context, 0);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1 = node_0->get_child(node_0->context, 1); node_1 = node_0->get_child(node_0->context, 1);
node_1->style.align_self = CSS_ALIGN_FLEX_START;
node_1->style.flex = 0; node_1->style.flex = 0;
} }
} }

View File

@@ -827,8 +827,8 @@ describe('Layout', function() {
it('should layout node with text bounded by parent', function() { it('should layout node with text bounded by parent', function() {
testLayout( testLayout(
{style: {width: 100}, children: [ {style: {width: 100, alignSelf: 'flex-start'}, children: [
{style: {measure: text(texts.big)}} {style: {measure: text(texts.big), alignSelf: 'flex-start'}}
]}, ]},
{width: 100, height: textSizes.bigHeight, top: 0, left: 0, children: [ {width: 100, height: textSizes.bigHeight, top: 0, left: 0, children: [
{width: textSizes.bigMinWidth, height: textSizes.bigHeight, top: 0, left: 0} {width: textSizes.bigMinWidth, height: textSizes.bigHeight, top: 0, left: 0}
@@ -838,8 +838,8 @@ describe('Layout', function() {
it('should layout node with text bounded by grand-parent', function() { it('should layout node with text bounded by grand-parent', function() {
testLayout( testLayout(
{style: {width: 100, padding: 10}, children: [ {style: {width: 100, padding: 10, alignSelf: 'flex-start'}, children: [
{style: {margin: 10}, children: [ {style: {margin: 10, alignSelf: 'flex-start'}, children: [
{style: {measure: text(texts.big)}} {style: {measure: text(texts.big)}}
]} ]}
]}, ]},
@@ -918,9 +918,9 @@ describe('Layout', function() {
it('should layout with arbitrary flex', function() { it('should layout with arbitrary flex', function() {
testLayout( testLayout(
{style: {width: 100, height: 100}, children: [ {style: {width: 100, height: 100, alignSelf: 'flex-start'}, children: [
{style: {flex: 2.5}}, {style: {flex: 2.5, alignSelf: 'flex-start'}},
{style: {flex: 7.5}} {style: {flex: 7.5, alignSelf: 'flex-start'}}
]}, ]},
{width: 100, height: 100, top: 0, left: 0, children: [ {width: 100, height: 100, top: 0, left: 0, children: [
{width: 0, height: 25, top: 0, left: 0}, {width: 0, height: 25, top: 0, left: 0},
@@ -931,9 +931,9 @@ describe('Layout', function() {
it('should layout with negative flex', function() { it('should layout with negative flex', function() {
testLayout( testLayout(
{style: {width: 100, height: 100}, children: [ {style: {width: 100, height: 100, alignSelf: 'flex-start'}, children: [
{style: {flex: -2.5}}, {style: {flex: -2.5, alignSelf: 'flex-start'}},
{style: {flex: 0}} {style: {flex: 0, alignSelf: 'flex-start'}}
]}, ]},
{width: 100, height: 100, top: 0, left: 0, children: [ {width: 100, height: 100, top: 0, left: 0, children: [
{width: 0, height: 0, top: 0, left: 0}, {width: 0, height: 0, top: 0, left: 0},

View File

@@ -7,7 +7,7 @@ public class CSSStyle {
public CSSFlexDirection flexDirection = CSSFlexDirection.COLUMN; public CSSFlexDirection flexDirection = CSSFlexDirection.COLUMN;
public CSSJustify justifyContent = CSSJustify.FLEX_START; public CSSJustify justifyContent = CSSJustify.FLEX_START;
public CSSAlign alignItems = CSSAlign.FLEX_START; public CSSAlign alignItems = CSSAlign.STRETCH;
public CSSAlign alignSelf = CSSAlign.AUTO; public CSSAlign alignSelf = CSSAlign.AUTO;
public CSSPositionType positionType = CSSPositionType.RELATIVE; public CSSPositionType positionType = CSSPositionType.RELATIVE;
public float flex; public float flex;

View File

@@ -2944,11 +2944,13 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode(); TestCSSNode root_node = new TestCSSNode();
{ {
TestCSSNode node_0 = root_node; TestCSSNode node_0 = root_node;
node_0.style.alignSelf = CSSAlign.FLEX_START;
node_0.style.width = 100; node_0.style.width = 100;
addChildren(node_0, 1); addChildren(node_0, 1);
{ {
TestCSSNode node_1; TestCSSNode node_1;
node_1 = node_0.getChildAt(0); node_1 = node_0.getChildAt(0);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1.setMeasureFunction(sTestMeasureFunction); node_1.setMeasureFunction(sTestMeasureFunction);
node_1.context = "loooooooooong with space"; node_1.context = "loooooooooong with space";
} }
@@ -2981,6 +2983,7 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode(); TestCSSNode root_node = new TestCSSNode();
{ {
TestCSSNode node_0 = root_node; TestCSSNode node_0 = root_node;
node_0.style.alignSelf = CSSAlign.FLEX_START;
node_0.style.width = 100; node_0.style.width = 100;
node_0.style.paddingLeft = 10; node_0.style.paddingLeft = 10;
node_0.style.paddingTop = 10; node_0.style.paddingTop = 10;
@@ -2990,6 +2993,7 @@ public class LayoutEngineTest {
{ {
TestCSSNode node_1; TestCSSNode node_1;
node_1 = node_0.getChildAt(0); node_1 = node_0.getChildAt(0);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1.style.marginLeft = 10; node_1.style.marginLeft = 10;
node_1.style.marginTop = 10; node_1.style.marginTop = 10;
node_1.style.marginRight = 10; node_1.style.marginRight = 10;
@@ -3273,14 +3277,17 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode(); TestCSSNode root_node = new TestCSSNode();
{ {
TestCSSNode node_0 = root_node; TestCSSNode node_0 = root_node;
node_0.style.alignSelf = CSSAlign.FLEX_START;
node_0.style.width = 100; node_0.style.width = 100;
node_0.style.height = 100; node_0.style.height = 100;
addChildren(node_0, 2); addChildren(node_0, 2);
{ {
TestCSSNode node_1; TestCSSNode node_1;
node_1 = node_0.getChildAt(0); node_1 = node_0.getChildAt(0);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1.style.flex = 2.5f; node_1.style.flex = 2.5f;
node_1 = node_0.getChildAt(1); node_1 = node_0.getChildAt(1);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1.style.flex = 7.5f; node_1.style.flex = 7.5f;
} }
} }
@@ -3317,13 +3324,16 @@ public class LayoutEngineTest {
TestCSSNode root_node = new TestCSSNode(); TestCSSNode root_node = new TestCSSNode();
{ {
TestCSSNode node_0 = root_node; TestCSSNode node_0 = root_node;
node_0.style.alignSelf = CSSAlign.FLEX_START;
node_0.style.width = 100; node_0.style.width = 100;
node_0.style.height = 100; node_0.style.height = 100;
addChildren(node_0, 2); addChildren(node_0, 2);
{ {
TestCSSNode node_1; TestCSSNode node_1;
node_1 = node_0.getChildAt(0); node_1 = node_0.getChildAt(0);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1 = node_0.getChildAt(1); node_1 = node_0.getChildAt(1);
node_1.style.alignSelf = CSSAlign.FLEX_START;
node_1.style.flex = 0; node_1.style.flex = 0;
} }
} }