fix(color): Disallow fullscreen mode for topbar widgets (#2327)
Related #2182
This commit is contained in:
@@ -30,15 +30,6 @@
|
|||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
#endif
|
#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,
|
Widget::Widget(const WidgetFactory* factory, Window* parent,
|
||||||
const rect_t &rect, WidgetPersistentData* persistentData) :
|
const rect_t &rect, WidgetPersistentData* persistentData) :
|
||||||
Button(parent, rect, nullptr, 0, 0, window_create),
|
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_SCROLLABLE);
|
||||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||||
|
|
||||||
|
if (dynamic_cast<Topbar*>(parent))
|
||||||
|
fsAllowed = false;
|
||||||
|
|
||||||
setPressHandler([&]() -> uint8_t {
|
setPressHandler([&]() -> uint8_t {
|
||||||
// When ViewMain is in "widget select mode",
|
// When ViewMain is in "widget select mode",
|
||||||
// the widget is added to a focus group
|
// the widget is added to a focus group
|
||||||
if (!fullscreen && lv_obj_get_group(lvobj))
|
if (!fullscreen && lv_obj_get_group(lvobj)) openMenu();
|
||||||
openWidgetMenu(this);
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
setLongPressHandler([&]() -> uint8_t {
|
setLongPressHandler([&]() -> uint8_t {
|
||||||
if (!fullscreen) openWidgetMenu(this);
|
if (!fullscreen) openMenu();
|
||||||
return 0;
|
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)
|
void Widget::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
@@ -101,6 +106,7 @@ void Widget::update()
|
|||||||
|
|
||||||
void Widget::setFullscreen(bool enable)
|
void Widget::setFullscreen(bool enable)
|
||||||
{
|
{
|
||||||
|
if (!fsAllowed) return;
|
||||||
if (enable == fullscreen) return;
|
if (enable == fullscreen) return;
|
||||||
|
|
||||||
// Leave Fullscreen Mode
|
// Leave Fullscreen Mode
|
||||||
@@ -152,6 +158,11 @@ void Widget::setFullscreen(bool enable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::disableFullscreen()
|
||||||
|
{
|
||||||
|
fsAllowed = false;
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::onLongPress()
|
void Widget::onLongPress()
|
||||||
{
|
{
|
||||||
if (!fullscreen) Button::onLongPress();
|
if (!fullscreen) Button::onLongPress();
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ class Widget : public Button
|
|||||||
// Set/unset fullscreen mode
|
// Set/unset fullscreen mode
|
||||||
void setFullscreen(bool enable);
|
void setFullscreen(bool enable);
|
||||||
|
|
||||||
|
// Disable setting fullscreen mode
|
||||||
|
void disableFullscreen();
|
||||||
|
bool isFullscreenAllowed() { return fsAllowed; }
|
||||||
|
|
||||||
// Called when the widget options have changed
|
// Called when the widget options have changed
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
@@ -107,10 +111,13 @@ class Widget : public Button
|
|||||||
PersistentData * persistentData;
|
PersistentData * persistentData;
|
||||||
uint32_t focusGainedTS = 0;
|
uint32_t focusGainedTS = 0;
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
|
bool fsAllowed = true;
|
||||||
|
|
||||||
void onCancel() override;
|
void onCancel() override;
|
||||||
void onLongPress() override;
|
void onLongPress() override;
|
||||||
|
|
||||||
virtual void onFullscreen(bool enable) {}
|
virtual void onFullscreen(bool enable) {}
|
||||||
|
void openMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
void registerWidget(const WidgetFactory * factory);
|
void registerWidget(const WidgetFactory * factory);
|
||||||
|
|||||||
Reference in New Issue
Block a user