diff options
Diffstat (limited to 'src/ui/screen_menu.cpp')
| -rw-r--r-- | src/ui/screen_menu.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/ui/screen_menu.cpp b/src/ui/screen_menu.cpp index b6d0606a..743dc6fa 100644 --- a/src/ui/screen_menu.cpp +++ b/src/ui/screen_menu.cpp @@ -11,35 +11,41 @@ #include "core/lv_group.h" #include "core/lv_obj_pos.h" +#include "event_queue.hpp" #include "extra/widgets/list/lv_list.h" #include "extra/widgets/menu/lv_menu.h" #include "extra/widgets/spinner/lv_spinner.h" #include "hal/lv_hal_disp.h" +#include "index.hpp" #include "misc/lv_area.h" +#include "ui_events.hpp" +#include "ui_fsm.hpp" #include "widgets/lv_label.h" namespace ui { namespace screens { static void item_click_cb(lv_event_t* ev) { - ESP_LOGI("menu", "clicked!"); + if (ev->user_data == NULL) { + return; + } + database::IndexInfo* index = + reinterpret_cast<database::IndexInfo*>(ev->user_data); + + events::Dispatch<internal::IndexSelected, UiState>( + internal::IndexSelected{.index = *index}); } -Menu::Menu() { +Menu::Menu(std::vector<database::IndexInfo> indexes) : indexes_(indexes) { lv_obj_t* list = lv_list_create(root_); lv_obj_set_size(list, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL)); lv_obj_center(list); - lv_obj_t* button; - - button = lv_list_add_btn(list, NULL, "hi"); - lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL); - - button = lv_list_add_btn(list, NULL, "second"); - lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL); - - button = lv_list_add_btn(list, NULL, "third"); - lv_obj_add_event_cb(button, item_click_cb, LV_EVENT_CLICKED, NULL); + for (database::IndexInfo& index : indexes_) { + lv_obj_t* item = lv_list_add_btn(list, NULL, index.name.c_str()); + lv_obj_add_event_cb(item, item_click_cb, LV_EVENT_CLICKED, &index); + lv_group_add_obj(group_, item); + } } Menu::~Menu() {} |
