Please note that the lv_label_set_text usage leads to the same problem. You may know that common compilers used for STM32 architectures put text literals into flash which are then static char arrays anyway.
The calculation in lv_txt_get_next_word sums up glyph widths and letter spaces, but does not take into account that the label width was calculated without the last letter spacing.
Compare:
static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t max_width,
lv_txt_flag_t flag, uint32_t *word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force)
{
[...]
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
cur_w += letter_w;
if(letter_w > 0) {
cur_w += letter_space;
}
/* Test if this character fits within max_width */
if(break_index == NO_BREAK_FOUND && cur_w > max_width) {
break_index = i;
break_letter_count = word_len - 1;
/* break_index is now pointing at the character that doesn't fit */
}
[...]
}
and
lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, const lv_font_t * font, lv_coord_t letter_space,
lv_txt_flag_t flag)
{
[...]
if(width > 0) {
width -= letter_space; /*Trim the last letter space. Important if the text is center
aligned */
}
}
return width;
}