initial support for text layout

This commit is contained in:
Christopher Chedeau
2014-04-26 12:16:27 -07:00
parent 6fdd724820
commit c06f48c45f
5 changed files with 21 additions and 4 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
#ifndef __LAYOUT_H
#define __LAYOUT_H
#define CSS_UNDEFINED NAN
typedef enum {
CSS_FLEX_DIRECTION_COLUMN = 0,

View File

@@ -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;
}
// <Loop A> Layout non flexible children and count children by type
@@ -272,6 +277,7 @@ var computeLayout = (function() {
}
}
// <Loop B> Layout flexible children and allocate empty space
// In order to position the elements in the main axis, we have two

View File

@@ -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);