diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-10-31 16:08:26 +0000 |
---|---|---|
committer | Michael Drake <mdrake.unique@gmail.com> | 2022-11-02 20:16:41 +0000 |
commit | d0b1bcb01a549a885007862112aeaa8b09ddf40d (patch) | |
tree | 7e146a05197feac5312dc38dbf50b68cfee08d9d | |
parent | 6c2f9f32853c6359516f643ce8f2b4fad968e058 (diff) | |
download | netsurf-d0b1bcb01a549a885007862112aeaa8b09ddf40d.tar.gz netsurf-d0b1bcb01a549a885007862112aeaa8b09ddf40d.tar.bz2 |
html: layout: flex: Unify line item placement
-rw-r--r-- | content/handlers/html/layout_flex.c | 103 |
1 files changed, 43 insertions, 60 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c index 07c3b5b89..6731e79bd 100644 --- a/content/handlers/html/layout_flex.c +++ b/content/handlers/html/layout_flex.c @@ -174,6 +174,10 @@ static bool layout_flex_item( break; } + if (!success) { + NSLOG(flex, ERROR, "box %p: layout failed", b); + } + return success; } @@ -215,7 +219,6 @@ static inline bool layout_flex__base_and_main_sizes( } if (!layout_flex_item(ctx, item, b->width)) { - NSLOG(flex, WARNING, "box %p: layout failed", b); return false; } } @@ -545,77 +548,64 @@ static inline void layout_flex__distribute_free_space( } } -static bool layout_flex__resolve_line_horizontal( +static bool layout_flex__resolve_line_item_positions( struct flex_ctx *ctx, struct flex_line_data *line, int available_width) { + enum box_side cross_start = ctx->horizontal ? TOP : LEFT; + enum box_side main_start = ctx->horizontal ? LEFT : TOP; size_t item_count = line->first + line->count; - int x = ctx->flex->padding[LEFT]; + int main_pos = ctx->flex->padding[main_start]; for (size_t i = line->first; i < item_count; i++) { struct flex_item_data *item = &ctx->item.data[i]; struct box *b = item->box; - bool success = false; - - b->width = item->target_main_size - lh__delta_outer_width(b); - - success = layout_flex_item(ctx, item, b->width); - if (!success) { - NSLOG(flex, WARNING, "box %p: layout failed", b); - return false; - } - - b->y = ctx->flex->padding[TOP] + ctx->cross_size + - lh__non_auto_margin(b, TOP) + - b->border[TOP].width; + int *box_pos_cross; + int *box_pos_main; - b->x = x + lh__non_auto_margin(b, LEFT) + - b->border[LEFT].width; + if (ctx->horizontal) { + bool success; - if (lh__box_is_absolute(b) == false) { - int height; + b->width = item->target_main_size - + lh__delta_outer_width(b); - height = b->height + lh__delta_outer_height(b); - if (line->cross_size < height) { - line->cross_size = height; + success = layout_flex_item(ctx, item, b->width); + if (!success) { + return false; } - x += b->width + lh__delta_outer_width(b); + box_pos_main = &b->x; + box_pos_cross = &b->y; + } else { + box_pos_main = &b->y; + box_pos_cross = &b->x; } - } - return true; -} + *box_pos_cross = ctx->flex->padding[cross_start] + + ctx->cross_size + + lh__non_auto_margin(b, cross_start) + + b->border[cross_start].width; -static bool layout_flex__resolve_line_vertical( - struct flex_ctx *ctx, - struct flex_line_data *line, - int available_width) -{ - size_t item_count = line->first + line->count; - int y = ctx->flex->padding[TOP]; - - for (size_t i = line->first; i < item_count; i++) { - struct flex_item_data *item = &ctx->item.data[i]; - struct box *b = item->box; - - b->x = ctx->flex->padding[LEFT] + ctx->cross_size + - lh__non_auto_margin(b, LEFT) + - b->border[LEFT].width; + *box_pos_main = main_pos + lh__non_auto_margin(b, main_start) + + b->border[main_start].width; - b->y = y + lh__non_auto_margin(b, TOP) + - b->border[TOP].width; + if (!lh__box_is_absolute(b)) { + int cross_size; + int *box_size_main; + int *box_size_cross; - if (lh__box_is_absolute(b) == false) { - int width; + box_size_main = lh__box_size_main(ctx->horizontal, b); + box_size_cross = lh__box_size_cross(ctx->horizontal, b); - width = b->width + lh__delta_outer_width(b); - if (line->cross_size < width) { - line->cross_size = width; + cross_size = *box_size_cross + lh__delta_outer_cross( + ctx->flex, b); + if (line->cross_size < cross_size) { + line->cross_size = cross_size; } - y += b->height + lh__delta_outer_height(b); + main_pos += *box_size_main + lh__delta_outer_main( + ctx->flex, b); } } @@ -712,16 +702,9 @@ static bool layout_flex__resolve_line( } } - if (ctx->horizontal) { - if (!layout_flex__resolve_line_horizontal(ctx, - line, available_width)) { - return false; - } - } else { - if (!layout_flex__resolve_line_vertical(ctx, - line, available_width)) { - return false; - } + if (!layout_flex__resolve_line_item_positions(ctx, line, + available_width)) { + return false; } return true; |