diff --git a/src/widgets/span/lv_span.c b/src/widgets/span/lv_span.c index e7ece397c..e2d40ebe6 100644 --- a/src/widgets/span/lv_span.c +++ b/src/widgets/span/lv_span.c @@ -1041,6 +1041,12 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer) uint32_t i; for(i = 0; i < item_cnt; i++) { lv_snippet_t * pinfo = lv_get_snippet(i); + if(ellipsis_valid && i == item_cnt - 1) { + uint32_t n_ofs = 0; + lv_text_get_snippet(pinfo->txt, pinfo->font, pinfo->letter_space, max_width - txts_w, + LV_TEXT_FLAG_BREAK_ALL, &pinfo->txt_w, &n_ofs); + pinfo->bytes = n_ofs; + } txts_w = txts_w + pinfo->txt_w; } txts_w -= lv_get_snippet(item_cnt - 1)->letter_space; diff --git a/tests/ref_imgs/widgets/span_10.png b/tests/ref_imgs/widgets/span_10.png new file mode 100644 index 000000000..ce0049c32 Binary files /dev/null and b/tests/ref_imgs/widgets/span_10.png differ diff --git a/tests/ref_imgs_vg_lite/widgets/span_10.png b/tests/ref_imgs_vg_lite/widgets/span_10.png new file mode 100644 index 000000000..84c3bda15 Binary files /dev/null and b/tests/ref_imgs_vg_lite/widgets/span_10.png differ diff --git a/tests/src/test_cases/widgets/test_span.c b/tests/src/test_cases/widgets/test_span.c index 5cbc8c223..ff4666a0d 100644 --- a/tests/src/test_cases/widgets/test_span.c +++ b/tests/src/test_cases/widgets/test_span.c @@ -479,4 +479,23 @@ void test_spangroup_get_span_coords(void) } #endif +void test_spangroup_set_right_align_on_overflow(void) +{ + active_screen = lv_screen_active(); + spangroup = lv_spangroup_create(active_screen); + + lv_obj_set_style_outline_width(spangroup, 1, 0); + + lv_obj_set_width(spangroup, 180); + lv_obj_set_height(spangroup, 20); + + lv_spangroup_set_align(spangroup, LV_TEXT_ALIGN_RIGHT); + + lv_span_t * span = lv_spangroup_new_span(spangroup); + lv_span_set_text_static(span, "China is a beautiful country."); + lv_spangroup_set_overflow(spangroup, LV_SPAN_OVERFLOW_ELLIPSIS); + + TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_10.png"); +} + #endif