passing height to the measure function
This diff: * adds height as another parameter passed to the measure function, computed the same way width is * adds tests for this extension, which has involved adding a new measure function to all of js, c, java and c# tests
This commit is contained in:
56
dist/css-layout.h
vendored
56
dist/css-layout.h
vendored
@@ -95,6 +95,7 @@ typedef struct {
|
||||
bool should_update;
|
||||
float last_requested_dimensions[2];
|
||||
float last_parent_max_width;
|
||||
float last_parent_max_height;
|
||||
float last_dimensions[2];
|
||||
float last_position[2];
|
||||
css_direction_t last_direction;
|
||||
@@ -143,7 +144,7 @@ struct css_node {
|
||||
css_node_t* next_absolute_child;
|
||||
css_node_t* next_flex_child;
|
||||
|
||||
css_dim_t (*measure)(void *context, float width);
|
||||
css_dim_t (*measure)(void *context, float width, float height);
|
||||
void (*print)(void *context);
|
||||
struct css_node* (*get_child)(void *context, int i);
|
||||
bool (*is_dirty)(void *context);
|
||||
@@ -165,7 +166,7 @@ typedef enum {
|
||||
void print_css_node(css_node_t *node, css_print_options_t options);
|
||||
|
||||
// Function that computes the layout!
|
||||
void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection);
|
||||
void layoutNode(css_node_t *node, float maxWidth, float maxHeight, css_direction_t parentDirection);
|
||||
bool isUndefined(float value);
|
||||
|
||||
#endif
|
||||
@@ -249,6 +250,7 @@ void init_css_node(css_node_t *node) {
|
||||
node->layout.last_requested_dimensions[CSS_WIDTH] = -1;
|
||||
node->layout.last_requested_dimensions[CSS_HEIGHT] = -1;
|
||||
node->layout.last_parent_max_width = -1;
|
||||
node->layout.last_parent_max_height = -1;
|
||||
node->layout.last_direction = (css_direction_t)-1;
|
||||
node->layout.should_update = true;
|
||||
}
|
||||
@@ -689,7 +691,7 @@ static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) {
|
||||
return -getPosition(node, trailing[axis]);
|
||||
}
|
||||
|
||||
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
|
||||
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
|
||||
/** START_GENERATED **/
|
||||
css_direction_t direction = resolveDirection(node, parentDirection);
|
||||
css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction);
|
||||
@@ -718,6 +720,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
// invocations during the layout calculation.
|
||||
int childCount = node->children_count;
|
||||
float paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
|
||||
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
||||
|
||||
if (isMeasureDefined(node)) {
|
||||
bool isResolvedRowDimDefined = !isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]);
|
||||
@@ -733,6 +736,17 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
}
|
||||
width -= paddingAndBorderAxisResolvedRow;
|
||||
|
||||
float height = CSS_UNDEFINED;
|
||||
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
height = node->style.dimensions[CSS_HEIGHT];
|
||||
} else if (!isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
|
||||
height = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
|
||||
} else {
|
||||
height = parentMaxHeight -
|
||||
getMarginAxis(node, resolvedRowAxis);
|
||||
}
|
||||
height -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
||||
|
||||
// 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
|
||||
// the element is flexible.
|
||||
@@ -745,7 +759,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
css_dim_t measureDim = node->measure(
|
||||
node->context,
|
||||
|
||||
width
|
||||
width,
|
||||
height
|
||||
);
|
||||
if (isRowUndefined) {
|
||||
node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] +
|
||||
@@ -753,7 +768,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
}
|
||||
if (isColumnUndefined) {
|
||||
node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] +
|
||||
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
||||
paddingAndBorderAxisColumn;
|
||||
}
|
||||
}
|
||||
if (childCount == 0) {
|
||||
@@ -834,6 +849,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
float crossDim = 0;
|
||||
|
||||
float maxWidth;
|
||||
float maxHeight;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node->get_child(node->context, i);
|
||||
child->line_index = linesCount;
|
||||
@@ -914,6 +930,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
|
||||
} else {
|
||||
maxWidth = CSS_UNDEFINED;
|
||||
maxHeight = CSS_UNDEFINED;
|
||||
|
||||
if (!isMainRowDirection) {
|
||||
if (isDimDefined(node, resolvedRowAxis)) {
|
||||
maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] -
|
||||
@@ -923,11 +941,20 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
getMarginAxis(node, resolvedRowAxis) -
|
||||
paddingAndBorderAxisResolvedRow;
|
||||
}
|
||||
} else {
|
||||
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
|
||||
paddingAndBorderAxisColumn;
|
||||
} else {
|
||||
maxHeight = parentMaxHeight -
|
||||
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
|
||||
paddingAndBorderAxisColumn;
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main recursive call. We layout non flexible children.
|
||||
if (alreadyComputedNextLayout == 0) {
|
||||
layoutNode(child, maxWidth, direction);
|
||||
layoutNode(child, maxWidth, maxHeight, direction);
|
||||
}
|
||||
|
||||
// Absolute positioned elements do not take part of the layout, so we
|
||||
@@ -1057,9 +1084,18 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
getMarginAxis(node, resolvedRowAxis) -
|
||||
paddingAndBorderAxisResolvedRow;
|
||||
}
|
||||
maxHeight = CSS_UNDEFINED;
|
||||
if (isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN)) {
|
||||
maxHeight = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] -
|
||||
paddingAndBorderAxisColumn;
|
||||
} else if (isMainRowDirection) {
|
||||
maxHeight = parentMaxHeight -
|
||||
getMarginAxis(node, CSS_FLEX_DIRECTION_COLUMN) -
|
||||
paddingAndBorderAxisColumn;
|
||||
}
|
||||
|
||||
// And we recursively call the layout algorithm for this child
|
||||
layoutNode(currentFlexChild, maxWidth, direction);
|
||||
layoutNode(currentFlexChild, maxWidth, maxHeight, direction);
|
||||
|
||||
child = currentFlexChild;
|
||||
currentFlexChild = currentFlexChild->next_flex_child;
|
||||
@@ -1378,7 +1414,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
/** END_GENERATED **/
|
||||
}
|
||||
|
||||
void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) {
|
||||
void layoutNode(css_node_t *node, float parentMaxWidth, float parentMaxHeight, css_direction_t parentDirection) {
|
||||
css_layout_t *layout = &node->layout;
|
||||
css_direction_t direction = node->style.direction;
|
||||
layout->should_update = true;
|
||||
@@ -1388,6 +1424,7 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
|
||||
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_direction, direction);
|
||||
|
||||
if (skipLayout) {
|
||||
@@ -1399,9 +1436,10 @@ void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDi
|
||||
layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
|
||||
layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];
|
||||
layout->last_parent_max_width = parentMaxWidth;
|
||||
layout->last_parent_max_height = parentMaxHeight;
|
||||
layout->last_direction = direction;
|
||||
|
||||
layoutNodeImpl(node, parentMaxWidth, parentDirection);
|
||||
layoutNodeImpl(node, parentMaxWidth, parentMaxHeight, parentDirection);
|
||||
|
||||
layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH];
|
||||
layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT];
|
||||
|
Reference in New Issue
Block a user