Skip to content

Commit

Permalink
fixup! fixup! feat: new layout process
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Dec 22, 2024
1 parent 7bb4389 commit 2c1bdbb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/css/src/computed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ static void compute_absolute_height(const css_computed_style_t *parent,
break;
}
if (is_css_display_inline(s) || !parent) {
s->type_bits.height = CSS_WIDTH_FIT_CONTENT;
s->type_bits.height = CSS_HEIGHT_FIT_CONTENT;
}
break;
case CSS_HEIGHT_SET:
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/src/ui_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void ui_widget_min_size_to_string(ui_widget_t *w, char str[40])
char height_str[16] = "auto";

switch (w->computed_style.type_bits.min_width) {
case CSS_WIDTH_FIT_CONTENT:
strcpy(width_str, "fit-content");
case CSS_MIN_WIDTH_MIN_CONTENT:
strcpy(width_str, "min-content");
break;
case CSS_WIDTH_SET:
snprintf(width_str, 16, "%g%s", w->computed_style.min_width,
Expand Down
11 changes: 8 additions & 3 deletions lib/ui/src/ui_flexbox_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ static float ui_compute_row_item_layout(ui_widget_t *item, float x, float y,
ui_widget_update_box_position(item);
return 0;
}
if (align == CSS_ALIGN_ITEMS_STRETCH &&
if (IS_CSS_PERCENTAGE(&item->specified_style, height)) {
ui_widget_reset_height(item);
} else if (align == CSS_ALIGN_ITEMS_STRETCH &&
item->specified_style.type_bits.height == CSS_HEIGHT_AUTO) {
CSS_SET_FIXED_LENGTH(
s, height,
Expand Down Expand Up @@ -771,7 +773,9 @@ static float ui_compute_column_item_layout(ui_widget_t *item, float x, float y,
ui_widget_update_box_position(item);
return 0;
}
if (align == CSS_ALIGN_ITEMS_STRETCH &&
if (IS_CSS_PERCENTAGE(&item->specified_style, width)) {
ui_widget_reset_width(item);
} else if (align == CSS_ALIGN_ITEMS_STRETCH &&
item->specified_style.type_bits.width == CSS_WIDTH_AUTO) {
CSS_SET_FIXED_LENGTH(
s, width,
Expand Down Expand Up @@ -921,7 +925,8 @@ void ui_flexbox_layout_reflow(ui_widget_t *w, ui_resizer_t *resizer)
{
UI_WIDGET_STR(w, str);
UI_WIDGET_SIZE_STR(w, size_str);
UI_DEBUG_MSG("%s: %s: begin, direction=%s, size=%s, content_size=(%g, %g)",
UI_DEBUG_MSG("%s: %s: begin, direction=%s, size=%s, "
"content_size=(%g, %g)",
__FUNCTION__, str,
ctx.column_direction ? "column" : "row", size_str,
w->content_box.width, w->content_box.height);
Expand Down
22 changes: 10 additions & 12 deletions lib/ui/src/ui_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static void ui_widget_reset_size(ui_widget_t *w)
static void ui_widget_update_size(ui_widget_t *w)
{
ui_resizer_t resizer;
int width = (int)(w->outer_box.width * 64.f);
int height = (int)(w->outer_box.height * 64.f);

ui_widget_reset_size(w);
ui_widget_compute_style(w);
Expand All @@ -347,6 +349,14 @@ static void ui_widget_update_size(ui_widget_t *w)
w->min_content_width = resizer.min_main_size;
w->min_content_height = resizer.min_cross_size;
}
if (w->parent && ui_widget_in_layout_flow(w)) {
if (width != (int)(w->outer_box.width * 64.f) ||
height != (int)(w->outer_box.height * 64.f)) {
ui_widget_request_reflow(w->parent);
}
} else {
ui_widget_update_box_position(w);
}
}

size_t ui_updater_update_widget(ui_updater_t *updater, ui_widget_t *w)
Expand Down Expand Up @@ -428,19 +438,7 @@ size_t ui_updater_update_widget(ui_updater_t *updater, ui_widget_t *w)
count += ui_updater_update_children(updater, w);
}
if (w->update.should_reflow) {
int width = (int)(w->outer_box.width * 64.f);
int height = (int)(w->outer_box.height * 64.f);

ui_widget_update_size(w);

if (w->parent && ui_widget_in_layout_flow(w)) {
if (width != (int)(w->outer_box.width * 64.f) ||
height != (int)(w->outer_box.height * 64.f)) {
ui_widget_request_reflow(w->parent);
}
} else {
ui_widget_update_box_position(w);
}
}
ui_widget_update_stacking_context(w);
#ifdef UI_DEBUG_ENABLED
Expand Down
6 changes: 4 additions & 2 deletions tests/cases/test_block_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <LCUI.h>
#include <ctest-custom.h>

#define SCROLLBAR_WIDTH 14

static void test_dropdown(void)
{
ui_widget_t *w;
Expand Down Expand Up @@ -503,7 +505,7 @@ static void test_block_layout_600(void)

rect.x = 10;
rect.y = 10;
rect.width = 600 - 20 - 14;
rect.width = 600 - 20 - SCROLLBAR_WIDTH;
rect.height = 504;
w = ui_widget_get_child(container, 0);
ctest_equal_ui_rect("$('.example')[0].border_box", &w->border_box,
Expand Down Expand Up @@ -695,7 +697,7 @@ static void test_block_layout_320(void)

rect.x = 10;
rect.y = 10;
rect.width = 320 - 20 - 14;
rect.width = 320 - 20 - SCROLLBAR_WIDTH;
rect.height = 604;
w = ui_widget_get_child(container, 0);
ctest_equal_ui_rect("$('.example')[0].border_box", &w->border_box,
Expand Down
6 changes: 4 additions & 2 deletions tests/cases/test_flex_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <LCUI.h>
#include <ctest-custom.h>

#define SCROLLBAR_WIDTH 14

static void test_flex_layout_with_content_width(float width)
{
float content_width = width - 22;
Expand Down Expand Up @@ -486,12 +488,12 @@ static void test_flex_layout_1280(void)
static void test_flex_layout_600(void)
{
ui_widget_resize(ui_root(), 600, 400);
test_flex_layout_with_content_width(580 - 14);
test_flex_layout_with_content_width(580 - SCROLLBAR_WIDTH);
}

static void test_flex_layout_320(void)
{
float width = 320 - 10 - 10 - 14;
float width = 320 - 10 - 10 - SCROLLBAR_WIDTH;
float content_width = width - 12 - 10;

ui_widget_t *w;
Expand Down

0 comments on commit 2c1bdbb

Please sign in to comment.