fix(color): Lua widgets may not update when quick menu is open (#6967)
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "etx_lv_theme.h"
|
#include "etx_lv_theme.h"
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
|
#include "view_main.h"
|
||||||
|
|
||||||
// timers_driver.h
|
// timers_driver.h
|
||||||
uint32_t timersGetMsTick();
|
uint32_t timersGetMsTick();
|
||||||
@@ -57,6 +58,8 @@ void MainWindow::run(bool trash)
|
|||||||
{
|
{
|
||||||
auto start = timersGetMsTick();
|
auto start = timersGetMsTick();
|
||||||
|
|
||||||
|
ViewMain::refreshWidgets();
|
||||||
|
|
||||||
auto opaque = Layer::getFirstOpaque();
|
auto opaque = Layer::getFirstOpaque();
|
||||||
if (opaque) {
|
if (opaque) {
|
||||||
opaque->checkEvents();
|
opaque->checkEvents();
|
||||||
|
|||||||
@@ -133,12 +133,6 @@ void Page::onCancel()
|
|||||||
|
|
||||||
void Page::onClicked() { Keyboard::hide(false); }
|
void Page::onClicked() { Keyboard::hide(false); }
|
||||||
|
|
||||||
void Page::checkEvents()
|
|
||||||
{
|
|
||||||
ViewMain::instance()->runBackground();
|
|
||||||
NavWindow::checkEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Page::enableRefresh()
|
void Page::enableRefresh()
|
||||||
{
|
{
|
||||||
lv_obj_enable_style_refresh(true);
|
lv_obj_enable_style_refresh(true);
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ class Page : public NavWindow
|
|||||||
Window* body = nullptr;
|
Window* body = nullptr;
|
||||||
QuickMenu* quickMenu = nullptr;
|
QuickMenu* quickMenu = nullptr;
|
||||||
|
|
||||||
void checkEvents() override;
|
|
||||||
bool bubbleEvents() override { return false; }
|
bool bubbleEvents() override { return false; }
|
||||||
|
|
||||||
NavWindow* navWindow();
|
NavWindow* navWindow();
|
||||||
|
|||||||
@@ -430,6 +430,15 @@ bool Window::isVisible()
|
|||||||
return !_deleted && lvobj && !lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
return !_deleted && lvobj && !lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Window::isOnScreen()
|
||||||
|
{
|
||||||
|
// Check window is at least partially visible
|
||||||
|
if (!isVisible()) return false;
|
||||||
|
lv_area_t a;
|
||||||
|
lv_obj_get_coords(lvobj, &a);
|
||||||
|
return a.x2 >= 0 && a.x1 < LCD_W && a.y2 >= 0 && a.y1 < LCD_H;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::enable(bool enabled)
|
void Window::enable(bool enabled)
|
||||||
{
|
{
|
||||||
if (!_deleted && lvobj) {
|
if (!_deleted && lvobj) {
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ class Window
|
|||||||
virtual void show(bool visible = true);
|
virtual void show(bool visible = true);
|
||||||
void hide() { show(false); }
|
void hide() { show(false); }
|
||||||
bool isVisible();
|
bool isVisible();
|
||||||
|
bool isOnScreen();
|
||||||
virtual void enable(bool enabled = true);
|
virtual void enable(bool enabled = true);
|
||||||
void disable() { enable(false); }
|
void disable() { enable(false); }
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ static void tile_view_scroll_end(lv_event_t* e)
|
|||||||
|
|
||||||
ViewMain* ViewMain::_instance = nullptr;
|
ViewMain* ViewMain::_instance = nullptr;
|
||||||
|
|
||||||
|
ViewMain* ViewMain::instance()
|
||||||
|
{
|
||||||
|
if (!_instance) _instance = new ViewMain();
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
ViewMain::ViewMain() :
|
ViewMain::ViewMain() :
|
||||||
NavWindow(MainWindow::instance(), MainWindow::instance()->getRect())
|
NavWindow(MainWindow::instance(), MainWindow::instance()->getRect())
|
||||||
{
|
{
|
||||||
@@ -178,16 +184,6 @@ void ViewMain::previousMainView()
|
|||||||
|
|
||||||
TopBar* ViewMain::getTopbar() { return topbar; }
|
TopBar* ViewMain::getTopbar() { return topbar; }
|
||||||
|
|
||||||
void ViewMain::enableTopbar()
|
|
||||||
{
|
|
||||||
if (topbar) topbar->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewMain::disableTopbar()
|
|
||||||
{
|
|
||||||
if (topbar) topbar->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewMain::updateTopbarVisibility()
|
void ViewMain::updateTopbarVisibility()
|
||||||
{
|
{
|
||||||
if (!tile_view) return;
|
if (!tile_view) return;
|
||||||
@@ -409,11 +405,18 @@ void ViewMain::hideTopBarEdgeTxButton()
|
|||||||
topbar->setEdgeTxButtonVisible(0.0);
|
topbar->setEdgeTxButtonVisible(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMain::runBackground()
|
void ViewMain::_refreshWidgets()
|
||||||
{
|
{
|
||||||
topbar->runBackground();
|
if (!_deleted) {
|
||||||
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
|
topbar->refreshWidgets(isVisible && hasTopbar());
|
||||||
if (customScreens[i])
|
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
|
||||||
customScreens[i]->runBackground();
|
if (customScreens[i])
|
||||||
|
customScreens[i]->refreshWidgets(isVisible);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewMain::refreshWidgets()
|
||||||
|
{
|
||||||
|
if (_instance) _instance->_refreshWidgets();
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
class QuickMenu;
|
class QuickMenu;
|
||||||
class SetupWidgetsPage;
|
|
||||||
class SetupTopBarWidgetsPage;
|
|
||||||
class TopBar;
|
class TopBar;
|
||||||
|
|
||||||
class ViewMain : public NavWindow
|
class ViewMain : public NavWindow
|
||||||
@@ -37,14 +35,7 @@ class ViewMain : public NavWindow
|
|||||||
public:
|
public:
|
||||||
~ViewMain() override;
|
~ViewMain() override;
|
||||||
|
|
||||||
static ViewMain* instance()
|
static ViewMain* instance();
|
||||||
{
|
|
||||||
if (!_instance) _instance = new ViewMain();
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ViewMain* getInstance() { return _instance; }
|
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override { return "ViewMain"; }
|
std::string getName() const override { return "ViewMain"; }
|
||||||
@@ -52,8 +43,6 @@ class ViewMain : public NavWindow
|
|||||||
|
|
||||||
void addMainView(WidgetsContainer* view, uint32_t viewId);
|
void addMainView(WidgetsContainer* view, uint32_t viewId);
|
||||||
|
|
||||||
void enableTopbar();
|
|
||||||
void disableTopbar();
|
|
||||||
void updateTopbarVisibility();
|
void updateTopbarVisibility();
|
||||||
bool enableWidgetSelect(bool enable);
|
bool enableWidgetSelect(bool enable);
|
||||||
|
|
||||||
@@ -76,7 +65,6 @@ class ViewMain : public NavWindow
|
|||||||
bool onLongPress() override;
|
bool onLongPress() override;
|
||||||
|
|
||||||
void show(bool visible = true) override;
|
void show(bool visible = true) override;
|
||||||
bool viewIsVisible() const { return isVisible; }
|
|
||||||
void showTopBarEdgeTxButton();
|
void showTopBarEdgeTxButton();
|
||||||
void hideTopBarEdgeTxButton();
|
void hideTopBarEdgeTxButton();
|
||||||
|
|
||||||
@@ -85,9 +73,10 @@ class ViewMain : public NavWindow
|
|||||||
bool isAppMode();
|
bool isAppMode();
|
||||||
bool isAppMode(unsigned view);
|
bool isAppMode(unsigned view);
|
||||||
|
|
||||||
void runBackground();
|
|
||||||
void refreshWidgetSelectTimer();
|
void refreshWidgetSelectTimer();
|
||||||
|
|
||||||
|
static void refreshWidgets();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static ViewMain* _instance;
|
static ViewMain* _instance;
|
||||||
|
|
||||||
@@ -100,14 +89,12 @@ class ViewMain : public NavWindow
|
|||||||
|
|
||||||
void deleteLater(bool detach = true, bool trash = true) override;
|
void deleteLater(bool detach = true, bool trash = true) override;
|
||||||
|
|
||||||
// Widget setup requires special permissions ;-)
|
|
||||||
friend class SetupWidgetsPage;
|
|
||||||
friend class SetupTopBarWidgetsPage;
|
|
||||||
|
|
||||||
// Set topbar visibility [0.0 -> 1.0]
|
// Set topbar visibility [0.0 -> 1.0]
|
||||||
void setTopbarVisible(float visible);
|
void setTopbarVisible(float visible);
|
||||||
void setEdgeTxButtonVisible(float visible);
|
void setEdgeTxButtonVisible(float visible);
|
||||||
|
|
||||||
|
void _refreshWidgets();
|
||||||
|
|
||||||
static void ws_timer(lv_timer_t* t);
|
static void ws_timer(lv_timer_t* t);
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
|
|||||||
@@ -108,8 +108,10 @@ class Widget : public ButtonBase
|
|||||||
// Called when the widget options have changed
|
// Called when the widget options have changed
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
// Called at regular time interval, even if the widget cannot be seen
|
// Called at regular time interval if the widget is hidden or off screen
|
||||||
virtual void background() {}
|
virtual void background() {}
|
||||||
|
// Called at regular time interval if the widget is visible and on screen
|
||||||
|
virtual void foreground() {}
|
||||||
|
|
||||||
// Update widget 'zone' data (for Lua widgets)
|
// Update widget 'zone' data (for Lua widgets)
|
||||||
virtual void updateZoneRect(rect_t rect, bool updateUI = true)
|
virtual void updateZoneRect(rect_t rect, bool updateUI = true)
|
||||||
|
|||||||
@@ -83,11 +83,16 @@ void WidgetsContainer::showWidgets(bool visible)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetsContainer::runBackground()
|
void WidgetsContainer::refreshWidgets(bool inForeground)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < zoneCount; i++) {
|
if (!_deleted) {
|
||||||
if (widgets[i]) {
|
for (int i = 0; i < zoneCount; i++) {
|
||||||
widgets[i]->background();
|
if (widgets[i]) {
|
||||||
|
if ((inForeground && widgets[i]->isOnScreen()) || widgets[i]->isFullscreen())
|
||||||
|
widgets[i]->foreground();
|
||||||
|
else
|
||||||
|
widgets[i]->background();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class WidgetsContainer: public Window
|
|||||||
void updateZones();
|
void updateZones();
|
||||||
void showWidgets(bool visible = true);
|
void showWidgets(bool visible = true);
|
||||||
void hideWidgets() { showWidgets(false); }
|
void hideWidgets() { showWidgets(false); }
|
||||||
void runBackground();
|
void refreshWidgets(bool inForeground);
|
||||||
|
|
||||||
virtual bool isLayout() { return false; }
|
virtual bool isLayout() { return false; }
|
||||||
virtual bool isAppMode() const { return false; }
|
virtual bool isAppMode() const { return false; }
|
||||||
|
|||||||
@@ -320,7 +320,6 @@ void PageGroupBase::checkEvents()
|
|||||||
if (currentTab) {
|
if (currentTab) {
|
||||||
currentTab->checkEvents();
|
currentTab->checkEvents();
|
||||||
}
|
}
|
||||||
ViewMain::instance()->runBackground();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageGroupBase::onClicked() { Keyboard::hide(false); }
|
void PageGroupBase::onClicked() { Keyboard::hide(false); }
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ void LuaEventHandler::removeHandler(Window* w)
|
|||||||
void LuaWidget::redraw_cb(lv_event_t* e)
|
void LuaWidget::redraw_cb(lv_event_t* e)
|
||||||
{
|
{
|
||||||
lv_obj_t* target = lv_event_get_target(e);
|
lv_obj_t* target = lv_event_get_target(e);
|
||||||
if (lv_obj_has_flag(target, LV_OBJ_FLAG_HIDDEN)) return;
|
|
||||||
|
|
||||||
LuaWidget* widget = (LuaWidget*)lv_obj_get_user_data(target);
|
LuaWidget* widget = (LuaWidget*)lv_obj_get_user_data(target);
|
||||||
|
|
||||||
@@ -292,47 +291,35 @@ void LuaWidget::onCancel()
|
|||||||
LuaScriptManager::onCancelEvent();
|
LuaScriptManager::onCancelEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaWidget::checkEvents()
|
void LuaWidget::foreground()
|
||||||
{
|
{
|
||||||
Widget::checkEvents();
|
|
||||||
|
|
||||||
if (closeFS) {
|
if (closeFS) {
|
||||||
closeFS = false;
|
closeFS = false;
|
||||||
setFullscreen(false);
|
setFullscreen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// refresh() has not been called
|
// Check widget is at least partially visible
|
||||||
if (!refreshed)
|
if (isOnScreen()) {
|
||||||
background();
|
if (useLvglLayout()) {
|
||||||
|
auto save = luaScriptManager;
|
||||||
refreshed = false;
|
PROTECT_LUA() {
|
||||||
|
luaScriptManager = this;
|
||||||
if (useLvglLayout()) {
|
refresh(nullptr);
|
||||||
if (!lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN)) {
|
if (!errorMessage) {
|
||||||
lv_area_t a;
|
if (!callRefs(lsWidgets)) {
|
||||||
lv_obj_get_coords(lvobj, &a);
|
setErrorMessage("function");
|
||||||
// Check widget is at least partially visible
|
|
||||||
if (a.x2 >= 0 && a.x1 < LCD_W) {
|
|
||||||
auto save = luaScriptManager;
|
|
||||||
PROTECT_LUA() {
|
|
||||||
luaScriptManager = this;
|
|
||||||
refresh(nullptr);
|
|
||||||
if (!errorMessage) {
|
|
||||||
if (!callRefs(lsWidgets)) {
|
|
||||||
setErrorMessage("function");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
refreshInstructionsPercent = instructionsPercent;
|
|
||||||
} else {
|
|
||||||
setErrorMessage("function");
|
|
||||||
}
|
}
|
||||||
luaScriptManager = save;
|
refreshInstructionsPercent = instructionsPercent;
|
||||||
UNPROTECT_LUA();
|
} else {
|
||||||
|
setErrorMessage("function");
|
||||||
}
|
}
|
||||||
|
luaScriptManager = save;
|
||||||
|
UNPROTECT_LUA();
|
||||||
|
} else {
|
||||||
|
// Force call to redraw_cb()
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Force call to redraw_cb()
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
@@ -537,9 +524,6 @@ void LuaWidget::refresh(BitmapBuffer* dc)
|
|||||||
// Remove LCD
|
// Remove LCD
|
||||||
luaLcdAllowed = lla;
|
luaLcdAllowed = lla;
|
||||||
luaLcdBuffer = nullptr;
|
luaLcdBuffer = nullptr;
|
||||||
|
|
||||||
// mark as refreshed
|
|
||||||
refreshed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaWidget::background()
|
void LuaWidget::background()
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class LuaWidget : public Widget, public LuaScriptManager
|
|||||||
const char* getErrorMessage() const override;
|
const char* getErrorMessage() const override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void background() override;
|
void background() override;
|
||||||
|
void foreground() override;
|
||||||
|
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
@@ -148,12 +149,10 @@ class LuaWidget : public Widget, public LuaScriptManager
|
|||||||
int zoneRectDataRef;
|
int zoneRectDataRef;
|
||||||
int optionsDataRef;
|
int optionsDataRef;
|
||||||
char* errorMessage;
|
char* errorMessage;
|
||||||
bool refreshed = false;
|
|
||||||
|
|
||||||
// Window interface
|
// Window interface
|
||||||
void onClicked() override;
|
void onClicked() override;
|
||||||
void onCancel() override;
|
void onCancel() override;
|
||||||
void checkEvents() override;
|
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
|
|
||||||
// Widget interface
|
// Widget interface
|
||||||
|
|||||||
Reference in New Issue
Block a user