initial support for text layout
This commit is contained in:
@@ -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,8 +84,10 @@ var layoutTestUtils = (function() {
|
||||
|
||||
var children = [];
|
||||
for (var child = div.firstChild; child; child = child.nextSibling) {
|
||||
if (child.nodeType !== 3 /* textNode */) {
|
||||
children.push(buildLayout(rect, child));
|
||||
}
|
||||
}
|
||||
if (children.length) {
|
||||
result.children = children;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#ifndef __LAYOUT_H
|
||||
#define __LAYOUT_H
|
||||
|
||||
#define CSS_UNDEFINED NAN
|
||||
|
||||
typedef enum {
|
||||
CSS_FLEX_DIRECTION_COLUMN = 0,
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user