2020-01-18 17:17:52 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <libs/date/includes/date/date.h>
|
|
|
|
#include <Components/DateTime/DateTimeController.h>
|
|
|
|
#include <Version.h>
|
2020-02-08 17:01:02 +00:00
|
|
|
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
2020-02-10 20:05:33 +00:00
|
|
|
#include <libs/lvgl/src/lv_font/lv_font.h>
|
2020-02-08 17:01:02 +00:00
|
|
|
#include <libs/lvgl/lvgl.h>
|
2020-02-16 17:32:36 +00:00
|
|
|
#include <libraries/log/nrf_log.h>
|
2020-01-18 17:17:52 +00:00
|
|
|
#include "Message.h"
|
2020-02-16 17:32:36 +00:00
|
|
|
#include <DisplayApp/DisplayApp.h>
|
|
|
|
|
2020-01-18 17:17:52 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2020-02-16 17:32:36 +00:00
|
|
|
extern lv_font_t jetbrains_mono_bold_20;
|
|
|
|
|
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|
|
|
Message* screen = static_cast<Message *>(obj->user_data);
|
|
|
|
screen->OnObjectEvent(obj, event);
|
|
|
|
}
|
|
|
|
|
2020-02-23 15:14:03 +00:00
|
|
|
Message::Message(DisplayApp* app) : Screen(app) {
|
2020-02-16 17:32:36 +00:00
|
|
|
|
|
|
|
backgroundLabel = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
backgroundLabel->user_data = this;
|
|
|
|
|
|
|
|
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(backgroundLabel, LV_LABEL_STYLE_MAIN));
|
|
|
|
labelStyle->text.font = &jetbrains_mono_bold_20;
|
|
|
|
|
|
|
|
lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle);
|
|
|
|
lv_obj_set_click(backgroundLabel, true);
|
|
|
|
lv_obj_set_event_cb(backgroundLabel, event_handler);
|
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text(backgroundLabel, "");
|
|
|
|
// lv_obj_align(backgroundLabel, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
|
|
|
|
button = lv_btn_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_event_cb(button, event_handler);
|
|
|
|
lv_obj_align(button, NULL, LV_ALIGN_CENTER, 0, -40);
|
|
|
|
button->user_data = this;
|
|
|
|
|
|
|
|
label = lv_label_create(button, NULL);
|
|
|
|
lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle);
|
|
|
|
lv_label_set_text(label, "Hello!");
|
|
|
|
|
|
|
|
labelClick = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_style(labelClick, LV_LABEL_STYLE_MAIN, labelStyle);
|
|
|
|
lv_obj_align(labelClick, button, LV_ALIGN_OUT_BOTTOM_MID, 0, 30);
|
|
|
|
lv_label_set_text(labelClick, "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
Message::~Message() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
2020-02-10 20:05:33 +00:00
|
|
|
|
2020-02-23 15:14:03 +00:00
|
|
|
bool Message::Refresh() {
|
2020-02-16 17:32:36 +00:00
|
|
|
if(previousClickCount != clickCount) {
|
|
|
|
lv_label_set_text_fmt(labelClick, "%d", clickCount);
|
|
|
|
previousClickCount = clickCount;
|
2020-01-18 17:17:52 +00:00
|
|
|
}
|
2020-02-23 15:14:03 +00:00
|
|
|
|
|
|
|
return running;
|
2020-02-16 17:32:36 +00:00
|
|
|
}
|
2020-02-08 17:01:02 +00:00
|
|
|
|
2020-02-16 17:32:36 +00:00
|
|
|
void Message::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
if(obj == backgroundLabel) {
|
|
|
|
if(event == LV_EVENT_CLICKED) {
|
|
|
|
app->PushMessage(DisplayApp::Messages::SwitchScreen);
|
|
|
|
NRF_LOG_INFO("SCREEN");
|
|
|
|
}
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event == LV_EVENT_CLICKED) {
|
|
|
|
NRF_LOG_INFO("Clicked");
|
|
|
|
clickCount++;
|
|
|
|
}
|
|
|
|
else if(event == LV_EVENT_VALUE_CHANGED) {
|
|
|
|
NRF_LOG_INFO("Toggled");
|
|
|
|
}
|
2020-01-18 17:17:52 +00:00
|
|
|
}
|
2020-02-23 15:14:03 +00:00
|
|
|
|
|
|
|
bool Message::OnButtonPushed() {
|
|
|
|
running = false;
|
|
|
|
return true;
|
|
|
|
}
|