InfiniTime.git

ref: 0195ece317d15bcba7dfbd74b58bb8dbcd3bca0a

src/DisplayApp/Screens/Tile.cpp


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <libs/lvgl/src/lv_core/lv_obj.h>
#include <libs/lvgl/src/lv_font/lv_font.h>
#include <libs/lvgl/lvgl.h>
#include "Tile.h"
#include <DisplayApp/DisplayApp.h>


using namespace Pinetime::Applications::Screens;

extern lv_font_t jetbrains_mono_bold_20;

static void event_handler(lv_obj_t * obj, lv_event_t event) {
  Tile* screen = static_cast<Tile *>(obj->user_data);
  uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data();
  uint32_t eventData = *eventDataPtr;
  screen->OnObjectEvent(obj, event, eventData);
}

static const char * btnm_map1[] = {"Meter", "Gauge", "Clock", "\n", "Soft\nversion", "App2", "Brightness", ""};

Tile::Tile(DisplayApp* app) : Screen(app) {
  modal.reset(new Modal(app));
/*
  static lv_point_t valid_pos[] = {{0,0}, {LV_COORD_MIN, LV_COORD_MIN}};
  tileview = lv_tileview_create(lv_scr_act(), NULL);
  lv_tileview_set_valid_positions(tileview, valid_pos, 1);
  lv_tileview_set_edge_flash(tileview, false);

  tile1 = lv_obj_create(tileview, NULL);
  lv_obj_set_pos(tile1, 0, 0);
  lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES);
  lv_tileview_add_element(tileview, tile1);
*/
  btnm1 = lv_btnm_create(lv_scr_act(), NULL);
  lv_btnm_set_map(btnm1, btnm_map1);
  lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES);

//  labelRelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
//  labelRelStyle->text.font = &jetbrains_mono_bold_20;
//  labelRelStyle->body.grad_color = labelRelStyle->body.main_color;
//  lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelRelStyle);
//
//  labelPrStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_PR));
//  labelPrStyle->text.font = &jetbrains_mono_bold_20;
//  labelPrStyle->body.grad_color = labelPrStyle->body.shadow.color;



//  lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelPrStyle);
//TODO better style handling
//  lv_obj_align(btnm1, tile1, LV_ALIGN_CENTER, 0, 0);
  btnm1->user_data = this;
  lv_obj_set_event_cb(btnm1, event_handler);

/*
  tile2 = lv_obj_create(tileview, NULL);
  lv_obj_set_pos(tile2, 0, LV_VER_RES);
  lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES);
  lv_tileview_add_element(tileview, tile2);

  btnm2 = lv_btnm_create(tileview, NULL);
  lv_btnm_set_map(btnm2, btnm_map2);
  lv_obj_align(btnm2, tile2, LV_ALIGN_CENTER, 0, 0);
*/
/*
  tile1 = lv_obj_create(tileview, NULL);
  lv_obj_set_pos(tile1, 0, 0);
  lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES);
  lv_tileview_add_element(tileview, tile1);

  btn1 = lv_btn_create(tile1, NULL);
  lv_obj_align(btn1, tile1, LV_ALIGN_CENTER, 0, 0);

  label1 = lv_label_create(btn1, NULL);
  lv_label_set_text(label1, "Button1");
*/
/*
  tile2 = lv_obj_create(tileview, NULL);
  lv_obj_set_pos(tile2, 0, LV_VER_RES);
  lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES);
  lv_tileview_add_element(tileview, tile2);

  btn2 = lv_btn_create(tile2, NULL);
  lv_obj_align(btn2, tile2, LV_ALIGN_CENTER, 0, 0);


  label2 = lv_label_create(btn2, NULL);
  lv_label_set_text(label2, "Button2");

  tile3 = lv_obj_create(tileview, NULL);
  lv_obj_set_pos(tile3, 0, LV_VER_RES*2);
  lv_obj_set_size(tile3, LV_HOR_RES, LV_VER_RES);
  lv_tileview_add_element(tileview, tile3);

  btn3 = lv_btn_create(tile3, NULL);
  lv_obj_align(btn3, tile3, LV_ALIGN_CENTER, 0, 0);


  label3 = lv_label_create(btn3, NULL);
  lv_label_set_text(label3, "Button3");
*/
}

Tile::~Tile() {
  lv_obj_clean(lv_scr_act());
}

bool Tile::Refresh() {
  return running;
}

void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) {
  auto* tile = static_cast<Tile*>(obj->user_data);
  if(event == LV_EVENT_VALUE_CHANGED) {
    switch(buttonId) {
      case 0:
        tile->StartMeterApp();
        break;
      case 1:
        tile->StartGaugeApp();
        break;
      case 2:
        tile->StartClockApp();
        break;
      case 3:
        char versionStr[20];
        sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch());
        modal->Show(versionStr);
        break;
      case 4:
        tile->StartSysInfoApp();
        break;
      case 5:
        tile->StartBrightnessApp();

        break;
    }
    clickCount++;
  }
}

bool Tile::OnButtonPushed() {
  app->StartApp(DisplayApp::Apps::Clock);
  running = false;
  return true;
}

void Tile::StartClockApp() {
  app->StartApp(DisplayApp::Apps::Clock);
  running = false;
}

void Tile::StartSysInfoApp() {
  app->StartApp(DisplayApp::Apps::SysInfo);
  running = false;
}

void Tile::StartBrightnessApp() {
  app->StartApp(DisplayApp::Apps::Brightness);
  running = false;
}

void Tile::StartMeterApp() {
  app->StartApp(DisplayApp::Apps::Meter);
  running = false;
}

void Tile::StartGaugeApp() {
  app->StartApp(DisplayApp::Apps::Gauge);
  running = false;
}