/** * Set a new text for a label. Memory will be allocated to store the text by the label. * @param label pointer to a label object * @param text '\0' terminated character string. NULL to refresh with the current text. */ void lv_label_set_text(lv_obj_t * label, const char * text) { lv_obj_invalidate(label); lv_label_ext_t * ext = lv_obj_get_ext_attr(label); /*If text is NULL then refresh */ if(text == NULL) { lv_label_refr_text(label); return; } if(ext->text == text) { /*If set its own text then reallocate it (maybe its size changed)*/ ext->text = lv_mem_realloc(ext->text, strlen(ext->text) + 1); } else { /*Allocate space for the new text*/ uint32_t len = strlen(text) + 1; if(ext->text != NULL && ext->static_txt == 0) { lv_mem_free(ext->text); ext->text = NULL; } ext->text = lv_mem_alloc(len); strcpy(ext->text, text); ext->static_txt = 0; /*Now the text is dynamically allocated*/ } lv_label_refr_text(label); }
/** * Set a static text. It will not be saved by the label so the 'text' variable * has to be 'alive' while the label exist. * @param label pointer to a label object * @param text pointer to a text. NULL to refresh with the current text. */ void lv_label_set_static_text(lv_obj_t * label, const char * text) { lv_label_ext_t * ext = lv_obj_get_ext_attr(label); if(ext->static_txt == 0 && ext->text != NULL) { lv_mem_free(ext->text); ext->text = NULL; } if(text != NULL) { ext->static_txt = 1; ext->text = (char *) text; } lv_label_refr_text(label); }
/** * Signal function of the gauge * @param gauge pointer to a gauge object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted */ static lv_res_t lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) { lv_res_t res; /* Include the ancient signal function */ res = ancestor_signal(gauge, sign, param); if(res != LV_RES_OK) return res; lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); if(sign == LV_SIGNAL_CLEANUP) { lv_mem_free(ext->values); ext->values = NULL; } return res; }
/** * Signal function of the label * @param label pointer to a label object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted */ static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param) { lv_res_t res; /* Include the ancient signal function */ res = ancestor_signal(label, sign, param); if(res != LV_RES_OK) return res; lv_label_ext_t * ext = lv_obj_get_ext_attr(label); if(sign == LV_SIGNAL_CLEANUP) { if(ext->static_txt == 0) { lv_mem_free(ext->text); ext->text = NULL; } } else if(sign == LV_SIGNAL_STYLE_CHG) { /*Revert dots for proper refresh*/ lv_label_revert_dots(label); lv_label_refr_text(label); } else if (sign == LV_SIGNAL_CORD_CHG) { if(lv_area_get_width(&label->coords) != lv_area_get_width(param) || lv_area_get_height(&label->coords) != lv_area_get_height(param)) { lv_label_revert_dots(label); lv_label_refr_text(label); } } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { if(ext->body_draw) { lv_style_t * style = lv_label_get_style(label); label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.hor); label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.ver); } } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ if(buf->type[i] == NULL) break; } buf->type[i] = "lv_label"; } return res; }
/** * Set the number of needles * @param gauge pointer to gauge object * @param needle_cnt new count of needles * @param colors an array of colors for needles (with 'num' elements) */ void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors) { lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); if(ext->values != NULL) { lv_mem_free(ext->values); ext->values = NULL; } ext->values = lv_mem_realloc(ext->values, needle_cnt * sizeof(int16_t)); int16_t min = lv_gauge_get_min_value(gauge); uint8_t n; for(n = ext->needle_count; n < needle_cnt; n++) { ext->values[n] = min; } ext->needle_count = needle_cnt; ext->needle_colors = colors; lv_obj_invalidate(gauge); }
/** * Signal function of the gauge * @param gauge pointer to a gauge object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted */ static lv_res_t lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) { lv_res_t res; /* Include the ancient signal function */ res = ancestor_signal(gauge, sign, param); if(res != LV_RES_OK) return res; lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); if(sign == LV_SIGNAL_CLEANUP) { lv_mem_free(ext->values); ext->values = NULL; } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ if(buf->type[i] == NULL) break; } buf->type[i] = "lv_gauge"; } return res; }
/** * Set a new text for a label from a character array. The array don't has to be '\0' terminated. * Memory will be allocated to store the array by the label. * @param label pointer to a label object * @param array array of characters or NULL to refresh the label * @param size the size of 'array' in bytes */ void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size) { lv_obj_invalidate(label); lv_label_ext_t * ext = lv_obj_get_ext_attr(label); /*If trying to set its own text or the array is NULL then refresh */ if(array == ext->text || array == NULL) { lv_label_refr_text(label); return; } /*Allocate space for the new text*/ if(ext->text != NULL && ext->static_txt == 0) { lv_mem_free(ext->text); ext->text = NULL; } ext->text = lv_mem_alloc(size + 1); memcpy(ext->text, array, size); ext->text[size] = '\0'; ext->static_txt = 0; /*Now the text is dynamically allocated*/ lv_label_refr_text(label); }
/** * Delete a lv_task * @param lv_task_p pointer to task created by lv_task_p */ void lv_task_del(lv_task_t* lv_task_p) { lv_ll_rem(&lv_task_ll, lv_task_p); lv_mem_free(lv_task_p); }