Rename "dot" union in lv_label

This commit is contained in:
Themba Dube
2019-04-20 09:05:36 -04:00
parent d6ef684867
commit 95fc629aa5
2 changed files with 18 additions and 18 deletions

View File

@@ -97,7 +97,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy)
ext->txt_sel_start = LV_LABEL_TEXT_SEL_OFF;
ext->txt_sel_end = LV_LABEL_TEXT_SEL_OFF;
#endif
ext->dt.dot_tmp_ptr = NULL;
ext->dot.tmp_ptr = NULL;
ext->dot_tmp_alloc = 0;
lv_obj_set_design_cb(new_label, lv_label_design);
@@ -130,12 +130,12 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy)
memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text));
}
if(copy_ext->dot_tmp_alloc && copy_ext->dt.dot_tmp_ptr ){
int len = strlen(copy_ext->dt.dot_tmp_ptr);
lv_label_set_dot_tmp(new_label, ext->dt.dot_tmp_ptr, len);
if(copy_ext->dot_tmp_alloc && copy_ext->dot.tmp_ptr ){
int len = strlen(copy_ext->dot.tmp_ptr);
lv_label_set_dot_tmp(new_label, ext->dot.tmp_ptr, len);
}
else{
memcpy(ext->dt.dot_tmp, copy_ext->dt.dot_tmp, sizeof(ext->dt.dot_tmp));
memcpy(ext->dot.tmp, copy_ext->dot.tmp, sizeof(ext->dot.tmp));
}
ext->dot_tmp_alloc = copy_ext->dot_tmp_alloc;
ext->dot_end = copy_ext->dot_end;
@@ -1119,19 +1119,19 @@ static bool lv_label_set_dot_tmp(lv_obj_t *label, char *data, uint16_t len){
if( len > sizeof(char *) ){
/* Memory needs to be allocated. Allocates an additional byte
* for a NULL-terminator so it can be copied. */
ext->dt.dot_tmp_ptr = lv_mem_alloc(len + 1);
if( ext->dt.dot_tmp_ptr == NULL ){
ext->dot.tmp_ptr = lv_mem_alloc(len + 1);
if( ext->dot.tmp_ptr == NULL ){
LV_LOG_ERROR("Failed to allocate memory for dot_tmp_ptr");
return false;
}
memcpy(ext->dt.dot_tmp_ptr, data, len);
ext->dt.dot_tmp_ptr[len]='\0';
memcpy(ext->dot.tmp_ptr, data, len);
ext->dot.tmp_ptr[len]='\0';
ext->dot_tmp_alloc = true;
}
else {
/* Characters can be directly stored in object */
ext->dot_tmp_alloc = false;
memcpy(ext->dt.dot_tmp, data, len);
memcpy(ext->dot.tmp, data, len);
}
return true;
}
@@ -1144,10 +1144,10 @@ static bool lv_label_set_dot_tmp(lv_obj_t *label, char *data, uint16_t len){
static char * lv_label_get_dot_tmp(lv_obj_t *label){
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
if( ext->dot_tmp_alloc ){
return ext->dt.dot_tmp_ptr;
return ext->dot.tmp_ptr;
}
else{
return ext->dt.dot_tmp;
return ext->dot.tmp;
}
}
@@ -1158,11 +1158,11 @@ static char * lv_label_get_dot_tmp(lv_obj_t *label){
*/
static void lv_label_dot_tmp_free(lv_obj_t *label){
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
if( ext->dot_tmp_alloc && ext->dt.dot_tmp_ptr ){
lv_mem_free(ext->dt.dot_tmp_ptr);
if( ext->dot_tmp_alloc && ext->dot.tmp_ptr ){
lv_mem_free(ext->dot.tmp_ptr);
}
ext->dot_tmp_alloc = false;
ext->dt.dot_tmp_ptr = NULL;
ext->dot.tmp_ptr = NULL;
}
#endif

View File

@@ -64,9 +64,9 @@ typedef struct
/*New data for this type */
char * text; /*Text of the label*/
union{
char * dot_tmp_ptr; /* Pointer to the allocated memory containing the character which are replaced by dots (Handled by the library)*/
char dot_tmp[ sizeof(char *) ]; /* Directly store the characters if <=4 characters */
} dt;
char * tmp_ptr; /* Pointer to the allocated memory containing the character which are replaced by dots (Handled by the library)*/
char tmp[ sizeof(char *) ]; /* Directly store the characters if <=4 characters */
} dot;
uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/
lv_point_t offset; /*Text draw position offset*/