From c06f48c45ff874b9e4da7f177dd0435588424649 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 26 Apr 2014 12:16:27 -0700 Subject: [PATCH] initial support for text layout --- src/Layout-test-utils.js | 7 ++++++- src/Layout.c | 2 -- src/Layout.h | 1 + src/Layout.js | 6 ++++++ src/__tests__/Layout-test.js | 9 ++++++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Layout-test-utils.js b/src/Layout-test-utils.js index 100d5b57..c9c7ce6d 100644 --- a/src/Layout-test-utils.js +++ b/src/Layout-test-utils.js @@ -65,6 +65,9 @@ var layoutTestUtils = (function() { (node.children || []).forEach(function(child) { renderNode(div, child); }); + if (node.style.text) { + div.innerText = node.style.text; + } return div; } @@ -81,7 +84,9 @@ var layoutTestUtils = (function() { var children = []; for (var child = div.firstChild; child; child = child.nextSibling) { - children.push(buildLayout(rect, child)); + if (child.nodeType !== 3 /* textNode */) { + children.push(buildLayout(rect, child)); + } } if (children.length) { result.children = children; diff --git a/src/Layout.c b/src/Layout.c index 35059c71..aae1e713 100644 --- a/src/Layout.c +++ b/src/Layout.c @@ -7,8 +7,6 @@ #include "Layout.h" -#define CSS_UNDEFINED NAN - void init_css_node(css_node_t *node) { node->style.align_items = CSS_ALIGN_FLEX_START; diff --git a/src/Layout.h b/src/Layout.h index c96b3c23..4c42c083 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -1,6 +1,7 @@ #ifndef __LAYOUT_H #define __LAYOUT_H +#define CSS_UNDEFINED NAN typedef enum { CSS_FLEX_DIRECTION_COLUMN = 0, diff --git a/src/Layout.js b/src/Layout.js index 45f88464..23db16a8 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -231,6 +231,11 @@ var computeLayout = (function() { node.layout[leading[crossAxis]] += getMargin(node, leading[crossAxis]) + getRelativePosition(node, crossAxis); + if ('text' in node.style) { + node.layout.width = 36; + node.layout.height = 18; + return; + } // Layout non flexible children and count children by type @@ -272,6 +277,7 @@ var computeLayout = (function() { } } + // Layout flexible children and allocate empty space // In order to position the elements in the main axis, we have two diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 2a8ed965..a363f6b0 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -744,6 +744,13 @@ describe('Layout', function() { ) }); + it('should layout node with text', function() { + testLayout( + {style: {text: 'kikoo'}}, + {width: 36, height: 18, top: 0, left: 0} + ) + }); + it('should layout randomly', function() { @@ -806,7 +813,7 @@ describe('Layout', function() { return node; } - for (var i = 0; i < 1000; ++i) { + for (var i = 0; i < 100; ++i) { var node = generateRandomNode(); if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { node = reduceTest(node);