fix(flex): fix alignment issue when using rtl in flex layout (#8929)

This commit is contained in:
caibutshuai
2025-09-23 17:43:21 +08:00
committed by GitHub
parent 173cae5456
commit 4c74f68154
4 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -386,7 +386,7 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i
int32_t place_gap = 0;
place_content(f->main_place, max_main_size, t->track_main_size, t->item_cnt, &main_pos, &place_gap);
if(f->row && rtl) main_pos += lv_obj_get_content_width(cont);
if(f->row && rtl) main_pos = max_main_size - main_pos;
lv_obj_t * item = lv_obj_get_child(cont, item_first_id);
/*Reposition the children*/
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

+20
View File
@@ -170,5 +170,25 @@ void test_flex_hide_items(void)
TEST_ASSERT_EQUAL_SCREENSHOT("flex_hide_items.png");
}
void test_flex_use_rtl(void)
{
lv_obj_t * test = lv_obj_create(lv_screen_active());
lv_obj_center(test);
lv_obj_set_width(test, LV_PCT(40));
lv_obj_set_height(test, LV_SIZE_CONTENT);
lv_obj_set_style_border_width(test, 2, 0);
lv_obj_set_style_base_dir(test, LV_BASE_DIR_RTL, 0);
lv_obj_set_flex_flow(test, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(test, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
for(int i = 0; i < 8; i++) {
lv_obj_t * obj = lv_obj_create(test);
lv_obj_set_size(obj, 70, 70);
lv_obj_set_style_border_width(obj, 2, 0);
}
TEST_ASSERT_EQUAL_SCREENSHOT("flex_use_rtl.png");
}
#endif