Description
I have a list with a couple items, each item is just a simple label. By using lv_list_get_btn_label and apply style to it, I’m able to change the font size/family. However, the item row does not resize accordingly and it end up with some vertical animation in a very short row.
What MCU/Processor/Board and compiler are you using?
I’m running this in Zephyr POSIX emulator.
What LVGL version are you using?
7.4.0
What do you want to achieve?
Let the list auto-resize its row according to the label size
What have you tried so far?
setting auto-align on both the list and the button contains the label.
Screenshot and/or video
The following code works well for me (the key is the lv_obj_set_style_local_text_font
line):
void list_font_example(void)
{
/*Create a list*/
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_size(list1, 160, 200);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_local_text_font(list1, LV_LIST_PART_BG, LV_STATE_DEFAULT, &lv_font_montserrat_8);
/*Add buttons to the list*/
lv_obj_t * list_btn;
list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "New");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Open");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Delete");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Edit");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Save");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_BELL, "Notify");
lv_obj_set_event_cb(list_btn, event_handler);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery");
lv_obj_set_event_cb(list_btn, event_handler);
}
1 Like