2021-04-03 22:08:51 -04:00
|
|
|
#include "List.h"
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "Symbols.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
2021-04-18 13:28:14 -04:00
|
|
|
static void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
List* 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)
|
|
|
|
: Screen(app), settingsController {settingsController} {
|
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);
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
if (numScreens > 1) {
|
2021-06-13 05:47:12 -04:00
|
|
|
pageIndicatorBasePoints[0].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorBasePoints[0].y = 0;
|
|
|
|
pageIndicatorBasePoints[1].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorBasePoints[1].y = LV_VER_RES;
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
pageIndicatorBase = lv_line_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
|
|
|
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2);
|
|
|
|
|
2021-06-13 05:47:12 -04:00
|
|
|
const uint16_t indicatorSize = LV_VER_RES / numScreens;
|
|
|
|
const uint16_t indicatorPos = indicatorSize * screenID;
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-06-13 05:47:12 -04:00
|
|
|
pageIndicatorPoints[0].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorPoints[0].y = indicatorPos;
|
|
|
|
pageIndicatorPoints[1].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorPoints[1].y = indicatorPos + indicatorSize;
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
pageIndicator = lv_line_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
|
|
|
lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
|
|
|
|
|
|
|
|
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 4);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
|
|
|
|
|
|
|
|
lv_obj_set_pos(container1, 0, 0);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_width(container1, LV_HOR_RES - 8);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_height(container1, LV_VER_RES);
|
|
|
|
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
lv_obj_t* labelBt;
|
|
|
|
lv_obj_t* labelBtIco;
|
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
|
|
|
|
|
|
|
itemApps[i] = lv_btn_create(container1, nullptr);
|
|
|
|
lv_obj_set_style_local_bg_opa(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 57);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_bg_color(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
|
|
|
|
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_width(itemApps[i], LV_HOR_RES - 8);
|
|
|
|
lv_obj_set_height(itemApps[i], 57);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_event_cb(itemApps[i], ButtonEventHandler);
|
|
|
|
lv_btn_set_layout(itemApps[i], LV_LAYOUT_ROW_MID);
|
|
|
|
itemApps[i]->user_data = this;
|
|
|
|
|
|
|
|
labelBtIco = lv_label_create(itemApps[i], nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
|
|
|
lv_label_set_text_static(labelBtIco, applications[i].icon);
|
|
|
|
|
|
|
|
labelBt = lv_label_create(itemApps[i], nullptr);
|
|
|
|
lv_label_set_text_fmt(labelBt, " %s", applications[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, LV_HOR_RES, LV_VER_RES);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text_static(backgroundLabel, "");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|