Add support for measure mode
This commit is contained in:
30
dist/css-layout.h
vendored
30
dist/css-layout.h
vendored
@@ -80,6 +80,12 @@ typedef enum {
|
||||
CSS_POSITION_COUNT
|
||||
} css_position_t;
|
||||
|
||||
typedef enum {
|
||||
CSS_MEASURE_MODE_UNDEFINED = 0,
|
||||
CSS_MEASURE_MODE_EXACTLY,
|
||||
CSS_MEASURE_MODE_AT_MOST
|
||||
} css_measure_mode_t;
|
||||
|
||||
typedef enum {
|
||||
CSS_WIDTH = 0,
|
||||
CSS_HEIGHT
|
||||
@@ -144,7 +150,7 @@ struct css_node {
|
||||
css_node_t *next_absolute_child;
|
||||
css_node_t *next_flex_child;
|
||||
|
||||
css_dim_t (*measure)(void *context, float width, float height);
|
||||
css_dim_t (*measure)(void *context, float width, css_measure_mode_t widthMode, float height, css_measure_mode_t heightMode);
|
||||
void (*print)(void *context);
|
||||
struct css_node* (*get_child)(void *context, int i);
|
||||
bool (*is_dirty)(void *context);
|
||||
@@ -734,26 +740,40 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, float parentM
|
||||
bool isResolvedRowDimDefined = isLayoutDimDefined(node, resolvedRowAxis);
|
||||
|
||||
float width = CSS_UNDEFINED;
|
||||
css_measure_mode_t widthMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
if (isStyleDimDefined(node, resolvedRowAxis)) {
|
||||
width = node->style.dimensions[CSS_WIDTH];
|
||||
widthMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else if (isResolvedRowDimDefined) {
|
||||
width = node->layout.dimensions[dim[resolvedRowAxis]];
|
||||
widthMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else {
|
||||
width = parentMaxWidth -
|
||||
getMarginAxis(node, resolvedRowAxis);
|
||||
widthMode = CSS_MEASURE_MODE_AT_MOST;
|
||||
}
|
||||
width -= paddingAndBorderAxisResolvedRow;
|
||||
if (isUndefined(width)) {
|
||||
widthMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
}
|
||||
|
||||
float height = CSS_UNDEFINED;
|
||||
css_measure_mode_t heightMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
if (isStyleDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
height = node->style.dimensions[CSS_HEIGHT];
|
||||
heightMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else if (isLayoutDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
height = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
|
||||
heightMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else {
|
||||
height = parentMaxHeight -
|
||||
getMarginAxis(node, resolvedRowAxis);
|
||||
heightMode = CSS_MEASURE_MODE_AT_MOST;
|
||||
}
|
||||
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
||||
if (isUndefined(height)) {
|
||||
heightMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
}
|
||||
|
||||
// We only need to give a dimension for the text if we haven't got any
|
||||
// for it computed yet. It can either be from the style attribute or because
|
||||
@@ -768,7 +788,9 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, float parentM
|
||||
node->context,
|
||||
|
||||
width,
|
||||
height
|
||||
widthMode,
|
||||
height,
|
||||
heightMode
|
||||
);
|
||||
if (isRowUndefined) {
|
||||
node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] +
|
||||
@@ -1447,8 +1469,8 @@ void layoutNode(css_node_t *node, float parentMaxWidth, float parentMaxHeight, c
|
||||
!node->is_dirty(node->context) &&
|
||||
eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) &&
|
||||
eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) &&
|
||||
eq(layout->last_parent_max_width, parentMaxWidth);
|
||||
eq(layout->last_parent_max_height, parentMaxHeight);
|
||||
eq(layout->last_parent_max_width, parentMaxWidth) &&
|
||||
eq(layout->last_parent_max_height, parentMaxHeight) &&
|
||||
eq(layout->last_direction, direction);
|
||||
|
||||
if (skipLayout) {
|
||||
|
BIN
dist/css-layout.jar
vendored
BIN
dist/css-layout.jar
vendored
Binary file not shown.
24
dist/css-layout.js
vendored
24
dist/css-layout.js
vendored
@@ -53,6 +53,10 @@ var computeLayout = (function() {
|
||||
var CSS_POSITION_RELATIVE = 'relative';
|
||||
var CSS_POSITION_ABSOLUTE = 'absolute';
|
||||
|
||||
var CSS_MEASURE_MODE_UNDEFINED = 'undefined';
|
||||
var CSS_MEASURE_MODE_EXACTLY = 'exactly';
|
||||
var CSS_MEASURE_MODE_AT_MOST = 'at-most';
|
||||
|
||||
var leading = {
|
||||
'row': 'left',
|
||||
'row-reverse': 'right',
|
||||
@@ -110,7 +114,7 @@ var computeLayout = (function() {
|
||||
}
|
||||
|
||||
function isUndefined(value) {
|
||||
return value === undefined;
|
||||
return value === undefined || isNaN(value);
|
||||
}
|
||||
|
||||
function isRowDirection(flexDirection) {
|
||||
@@ -501,26 +505,40 @@ var computeLayout = (function() {
|
||||
var/*bool*/ isResolvedRowDimDefined = isLayoutDimDefined(node, resolvedRowAxis);
|
||||
|
||||
var/*float*/ width = CSS_UNDEFINED;
|
||||
var/*css_measure_mode_t*/ widthMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
if (isStyleDimDefined(node, resolvedRowAxis)) {
|
||||
width = node.style.width;
|
||||
widthMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else if (isResolvedRowDimDefined) {
|
||||
width = node.layout[dim[resolvedRowAxis]];
|
||||
widthMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else {
|
||||
width = parentMaxWidth -
|
||||
getMarginAxis(node, resolvedRowAxis);
|
||||
widthMode = CSS_MEASURE_MODE_AT_MOST;
|
||||
}
|
||||
width -= paddingAndBorderAxisResolvedRow;
|
||||
if (isUndefined(width)) {
|
||||
widthMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
}
|
||||
|
||||
var/*float*/ height = CSS_UNDEFINED;
|
||||
var/*css_measure_mode_t*/ heightMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
if (isStyleDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
height = node.style.height;
|
||||
heightMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else if (isLayoutDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
height = node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]];
|
||||
heightMode = CSS_MEASURE_MODE_EXACTLY;
|
||||
} else {
|
||||
height = parentMaxHeight -
|
||||
getMarginAxis(node, resolvedRowAxis);
|
||||
heightMode = CSS_MEASURE_MODE_AT_MOST;
|
||||
}
|
||||
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
||||
if (isUndefined(height)) {
|
||||
heightMode = CSS_MEASURE_MODE_UNDEFINED;
|
||||
}
|
||||
|
||||
// We only need to give a dimension for the text if we haven't got any
|
||||
// for it computed yet. It can either be from the style attribute or because
|
||||
@@ -535,7 +553,9 @@ var computeLayout = (function() {
|
||||
/*(c)!node->context,*/
|
||||
/*(java)!layoutContext.measureOutput,*/
|
||||
width,
|
||||
height
|
||||
widthMode,
|
||||
height,
|
||||
heightMode
|
||||
);
|
||||
if (isRowUndefined) {
|
||||
node.layout.width = measureDim.width +
|
||||
|
2
dist/css-layout.min.js
vendored
2
dist/css-layout.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/css-layout.min.js.map
vendored
2
dist/css-layout.min.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user