diff --git a/src/widgets/label/lv_label.c b/src/widgets/label/lv_label.c index 186c9b25c0..af7bbcf06b 100644 --- a/src/widgets/label/lv_label.c +++ b/src/widgets/label/lv_label.c @@ -173,6 +173,14 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) } void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) +{ + va_list args; + va_start(args, fmt); + lv_label_set_text_vfmt(obj, fmt, args); + va_end(args); +} + +void lv_label_set_text_vfmt(lv_obj_t * obj, const char * fmt, va_list args) { LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(fmt); @@ -191,10 +199,7 @@ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) label->text = NULL; } - va_list args; - va_start(args, fmt); label->text = lv_text_set_text_vfmt(fmt, args); - va_end(args); label->static_txt = 0; /*Now the text is dynamically allocated*/ lv_label_refr_text(obj); diff --git a/src/widgets/label/lv_label.h b/src/widgets/label/lv_label.h index 77d2ee381b..c7800ec4d1 100644 --- a/src/widgets/label/lv_label.h +++ b/src/widgets/label/lv_label.h @@ -99,6 +99,22 @@ void lv_label_set_text(lv_obj_t * obj, const char * text); */ void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3); +/** + * Set a new formatted text for a label. Memory will be allocated to store the text by the label. + * @param obj pointer to a label object + * @param fmt `printf`-like format + * @param args variadic argments list + * + * Example: + * @code + * va_list args; + * va_start(args, fmt); + * lv_label_set_text_vfmt(label1, fmt, args); + * va_end(args); + * @endcode + */ +void lv_label_set_text_vfmt(lv_obj_t * obj, const char * fmt, va_list args); + /** * Set a static text. It will not be saved by the label so the 'text' variable * has to be 'alive' while the label exists.