Description
I want to navigate in menu with 6 buttons。1~3 buttons are used for menu’s left side. 4~6 for the other side.But only one side is not yet working well.
What MCU/Processor/Board and compiler are you using?
visual stidio 2019 simulator
What LVGL version are you using?
V8.1
What do you want to achieve?
I want to navigate in menu with 6 buttons。1~3 buttons are used for menu’s left side. 4~6 for the other side.But only one side is not yet working well.
What have you tried so far?
test the left side of menu
Code to reproduce
lv_example_menu_5() is called by main().
The code block(s) should be formatted like:
lv_style_t op_axis_label_style;
uint8_t axis_key_id = 0;
lv_obj_t* contL, * contR;
lv_group_t* dg;
lv_style_t label_flex_style;//
void event_op_key(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* obj = lv_event_get_target(e);
lv_obj_t* par = lv_obj_get_parent(obj);
uint8_t id = lv_obj_get_child_id(obj) + 1;
lv_group_focus_freeze(dg, 0);
lv_group_set_editing(dg, 0);
switch(id)
{
case 1:lv_group_send_data(dg, LV_KEY_PREV);break;
case 2:lv_group_send_data(dg, LV_KEY_NEXT);break;
case 3:lv_group_send_data(dg, LV_KEY_ENTER);break;
default:break;
}
}
void op_axis_key_init( lv_obj_t* par)
{
lv_style_init(&label_flex_style);
lv_style_set_flex_flow(&label_flex_style, LV_FLEX_FLOW_COLUMN_WRAP);
lv_style_set_flex_main_place(&label_flex_style, LV_FLEX_ALIGN_SPACE_EVENLY);
lv_style_set_pad_row(&label_flex_style, 60);
// lv_style_set_pad_column(&label_flex_style, 600);
lv_style_set_flex_cross_place(&label_flex_style, LV_FLEX_ALIGN_SPACE_EVENLY);
contL = lv_obj_create(par);
contR = lv_obj_create(par);
lv_obj_add_style(contL, &label_flex_style, LV_PART_MAIN);
lv_obj_set_flex_flow(contL, LV_FLEX_FLOW_COLUMN_WRAP);
lv_obj_set_size(contL, 100, LV_VER_RES);
lv_obj_align(contL, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_add_style(contR, &label_flex_style, LV_PART_MAIN);
lv_obj_set_flex_flow(contR, LV_FLEX_FLOW_COLUMN_WRAP);
lv_obj_set_size(contR, 100, LV_VER_RES);
lv_obj_align(contR, LV_ALIGN_RIGHT_MID, 0, 0);
uint8_t i = 0;
lv_obj_t* obj;
for (i = 0;i < 6;i++)
{
if(i<3)
obj = lv_btn_create(contL);
else
obj = lv_btn_create(contR);
lv_obj_add_event_cb(obj, event_op_key, LV_EVENT_CLICKED, NULL);
lv_obj_t* label = lv_label_create(obj);
char s = 0x30 + i + 1;
char txt[5];
txt[0] = s;
txt[1] = '\0';
lv_label_set_text(label, txt);
lv_group_remove_obj(obj);
}
}
void lv_example_menu_5(void)
{
op_axis_key_init( lv_layer_top());
lv_obj_t* menu = lv_menu_create(lv_scr_act());
lv_menu_set_mode_root_back_btn(menu, LV_MENU_ROOT_BACK_BTN_ENABLED);
lv_obj_set_size(menu, lv_pct(50), lv_disp_get_ver_res(NULL));
lv_obj_center(menu);
lv_obj_t* section;
/*Create sub pages*/
lv_obj_t* sub_mechanics_page = lv_menu_page_create(menu, NULL);
lv_obj_set_style_pad_hor(sub_mechanics_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
lv_menu_separator_create(sub_mechanics_page);
section = lv_menu_section_create(sub_mechanics_page);
for (uint8_t i = 0;i < 3;i++)
{
lv_obj_t* obj = lv_btn_create(section);
lv_obj_t* label = lv_label_create(obj);
char s = 0x30 + i;
char txt[5];
txt[0] = 'a';
txt[1] = s;
txt[2] = '\0';
lv_label_set_text(label, txt);
lv_group_add_obj(dg, obj);
}
lv_obj_t* btn = lv_btn_create(root_page);
lv_obj_add_flag(btn, LV_OBJ_FLAG_HIDDEN);
dg = lv_obj_get_group(btn);
/*Create a root page*/
root_page = lv_menu_page_create(menu, "Settings");
lv_obj_set_style_pad_hor(root_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
for (uint8_t i = 0;i < 3;i++)
{
lv_obj_t* obj = lv_btn_create(root_page);
lv_menu_set_load_page_event(menu, obj, sub_mechanics_page);
lv_obj_t* label = lv_label_create(obj);
char s = 'a' + i ;
char txt[5];
txt[0] = s;
txt[1] = '\0';
lv_label_set_text(label, txt);
lv_group_add_obj(dg, obj);
}
lv_menu_set_sidebar_page(menu, root_page);
lv_event_send(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 0), LV_EVENT_CLICKED, NULL);
lv_group_focus_obj(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 1));
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.