diff --git a/radio/src/gui/colorlcd/LvglWrapper.cpp b/radio/src/gui/colorlcd/LvglWrapper.cpp index fd3bc46b9..6a4502cbe 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.cpp +++ b/radio/src/gui/colorlcd/LvglWrapper.cpp @@ -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) diff --git a/radio/src/gui/colorlcd/LvglWrapper.h b/radio/src/gui/colorlcd/LvglWrapper.h index 9b9d331c4..7ace3a3a2 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.h +++ b/radio/src/gui/colorlcd/LvglWrapper.h @@ -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 LvObjConstructor; +typedef std::function 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(); diff --git a/radio/src/gui/colorlcd/fullscreen_dialog.cpp b/radio/src/gui/colorlcd/fullscreen_dialog.cpp index 4a32f447d..83c8e1332 100644 --- a/radio/src/gui/colorlcd/fullscreen_dialog.cpp +++ b/radio/src/gui/colorlcd/fullscreen_dialog.cpp @@ -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& 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)), diff --git a/radio/src/gui/colorlcd/page.cpp b/radio/src/gui/colorlcd/page.cpp index 2213fd85a..415ed0014 100644 --- a/radio/src/gui/colorlcd/page.cpp +++ b/radio/src/gui/colorlcd/page.cpp @@ -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) { diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index 5a9e49dfb..1137caa3e 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -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) { diff --git a/radio/src/gui/colorlcd/topbar.cpp b/radio/src/gui/colorlcd/topbar.cpp index 03b263203..63497bc53 100644 --- a/radio/src/gui/colorlcd/topbar.cpp +++ b/radio/src/gui/colorlcd/topbar.cpp @@ -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 diff --git a/radio/src/gui/colorlcd/view_main_menu.cpp b/radio/src/gui/colorlcd/view_main_menu.cpp index 25b80f7c0..f6b1eee7c 100644 --- a/radio/src/gui/colorlcd/view_main_menu.cpp +++ b/radio/src/gui/colorlcd/view_main_menu.cpp @@ -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);