added factory code, and the beginnings of styling

This commit is contained in:
kkoenig1@optonline.com
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 528e1a9031
commit 52ec439ca2
7 changed files with 66 additions and 8 deletions
+14 -3
View File
@@ -59,6 +59,17 @@ extern "C" void my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
#endif
}
/**
* Helper function to translate a colorFlags value to a lv_color_t suitable
* for passing to an lv_obj function
* @param colorFlags a textFlags value. This value will contain the color shifted by 16 bits.
*/
lv_color_t makeLvColor(uint32_t colorFlags)
{
auto color = COLOR_VAL(colorFlags);
return lv_color_make(GET_RED(color), GET_GREEN(color), GET_BLUE(color));
}
lv_obj_t * canvas=nullptr;
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(LCD_W, LCD_H)] __SDRAM;
@@ -70,9 +81,9 @@ LvglWrapper::LvglWrapper()
lv_disp_draw_buf_init(&disp_buf, lcdFront->getData(), lcd->getData(), LCD_W*LCD_H);
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
disp_drv.flush_cb = flushLcd; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = LCD_W; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = LCD_H; /*Set the vertical resolution in pixels*/
disp_drv.flush_cb = flushLcd; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = LCD_W; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = LCD_H; /*Set the vertical resolution in pixels*/
disp_drv.full_refresh = 0;
disp_drv.direct_mode = 0;
#if defined (LCD_VERTICAL_INVERT)
+33
View File
@@ -25,6 +25,39 @@
#include "opentx_types.h"
#include "lvgl/lvgl.h"
extern lv_color_t makeLvColor(uint32_t colorFlags);
class LvglWidgetFactory;
typedef std::function<lv_obj_t *(lv_obj_t *parent)> LvObjConstructor;
typedef std::function<void (LvglWidgetFactory *factory)> LvStyleInitializer;
class LvglWidgetFactory
{
public:
LvglWidgetFactory(LvObjConstructor construct, LvStyleInitializer styleInitializer = nullptr) :
_construct(std::move(construct)),
_styleInitializer(std::move(styleInitializer))
{
lv_style_init(&style);
styleInitialized = false;
};
lv_style_t style;
inline lv_obj_t *construct(lv_obj_t *parent) {
if (!styleInitialized && _styleInitializer != nullptr) {
(_styleInitializer(this));
styleInitialized = true;
}
return _construct(parent);
}
private:
LvObjConstructor _construct;
LvStyleInitializer _styleInitializer;
bool styleInitialized;
};
class LvglWrapper {
public:
LvglWrapper();
+5 -1
View File
@@ -25,10 +25,14 @@
#include "opentx.h"
#include "libopenui.h"
LvglWidgetFactory fullScreenDialogFactory = LvglWidgetFactory([] (lv_obj_t *parent) {
return lv_obj_create(nullptr);
});
FullScreenDialog::FullScreenDialog(
uint8_t type, std::string title, std::string message, std::string action,
const std::function<void(void)>& confirmHandler) :
FormGroup(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE, true),
FormGroup(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE, &fullScreenDialogFactory),
type(type),
title(std::move(title)),
message(std::move(message)),
+6 -1
View File
@@ -44,8 +44,13 @@ void PageHeader::paint(BitmapBuffer * dc)
MENU_HEADER_HEIGHT, COLOR_THEME_SECONDARY1);
}
LvglWidgetFactory pageFactory = LvglWidgetFactory([] (lv_obj_t * parent) {
return lv_obj_create(nullptr);
});
Page::Page(unsigned icon):
Window(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE, 0, true),
Window(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE, 0, &pageFactory),
header(this, icon),
body(this, { 0, MENU_HEADER_HEIGHT, LCD_W, LCD_H - MENU_HEADER_HEIGHT }, FORM_FORWARD_FOCUS)
{
+1 -1
View File
@@ -161,7 +161,7 @@ class SetupWidgetsPage: public FormWindow
{
public:
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx):
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS,true),
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
menu(menu),
customScreenIdx(customScreenIdx)
{
+1 -1
View File
@@ -34,7 +34,7 @@ Topbar * TopbarFactory::create(Window * parent)
}
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(ScreenMenu* menu):
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS, true),
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
menu(menu)
{
// remember focus
+6 -1
View File
@@ -33,8 +33,13 @@
#include "select_fab_carousel.h"
#include "view_text.h"
LvglWidgetFactory viewMainFactory = LvglWidgetFactory([] (lv_obj_t *parent) {
return lv_obj_create(nullptr);
});
ViewMainMenu::ViewMainMenu(Window* parent) :
Window(parent->getFullScreenWindow(), {}, 0, 0, true)
Window(parent->getFullScreenWindow(), {}, 0, 0, &viewMainFactory)
{
// Save focus
Layer::push(this);