1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(span): fix align text to center and right layout issues. (#7615)

Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
This commit is contained in:
红桃六 2025-01-21 17:33:26 +08:00 committed by GitHub
parent 2cdcf8d729
commit 7ab421ed30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 0 deletions

View File

@ -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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -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