| 12 | namespace tt::app::appsettings { |
| 13 | |
| 14 | class AppSettingsApp final : public App { |
| 15 | |
| 16 | static void onAppPressed(lv_event_t* e) { |
| 17 | const auto* manifest = static_cast<const AppManifest*>(lv_event_get_user_data(e)); |
| 18 | appdetails::start(manifest->appId); |
| 19 | } |
| 20 | |
| 21 | static void createAppWidget(const std::shared_ptr<AppManifest>& manifest, lv_obj_t* list) { |
| 22 | const void* icon = !manifest->appIcon.empty() ? manifest->appIcon.c_str() : LVGL_ICON_SHARED_TOOLBAR; |
| 23 | lv_obj_t* btn = lv_list_add_button(list, icon, manifest->appName.c_str()); |
| 24 | lv_obj_t* image = lv_obj_get_child(btn, 0); |
| 25 | lv_obj_set_style_text_font(image, lvgl_get_shared_icon_font(), LV_PART_MAIN); |
| 26 | lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get()); |
| 27 | } |
| 28 | |
| 29 | public: |
| 30 | |
| 31 | void onShow(AppContext& app, lv_obj_t* parent) override { |
| 32 | auto* toolbar = lvgl::toolbar_create(parent, "Installed Apps"); |
| 33 | lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); |
| 34 | |
| 35 | lv_obj_t* list = lv_list_create(parent); |
| 36 | lv_obj_set_width(list, LV_PCT(100)); |
| 37 | lv_obj_align_to(list, toolbar, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); |
| 38 | |
| 39 | auto toolbar_height = lv_obj_get_height(toolbar); |
| 40 | auto parent_content_height = lv_obj_get_content_height(parent); |
| 41 | lv_obj_set_height(list, parent_content_height - toolbar_height); |
| 42 | |
| 43 | auto manifests = getAppManifests(); |
| 44 | std::ranges::sort(manifests, SortAppManifestByName); |
| 45 | |
| 46 | size_t app_count = 0; |
| 47 | for (const auto& manifest: manifests) { |
| 48 | if (manifest->appLocation.isExternal()) { |
| 49 | app_count++; |
| 50 | createAppWidget(manifest, list); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (app_count == 0) { |
| 55 | auto* no_apps_label = lv_label_create(parent); |
| 56 | lv_label_set_text(no_apps_label, "No apps installed"); |
| 57 | lv_obj_align(no_apps_label, LV_ALIGN_CENTER, 0, 0); |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | extern const AppManifest manifest = { |
| 63 | .appId = "AppSettings", |
nothing calls this directly
no outgoing calls
no test coverage detected