Add touch panel port to lvgl.
PoC of user interaction with 3 screen (clock, menu and app).main
parent
52539a5ff1
commit
167a0ffc87
@ -0,0 +1,67 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <libs/date/includes/date/date.h>
|
||||||
|
#include <Components/DateTime/DateTimeController.h>
|
||||||
|
#include <Version.h>
|
||||||
|
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
||||||
|
#include <libs/lvgl/src/lv_font/lv_font.h>
|
||||||
|
#include <libs/lvgl/lvgl.h>
|
||||||
|
#include <libraries/log/nrf_log.h>
|
||||||
|
#include "Tab.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);
|
||||||
|
// screen->OnObjectEvent(obj, event);
|
||||||
|
//}
|
||||||
|
|
||||||
|
Tab::Tab(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
|
||||||
|
/*Create a Tab view object*/
|
||||||
|
lv_obj_t *tabview;
|
||||||
|
tabview = lv_tabview_create(lv_scr_act(), NULL);
|
||||||
|
|
||||||
|
/*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
|
||||||
|
lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1");
|
||||||
|
lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2");
|
||||||
|
lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3");
|
||||||
|
|
||||||
|
|
||||||
|
/*Add content to the tabs*/
|
||||||
|
lv_obj_t * label = lv_label_create(tab1, NULL);
|
||||||
|
lv_label_set_text(label, "This the first tab\n\n"
|
||||||
|
"If the content\n"
|
||||||
|
"of a tab\n"
|
||||||
|
"become too long\n"
|
||||||
|
"the it \n"
|
||||||
|
"automatically\n"
|
||||||
|
"become\n"
|
||||||
|
"scrollable.");
|
||||||
|
|
||||||
|
label = lv_label_create(tab2, NULL);
|
||||||
|
lv_label_set_text(label, "Second tab");
|
||||||
|
|
||||||
|
label = lv_label_create(tab3, NULL);
|
||||||
|
lv_label_set_text(label, "Third tab");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab::~Tab() {
|
||||||
|
lv_obj_clean(lv_scr_act());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tab::Refresh(bool fullRefresh) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tab::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
||||||
|
if(event == LV_EVENT_CLICKED) {
|
||||||
|
NRF_LOG_INFO("Clicked");
|
||||||
|
}
|
||||||
|
else if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
|
NRF_LOG_INFO("Toggled");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <chrono>
|
||||||
|
#include <Components/Gfx/Gfx.h>
|
||||||
|
#include "Screen.h"
|
||||||
|
#include <bits/unique_ptr.h>
|
||||||
|
#include "../Fonts/lcdfont14.h"
|
||||||
|
#include "../Fonts/lcdfont70.h"
|
||||||
|
#include "../../Version.h"
|
||||||
|
#include <lvgl/src/lv_core/lv_style.h>
|
||||||
|
|
||||||
|
namespace Pinetime {
|
||||||
|
namespace Applications {
|
||||||
|
namespace Screens {
|
||||||
|
class Tab : public Screen {
|
||||||
|
public:
|
||||||
|
explicit Tab(DisplayApp* app, Components::Gfx& gfx);
|
||||||
|
~Tab() override;
|
||||||
|
void Refresh(bool fullRefresh) override;
|
||||||
|
void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <libs/date/includes/date/date.h>
|
||||||
|
#include <Components/DateTime/DateTimeController.h>
|
||||||
|
#include <Version.h>
|
||||||
|
#include <libs/lvgl/src/lv_core/lv_obj.h>
|
||||||
|
#include <libs/lvgl/src/lv_font/lv_font.h>
|
||||||
|
#include <libs/lvgl/lvgl.h>
|
||||||
|
#include <libraries/log/nrf_log.h>
|
||||||
|
#include "Tile.h"
|
||||||
|
#include <DisplayApp/DisplayApp.h>
|
||||||
|
#include <libs/lvgl/src/lv_core/lv_style.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);
|
||||||
|
screen->OnObjectEvent(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
//static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""};
|
||||||
|
//static const char * btnm_map2[] = {"App6", "App7", "App8", "\n", "App9", "App10", "App22",""};
|
||||||
|
static const char * btnm_map1[] = {"App1", ""};
|
||||||
|
|
||||||
|
Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) {
|
||||||
|
|
||||||
|
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(tile1, NULL);
|
||||||
|
lv_btnm_set_map(btnm1, btnm_map1);
|
||||||
|
lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES);
|
||||||
|
|
||||||
|
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL));
|
||||||
|
labelStyle->text.font = &jetbrains_mono_bold_20;
|
||||||
|
labelStyle->body.grad_color = labelStyle->body.main_color;
|
||||||
|
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelStyle);
|
||||||
|
lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelStyle);
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tile::Refresh(bool fullRefresh) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
||||||
|
if(event == LV_EVENT_CLICKED) {
|
||||||
|
NRF_LOG_INFO("Clicked");
|
||||||
|
nextScreen = Screen::NextScreen::App;
|
||||||
|
clickCount++;
|
||||||
|
}
|
||||||
|
else if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
|
NRF_LOG_INFO("Toggled");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <chrono>
|
||||||
|
#include <Components/Gfx/Gfx.h>
|
||||||
|
#include "Screen.h"
|
||||||
|
#include <bits/unique_ptr.h>
|
||||||
|
#include "../Fonts/lcdfont14.h"
|
||||||
|
#include "../Fonts/lcdfont70.h"
|
||||||
|
#include "../../Version.h"
|
||||||
|
#include <lvgl/src/lv_core/lv_style.h>
|
||||||
|
|
||||||
|
namespace Pinetime {
|
||||||
|
namespace Applications {
|
||||||
|
namespace Screens {
|
||||||
|
class Tile : public Screen {
|
||||||
|
public:
|
||||||
|
explicit Tile(DisplayApp* app, Components::Gfx& gfx);
|
||||||
|
~Tile() override;
|
||||||
|
void Refresh(bool fullRefresh) override;
|
||||||
|
void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
|
||||||
|
|
||||||
|
void OnButtonPushed() override {nextScreen = NextScreen::Clock;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
|
||||||
|
const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data};
|
||||||
|
|
||||||
|
lv_style_t* labelStyle;
|
||||||
|
lv_obj_t * label1;
|
||||||
|
lv_obj_t * label2;
|
||||||
|
lv_obj_t * label3;
|
||||||
|
|
||||||
|
lv_obj_t* backgroundLabel;
|
||||||
|
lv_obj_t * button;
|
||||||
|
lv_obj_t * labelClick;
|
||||||
|
|
||||||
|
lv_obj_t *tileview;
|
||||||
|
lv_obj_t * tile1;
|
||||||
|
lv_obj_t * tile2;
|
||||||
|
lv_obj_t * list;
|
||||||
|
lv_obj_t * list_btn;
|
||||||
|
lv_obj_t * tile3;
|
||||||
|
lv_obj_t * btn1;
|
||||||
|
lv_obj_t * btn2;
|
||||||
|
lv_obj_t * btn3;
|
||||||
|
|
||||||
|
lv_obj_t * btnm1;
|
||||||
|
lv_obj_t * btnm2;
|
||||||
|
|
||||||
|
uint32_t clickCount = 0 ;
|
||||||
|
uint32_t previousClickCount = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue