Description
Hi there, I am trying to make a normal object (which contains two labels) clickable with an encoder.
Once I create the object, I have a callback registered for LV_EVENT_SHORT_CLICKED. However, to trigger my callback, I need to click the object twice. (It seems as though I need to activate edit mode, then click again to get the “LV_EVENT_SHORT_CLICKED” event to be sent.
Furthermore, once I am in edit mode, I cant for the life of me return to navigate mode without manually doing that in the callback. (So I get stuck within the object)
What MCU/Processor/Board and compiler are you using?
I am using an STM32F769 on a custom board, with CubeIDE
What LVGL version are you using?
Version 8.1+
What do you want to achieve?
I want my my objects to act like buttons (regarding navigation and clicking).
I dont want to be able to “edit” the object, I just want it to trigger the “clicked” callback, and then I want to continue navigating, just like a normal button would.
What have you tried so far?
So I have my objects, all underneath one another. I have tried setting various flags on the objects without success.
Code to reproduce:
This is where I create my objects:
void Display_BuildSettingsMenu(lv_event_t * e)
{
//Clear group of all objects
lv_group_remove_all_objs(TestmenuGroup);
//Create the array of setting items
for(uint8_t i = 0; i < Settings_Count; i++)
{
//Create an object
Display_SettingsObjects[i] = lv_obj_create(lv_win_right_main_buttons);
//Set the object size / align
lv_obj_set_width(Display_SettingsObjects[i], LV_PCT(100));
lv_obj_set_height(Display_SettingsObjects[i], 30);
lv_obj_align(Display_SettingsObjects[i], LV_ALIGN_CENTER, 0, 0);
//Reduce padding
lv_obj_set_style_pad_all(Display_SettingsObjects[i], 2, 0);
//Add the first label (name of the setting)
lv_obj_t * child1 = lv_label_create(Display_SettingsObjects[i]);
lv_label_set_text(child1, TestJigSettings[i].Name);
//set the width of the name label
lv_obj_set_width(child1, LV_PCT(65));
lv_obj_align(child1, LV_ALIGN_LEFT_MID, 0, 0);
//Convert settings value to text for the second label
char tempSettingText[MAX_SETTING_TEXT_LENGTH];
Display_getSettingText(TestSettings[i].Type, TestSettings[i].Current, TestSettings[i].Options, TestSettings[i].OptionCount, tempSettingText);
//Add the second label
lv_obj_t * child2 = lv_label_create(Display_SettingsObjects[i]);
lv_label_set_text(child2, tempSettingText);
//set the width
lv_obj_set_width(child2, LV_PCT(30));
lv_obj_align(child2, LV_ALIGN_RIGHT_MID, 0, 0);
//Add the parent object to the group
lv_group_add_obj(TestmenuGroup, Display_SettingsObjects[i]);
//Enable scrolling
lv_obj_add_flag(Display_SettingsObjects[i], LV_OBJ_FLAG_SCROLL_ON_FOCUS);
//Make clickable
lv_obj_add_flag(Display_SettingsObjects[i], LV_OBJ_FLAG_CLICK_FOCUSABLE);
//Add the callback for the menu item
lv_obj_add_event_cb(Display_SettingsObjects[i], Display_EditSetting, LV_EVENT_SHORT_CLICKED, &TestJigSettings[i]);
}
//Set indevices
lv_indev_set_group(MyInputDevice, TestmenuGroup);
lv_indev_set_group(MyInputDevice2, TestmenuGroup);
//focus the first setting
lv_group_focus_obj(Display_SettingsObjects[0]);
}
The callback “Display_EditSetting” is only called once I click one of the objects twice. Then I get stuck within that object (I assume in edit mode)