fix(flex): don't count item gap for leading hidden items (#7720)
This commit is contained in:
committed by
GitHub
parent
b504294613
commit
b9e0c4daaf
@@ -254,6 +254,7 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id
|
||||
int32_t item_id = item_start_id;
|
||||
int32_t grow_min_size_sum = 0;
|
||||
lv_obj_t * item = lv_obj_get_child(cont, item_id);
|
||||
bool first_item = true;
|
||||
while(item) {
|
||||
if(item_id != item_start_id && lv_obj_has_flag(item, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK)) break;
|
||||
|
||||
@@ -296,11 +297,12 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id
|
||||
else {
|
||||
int32_t item_size = get_main_size(item);
|
||||
int32_t req_size = item_size;
|
||||
if(item_id != item_start_id) req_size += item_gap; /*No gap before the first item*/
|
||||
if(!first_item) req_size += item_gap; /*No gap before the first item*/
|
||||
if(f->wrap && t->track_fix_main_size + grow_min_size_sum + req_size > max_main_size) break;
|
||||
t->track_fix_main_size += req_size;
|
||||
}
|
||||
|
||||
first_item = false;
|
||||
t->track_cross_size = LV_MAX(get_cross_size(item), t->track_cross_size);
|
||||
t->item_cnt++;
|
||||
}
|
||||
|
||||
BIN
tests/ref_imgs/flex_hide_items.png
Normal file
BIN
tests/ref_imgs/flex_hide_items.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
tests/ref_imgs_vg_lite/flex_hide_items.png
Normal file
BIN
tests/ref_imgs_vg_lite/flex_hide_items.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -81,7 +81,6 @@ void test_align(void)
|
||||
/*See https://github.com/lvgl/lvgl/issues/7035*/
|
||||
void test_wrap_grow_min_width(void)
|
||||
{
|
||||
|
||||
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY);
|
||||
|
||||
@@ -106,4 +105,70 @@ void test_wrap_grow_min_width(void)
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("flex_wrap_grow_min_width.png");
|
||||
}
|
||||
|
||||
|
||||
static lv_obj_t * cont_row_5_create(void)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_size(cont, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_center(cont);
|
||||
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
lv_obj_t * btn = lv_button_create(cont);
|
||||
lv_obj_set_size(btn, 40, 60);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text_fmt(label, "%d", i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
return cont;
|
||||
}
|
||||
|
||||
static void hide(lv_obj_t * cont, uint32_t idx)
|
||||
{
|
||||
lv_obj_add_flag(lv_obj_get_child(cont, idx), LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
void test_flex_hide_items(void)
|
||||
{
|
||||
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_COLUMN_WRAP);
|
||||
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_SPACE_EVENLY);
|
||||
|
||||
lv_obj_t * cont;
|
||||
cont = cont_row_5_create();
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 0);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 0);
|
||||
hide(cont, 1);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 4);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 3);
|
||||
hide(cont, 4);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 0);
|
||||
hide(cont, 1);
|
||||
hide(cont, 3);
|
||||
hide(cont, 4);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 1);
|
||||
hide(cont, 3);
|
||||
|
||||
cont = cont_row_5_create();
|
||||
hide(cont, 0);
|
||||
hide(cont, 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("flex_hide_items.png");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user