How to align text in button matrix


I want to employ a tabview with the LV_DIR_LEFT direction to present tabs in a menu-like list. However, I’m encountering a challenge where I cannot align the titles to the left within the button matrix. The text is automatically centered in the virtual buttons (see screenshot bellow), and I’m looking for a way to customize the alignment to achieve a left-aligned presentation.

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

vscode simulator

What LVGL version are you using?

LVGL 8.3.7

What have you tried so far?

lv_obj_set_style_text_align(lv_tabview_get_tab_btns(tabview),LV_TEXT_ALIGN_LEFT,LV_PART_ITEMS| LV_STATE_DEFAULT);

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

lv_obj_t *tabview = lv_tabview_create(screen,LV_DIR_LEFT,200);
lv_tabview_add_tab(tabview,  "\they you" );
lv_tabview_add_tab(tabview, "\thello world");
lv_tabview_add_tab(tabview,  "\tfourth page");
lv_tabview_add_tab(tabview, "\tHome");

Screenshot and/or video

Judging from the source code of tabview’s sub-component btnmatrix, the coordinates of the text are forced to be centered:

you can try to manually create a label component and cooperate with flex layout to achieve a similar effect.


thank you for your response,
Maybe i’ll try to switch to the master version and take the new widget tabview which it uses buttons and labels instead of btnmatrix, i don’t know yet if tabview in master branch is working