diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 90fec1535b..0dfc071ac3 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -703,8 +703,11 @@ void lv_obj_refr_pos(lv_obj_t * obj) lv_align_t align = lv_obj_get_style_align(obj, LV_PART_MAIN); + bool rtl = false; + if(align == LV_ALIGN_DEFAULT) { - if(lv_obj_get_style_base_dir(parent, LV_PART_MAIN) == LV_BASE_DIR_RTL) align = LV_ALIGN_TOP_RIGHT; + rtl = lv_obj_get_style_base_dir(parent, LV_PART_MAIN) == LV_BASE_DIR_RTL; + if(rtl) align = LV_ALIGN_TOP_RIGHT; else align = LV_ALIGN_TOP_LEFT; } @@ -715,7 +718,7 @@ void lv_obj_refr_pos(lv_obj_t * obj) x += pw / 2 - w / 2; break; case LV_ALIGN_TOP_RIGHT: - x += pw - w; + x = rtl ? pw - w - x : pw - w + x; break; case LV_ALIGN_LEFT_MID: y += ph / 2 - h / 2; diff --git a/tests/ref_imgs/widgets/rtl_pos_x_y.png b/tests/ref_imgs/widgets/rtl_pos_x_y.png new file mode 100644 index 0000000000..2edd9e3eb7 Binary files /dev/null and b/tests/ref_imgs/widgets/rtl_pos_x_y.png differ diff --git a/tests/ref_imgs_vg_lite/widgets/rtl_pos_x_y.png b/tests/ref_imgs_vg_lite/widgets/rtl_pos_x_y.png new file mode 100644 index 0000000000..dd37f3ec60 Binary files /dev/null and b/tests/ref_imgs_vg_lite/widgets/rtl_pos_x_y.png differ diff --git a/tests/src/test_cases/widgets/test_obj_pos.c b/tests/src/test_cases/widgets/test_obj_pos.c index 7eeaa81a18..ac14124a42 100644 --- a/tests/src/test_cases/widgets/test_obj_pos.c +++ b/tests/src/test_cases/widgets/test_obj_pos.c @@ -195,4 +195,53 @@ void test_circular_width_dependency(void) TEST_ASSERT_EQUAL_INT32(lv_obj_get_width(item2), lv_obj_get_width(item3)); } +static void cont_create_x_y(lv_obj_t * parent, const char * text, int32_t x, int32_t y) +{ + lv_obj_t * cont = lv_obj_create(parent); + lv_obj_remove_style(cont, NULL, LV_PART_MAIN); + lv_obj_set_style_border_width(cont, 1, LV_PART_MAIN); + lv_obj_set_size(cont, 150, 30); + lv_obj_set_pos(cont, x, y); + + lv_obj_t * label = lv_label_create(cont); + lv_label_set_text(label, text); + + lv_obj_t * rect_top_right = lv_obj_create(cont); + lv_obj_remove_style(rect_top_right, NULL, LV_PART_MAIN); + lv_obj_set_size(rect_top_right, 10, 10); + lv_obj_set_align(rect_top_right, LV_ALIGN_TOP_RIGHT); + lv_obj_set_style_bg_color(rect_top_right, lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN); + lv_obj_set_style_bg_opa(rect_top_right, LV_OPA_COVER, LV_PART_MAIN); + + lv_obj_t * rect_bottom_left = lv_obj_create(cont); + lv_obj_remove_style(rect_bottom_left, NULL, LV_PART_MAIN); + lv_obj_set_size(rect_bottom_left, 10, 10); + lv_obj_set_align(rect_bottom_left, LV_ALIGN_BOTTOM_LEFT); + lv_obj_set_style_bg_color(rect_bottom_left, lv_palette_main(LV_PALETTE_GREEN), LV_PART_MAIN); + lv_obj_set_style_bg_opa(rect_bottom_left, LV_OPA_COVER, LV_PART_MAIN); + + lv_obj_t * rect_bottom_right = lv_obj_create(cont); + lv_obj_remove_style(rect_bottom_right, NULL, LV_PART_MAIN); + lv_obj_set_size(rect_bottom_right, 10, 10); + lv_obj_set_align(rect_bottom_right, LV_ALIGN_BOTTOM_RIGHT); + lv_obj_set_style_bg_color(rect_bottom_right, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN); + lv_obj_set_style_bg_opa(rect_bottom_right, LV_OPA_COVER, LV_PART_MAIN); +} + +void test_rtl_pos_x_y(void) +{ + lv_obj_t * cont = lv_obj_create(lv_screen_active()); + + lv_obj_set_size(cont, LV_PCT(100), LV_PCT(100)); + lv_obj_set_style_base_dir(cont, LV_BASE_DIR_RTL, LV_PART_MAIN); + + cont_create_x_y(cont, "(0,0)", 0, 0); + cont_create_x_y(cont, "(50,50)", 50, 50); + cont_create_x_y(cont, "(100,100)", 100, 100); + cont_create_x_y(cont, "(150,150)", 150, 150); + cont_create_x_y(cont, "(100,200)", 100, 200); + + TEST_ASSERT_EQUAL_SCREENSHOT("widgets/rtl_pos_x_y.png"); +} + #endif