How can I allign a label vertical

Description

I have a label that contains often short texts but in a error case it can have longer texts that should be placed on several lines.

So i use:

lv_label_set_long_mode(label_error_text, LV_LABEL_LONG_BREAK);

How can I make the text in the label allways vertical center alligned on my display?

What LVGL version are you using?

7.10.1

What do you want to achieve?

A vertical center alligned label with line break.

What have you tried so far?

lv_obj_align to “Center”, but this has a reverence of the label to the upper left corner from the label. I need to center on the vertical center of the label it selve.

Code to reproduce

  label_error_text = lv_label_create(lv_scr_act(), NULL);
  lv_label_set_long_mode(label_error_text, LV_LABEL_LONG_BREAK);   /*Break the long lines*/
  lv_label_set_align(label_error_text, LV_LABEL_ALIGN_LEFT);       /*Left aligned lines*/
  lv_obj_set_size(label_error_text, (LV_HOR_RES_MAX-ERR_TEXT_HOR), LV_VER_RES_MAX);
  lv_obj_set_pos(label_error_text, ERR_TEXT_HOR, 0);
  lv_obj_set_style_local_text_font(label_error_text, LV_LABEL_PART_MAIN , LV_STATE_DEFAULT, lv_theme_get_font_normal()); /*sets the text size*/

Thank you for your always great help!

Try lv_obj_align_mid.

thank you. Now I learnd also how to use the API.

my solution:

  lv_obj_align_origo_y(label_error_text, NULL, LV_ALIGN_IN_RIGHT_MID, 0); /*realign y pos*/

Hmm… you mentioned you were using 7.10.1 in your original post. In that version you should be able to use the mid name and not origo. The old API names are implemented as wrappers in v7 for compatibility, but they have been removed entirely in v8.