fix(color): Disallow fullscreen mode for topbar widgets (#2327)

Related #2182
This commit is contained in:
Raphael Coeffic
2022-09-18 13:15:01 +10:00
committed by GitHub
parent c2b1b6febf
commit 3765e678b9
2 changed files with 30 additions and 12 deletions
+23 -12
View File
@@ -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<Topbar*>(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();
+7
View File
@@ -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);