diff --git a/radio/src/gui/colorlcd/widget.cpp b/radio/src/gui/colorlcd/widget.cpp index 365e8e6a1..531fc4b31 100644 --- a/radio/src/gui/colorlcd/widget.cpp +++ b/radio/src/gui/colorlcd/widget.cpp @@ -30,15 +30,6 @@ #include "touch.h" #endif -static void openWidgetMenu(Widget * parent) -{ - Menu *menu = new Menu(parent); - menu->addLine("Full screen", [=]() { parent->setFullscreen(true); }); - if (parent->getOptions() && parent->getOptions()->name) - menu->addLine(TR_WIDGET_SETTINGS, - [=]() { new WidgetSettings(parent, parent); }); -} - Widget::Widget(const WidgetFactory* factory, Window* parent, const rect_t &rect, WidgetPersistentData* persistentData) : Button(parent, rect, nullptr, 0, 0, window_create), @@ -48,20 +39,34 @@ Widget::Widget(const WidgetFactory* factory, Window* parent, lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE); lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE); + if (dynamic_cast(parent)) + fsAllowed = false; + setPressHandler([&]() -> uint8_t { // When ViewMain is in "widget select mode", // the widget is added to a focus group - if (!fullscreen && lv_obj_get_group(lvobj)) - openWidgetMenu(this); + if (!fullscreen && lv_obj_get_group(lvobj)) openMenu(); return 0; }); setLongPressHandler([&]() -> uint8_t { - if (!fullscreen) openWidgetMenu(this); + if (!fullscreen) openMenu(); return 0; }); } +void Widget::openMenu() +{ + Menu* menu = new Menu(this); + if (fsAllowed) { + menu->addLine("Full screen", [&]() { setFullscreen(true); }); + } + if (getOptions() && getOptions()->name) { + menu->addLine(TR_WIDGET_SETTINGS, + [=]() { new WidgetSettings(this, this); }); + } +} + void Widget::paint(BitmapBuffer * dc) { if (fullscreen) { @@ -101,6 +106,7 @@ void Widget::update() void Widget::setFullscreen(bool enable) { + if (!fsAllowed) return; if (enable == fullscreen) return; // Leave Fullscreen Mode @@ -152,6 +158,11 @@ void Widget::setFullscreen(bool enable) } } +void Widget::disableFullscreen() +{ + fsAllowed = false; +} + void Widget::onLongPress() { if (!fullscreen) Button::onLongPress(); diff --git a/radio/src/gui/colorlcd/widget.h b/radio/src/gui/colorlcd/widget.h index a2763a4ec..13866611e 100644 --- a/radio/src/gui/colorlcd/widget.h +++ b/radio/src/gui/colorlcd/widget.h @@ -93,6 +93,10 @@ class Widget : public Button // Set/unset fullscreen mode void setFullscreen(bool enable); + // Disable setting fullscreen mode + void disableFullscreen(); + bool isFullscreenAllowed() { return fsAllowed; } + // Called when the widget options have changed virtual void update(); @@ -107,10 +111,13 @@ class Widget : public Button PersistentData * persistentData; uint32_t focusGainedTS = 0; bool fullscreen = false; + bool fsAllowed = true; void onCancel() override; void onLongPress() override; + virtual void onFullscreen(bool enable) {} + void openMenu(); }; void registerWidget(const WidgetFactory * factory);