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) {
|
||||
|
Reference in New Issue
Block a user