2021-10-13 16:08:35 -04:00
|
|
|
#include "displayapp/screens/List.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
2022-07-22 00:43:58 -04:00
|
|
|
#include "displayapp/InfiniTimeTheme.h"
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2022-04-09 06:37:31 -04:00
|
|
|
void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* screen = static_cast<List*>(obj->user_data);
|
2021-04-03 22:08:51 -04:00
|
|
|
screen->OnButtonEvent(obj, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
List::List(uint8_t screenID,
|
|
|
|
uint8_t numScreens,
|
|
|
|
DisplayApp* app,
|
|
|
|
Controllers::Settings& settingsController,
|
|
|
|
std::array<Applications, MAXLISTITEMS>& applications)
|
2022-07-05 01:41:09 -04:00
|
|
|
: Screen(app), settingsController {settingsController}, pageIndicator(screenID, numScreens) {
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
// Set the background to Black
|
|
|
|
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0, 0, 0));
|
|
|
|
|
|
|
|
settingsController.SetSettingsMenu(screenID);
|
|
|
|
|
2022-07-05 01:41:09 -04:00
|
|
|
pageIndicator.Create();
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
|
|
|
static constexpr int innerPad = 4;
|
|
|
|
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, innerPad);
|
|
|
|
lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_obj_set_pos(container, 0, 0);
|
|
|
|
lv_obj_set_width(container, LV_HOR_RES - 8);
|
|
|
|
lv_obj_set_height(container, LV_VER_RES);
|
|
|
|
lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
for (int i = 0; i < MAXLISTITEMS; i++) {
|
2021-04-03 22:08:51 -04:00
|
|
|
apps[i] = applications[i].application;
|
2021-04-18 13:28:14 -04:00
|
|
|
if (applications[i].application != Apps::None) {
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2022-07-22 00:43:58 -04:00
|
|
|
static constexpr int btnHeight = (LV_HOR_RES_MAX - ((MAXLISTITEMS - 1) * innerPad)) / MAXLISTITEMS;
|
|
|
|
itemApps[i] = lv_btn_create(container, nullptr);
|
|
|
|
lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, btnHeight / 3);
|
|
|
|
lv_obj_set_style_local_bg_color(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_width(itemApps[i], LV_HOR_RES - 8);
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_obj_set_height(itemApps[i], btnHeight);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_event_cb(itemApps[i], ButtonEventHandler);
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_btn_set_layout(itemApps[i], LV_LAYOUT_OFF);
|
2021-04-03 22:08:51 -04:00
|
|
|
itemApps[i]->user_data = this;
|
2022-07-22 00:43:58 -04:00
|
|
|
lv_obj_set_style_local_clip_corner(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, true);
|
|
|
|
|
|
|
|
lv_obj_t* icon = lv_label_create(itemApps[i], nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
|
|
|
lv_label_set_text_static(icon, applications[i].icon);
|
|
|
|
lv_label_set_long_mode(icon, LV_LABEL_LONG_CROP);
|
|
|
|
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_set_width(icon, btnHeight);
|
|
|
|
lv_obj_align(icon, nullptr, LV_ALIGN_IN_LEFT_MID, 0, 0);
|
|
|
|
|
|
|
|
lv_obj_t* text = lv_label_create(itemApps[i], nullptr);
|
|
|
|
lv_label_set_text_fmt(text, "%s", applications[i].name);
|
|
|
|
lv_obj_align(text, icon, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
List::~List() {
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
2021-07-15 07:11:27 -04:00
|
|
|
if (event == LV_EVENT_CLICKED) {
|
2021-04-18 13:28:14 -04:00
|
|
|
for (int i = 0; i < MAXLISTITEMS; i++) {
|
|
|
|
if (apps[i] != Apps::None && object == itemApps[i]) {
|
2021-04-15 10:55:01 -04:00
|
|
|
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up);
|
2021-04-03 22:08:51 -04:00
|
|
|
running = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|