Wrong Text alignment

Description

Hi,
i am facing an issue with labels

What MCU/Processor/Board and compiler are you using?

ARM

What do you experience?

when i set text from handleHumidity function the text is not showing as written. as per the code the text is set to below to temp_decrease img button. but the text is setting to right alignment.
but when i hardcode the text in humidity object it showing perfect.

What do you expect?

i want to print this text exactly below the img button.

Code to reproduce

static lv_obj_t * humidity;
static lv_obj_t * temp_decrease;
void test_screen(void)
{
              temp_decrease=lv_imgbtn_create(lv_scr_act(), NULL);
              lv_imgbtn_set_src(temp_decrease,LV_BTN_STATE_RELEASED,&temp_down);
              lv_imgbtn_set_src(temp_decrease,LV_BTN_STATE_PRESSED,&temp_down);
              lv_obj_align(temp_decrease,NULL,LV_ALIGN_CENTER,0,0);

              humidity = lv_label_create(lv_scr_act(), NULL);
              lv_label_set_text(humidity, "");
              lv_obj_align(humidity,temp_decrease,LV_ALIGN_OUT_BOTTOM_MID,0,30);
}
int handleHumidity(char *message){

    printf("### Message Arrived [Humidity]: %s",message); //Here message value is 36
    char curr_humidity[64];
    sprintf(curr_humidity,"Humidity is %s",message);
    lv_label_set_text(humidity,curr_humidity);
    return 0;
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current issue.

Maybe a little difficult to explain:

The alignment of text within a label is closely linked.
It means, when you change the address of the string buffer the alignment is lost.

Or said differently, when you link a new string buffer to a label (or other control!?), you have to
set the alignment again.
Which means after the call of lv_label_set_text in handleHumidity, you have to call lv_obj_align
again.

If you write your code this way:

static lv_obj_t* humidity;
static lv_obj_t* temp_decrease;

char curr_humidity[64];

void test_screen (void)
{
    temp_decrease = lv_imgbtn_create (lv_scr_act(), NULL);

    lv_imgbtn_set_src (temp_decrease, LV_BTN_STATE_RELEASED, &temp_down);
    lv_imgbtn_set_src (temp_decrease, LV_BTN_STATE_PRESSED,  &temp_down);
    lv_obj_align      (temp_decrease, NULL, LV_ALIGN_CENTER, 0, 0);

    snprintf (curr_humidity, 64, "Humidity is 000000"); // just as an example, you also can use ""

    humidity = lv_label_create (lv_scr_act(), NULL);
    lv_label_set_text (humidity, curr_humidity);
    lv_obj_align      (humidity, temp_decrease, LV_ALIGN_OUT_BOTTOM_MID, 0, 30);
}

int handleHumidity (char *message)
{
    snprintf (curr_humidity, 64, "Humidity is %s", message);
    lv_label_set_text (humidity, curr_humidity);

    return 0;
}

Now, the label is always linked with the same string buffer (curr_humidity), and so the alignment is kept.

Some additional hint: For string printing use snprintf!
With snprintf you avoid string overflows (in case you set the size in sprintf to the same value as of your string buffer).

Thanks Robekras. Issue resolved.