diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index b0126b731..345d33dc2 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -236,6 +236,32 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text) lv_label_refr_text(label); } + +/** + * Append a text to the label. The label current label text can not be static. + * @param label pointer to label object + * @param text pointe rto the new text + */ +void lv_label_append_text(lv_obj_t * label, const char * text) +{ + lv_label_ext_t * ext = lv_obj_get_ext(label); + + /*Can not append to static text*/ + if(ext->static_txt != 0) return; + + lv_obj_inv(label); + + /*Allocate space for the new text*/ + uint32_t old_len = strlen(ext->txt); + uint32_t app_len = strlen(text); + uint32_t new_len = app_len + old_len; + ext->txt = dm_realloc(ext->txt, new_len + 1); + memcpy(ext->txt + old_len, text, app_len); + ext->txt[new_len] = '\0'; + + lv_label_refr_text(label); +} + /** * Set the behavior of the label with longer text then the object size * @param label pointer to a label object diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index fcaaf11eb..330b0ba43 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -111,6 +111,12 @@ void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size */ void lv_label_set_text_static(lv_obj_t * label, const char * text); +/** + * Append a text to the label. The label current label text can not be static. + * @param label pointer to label object + * @param text pointe rto the new text + */ +void lv_label_append_text(lv_obj_t * label, const char * text); /** * Set the behavior of the label with longer text then the object size * @param label pointer to a label object