fix(label): issue when setting fmt text with long mode dots (#8781)

This commit is contained in:
Andy Everitt
2025-09-11 21:30:11 +01:00
committed by GitHub
parent a160432baa
commit c48a42da79
4 changed files with 40 additions and 0 deletions
+2
View File
@@ -193,6 +193,8 @@ void lv_label_set_text_vfmt(lv_obj_t * obj, const char * fmt, va_list args)
lv_obj_invalidate(obj);
lv_label_t * label = (lv_label_t *)obj;
lv_label_revert_dots(obj);
/*If text is NULL then refresh*/
if(fmt == NULL) {
lv_label_refr_text(obj);
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

+38
View File
@@ -615,6 +615,44 @@ void test_label_max_width(void)
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/label_max_width.png");
}
void test_label_dots(void)
{
lv_obj_clean(lv_screen_active());
lv_obj_t * cont = lv_obj_create(lv_screen_active());
lv_obj_set_size(cont, LV_PCT(100), LV_PCT(100));
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
lv_obj_t * label1 = lv_label_create(cont);
lv_obj_t * label2 = lv_label_create(cont);
lv_obj_t * label3 = lv_label_create(cont);
lv_obj_t * label4 = lv_label_create(cont);
lv_obj_set_size(label1, 150, 30);
lv_obj_set_size(label2, 150, 30);
lv_obj_set_size(label3, 150, 30);
lv_obj_set_size(label4, 150, 30);
const char * temp_text = "Some other text";
lv_label_set_text(label1, long_text);
lv_label_set_text(label2, temp_text);
lv_label_set_text_fmt(label3, "%.*s", (int)strlen(long_text), long_text);
lv_label_set_text_fmt(label4, "%.*s", (int)strlen(temp_text), temp_text);
lv_label_set_long_mode(label1, LV_LABEL_LONG_MODE_DOTS);
lv_label_set_long_mode(label2, LV_LABEL_LONG_MODE_DOTS);
lv_label_set_long_mode(label3, LV_LABEL_LONG_MODE_DOTS);
lv_label_set_long_mode(label4, LV_LABEL_LONG_MODE_DOTS);
/* Setting the text with _fmt when long mode was dots would cause the incorrect text to be displayed */
lv_label_set_text(label2, long_text);
lv_label_set_text_fmt(label4, "%.*s", (int)strlen(long_text), long_text);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/label_dots.png");
}
void test_label_with_recolor_cmd(void)
{
lv_obj_clean(lv_screen_active());