Skip to content

Commit

Permalink
fix(ui): correct width calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Oct 7, 2024
1 parent 958fc38 commit 3395ec0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/css/src/computed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,10 @@ static void compute_absolute_width(const css_computed_style_t *parent,
s->type_bits.width = CSS_WIDTH_FIT_CONTENT;
break;
}
if (compute_content_box_fixed_width(parent, &parent_value)) {
// 当父元素是块级元素且 display 为 block 时,width 为父元素的
// content box 的宽度
if (is_css_display_block(parent) &&
compute_content_box_fixed_width(parent, &parent_value)) {
value = parent_value - s->margin_left - s->margin_right;
if (s->type_bits.box_sizing ==
CSS_BOX_SIZING_CONTENT_BOX) {
Expand Down Expand Up @@ -1147,8 +1150,7 @@ static void compute_absolute_height(const css_computed_style_t *parent,
if (css_computed_position(s) > CSS_POSITION_RELATIVE) {
parent_value += css_padding_y(parent);
}
CSS_SET_FIXED_LENGTH(s, height,
parent_value * value / 100.0f);
CSS_SET_FIXED_LENGTH(s, height, parent_value * value / 100.0f);
break;
default:
break;
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/src/ui_flexbox_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ static void ui_flexbox_layout_update_row(ui_flexbox_layout_context_t *ctx)

// 根据 justify-content 和 align-items,更新每个项目的位置和尺寸
ui_flexbox_layout_compute_justify_content(ctx, &main_axis, &space);
#ifdef UI_DEBUG_ENABLED
{
UI_WIDGET_STR(ctx->widget, str);
UI_DEBUG_MSG("%s: main_axis_start = %g, free_space = %g, justify_content = %d",
str, main_axis, space, ctx->widget->computed_style.type_bits.justify_content);
}
#endif
for (list_each(node, &ctx->line->items)) {
main_axis += space;
child = node->data;
Expand Down

0 comments on commit 3395ec0

Please sign in to comment.