widget: fixed full screen mode

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 12f51350ce
commit 52e988205e
4 changed files with 36 additions and 56 deletions
+14
View File
@@ -155,6 +155,20 @@ static bool hasTopbar(unsigned view)
return false;
}
void ViewMain::enableTopbar()
{
if (topbar && topbar->getLvObj()) {
lv_obj_clear_flag(topbar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
}
void ViewMain::disableTopbar()
{
if (topbar && topbar->getLvObj()) {
lv_obj_add_flag(topbar->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
}
void ViewMain::updateTopbarVisibility()
{
if (!tile_view) return;
+3 -1
View File
@@ -54,7 +54,9 @@ class ViewMain: public Window
#endif
void addMainView(Window* view, uint32_t viewId);
void enableTopbar();
void disableTopbar();
void updateTopbarVisibility();
// Get the available space in the middle of the screen
+18 -50
View File
@@ -35,13 +35,10 @@ constexpr uint32_t WIDGET_FOCUS_TIMEOUT = 10*1000; // 10 seconds
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);
});
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, FormGroup *parent,
@@ -49,15 +46,15 @@ Widget::Widget(const WidgetFactory *factory, FormGroup *parent,
Button(parent, rect), factory(factory), persistentData(persistentData)
{
setFocusHandler([&](bool focus) {
if (focus) { // gained focus
focusGainedTS = RTOS_GET_MS();
}
});
if (focus) { // gained focus
focusGainedTS = RTOS_GET_MS();
}
});
setPressHandler([&]() -> uint8_t {
openWidgetMenu(this);
return 0;
});
if (!fullscreen) openWidgetMenu(this);
return 0;
});
}
void Widget::checkEvents()
@@ -70,37 +67,6 @@ void Widget::checkEvents()
}
}
#if defined(HARDWARE_TOUCH)
bool Widget::onTouchEnd(coord_t x, coord_t y)
{
TRACE_WINDOWS("Widget received touch end (%d) x=%d;y=%d",
hasFocus(), x, y);
if (hasFocus()) {
// TODO: find a better way
// if (touchState.tapCount == 0)
// onPress();
// else
if (touchState.tapCount > 1)
setFullscreen(true);
}
else {
setFocus();
}
return true;
}
bool Widget::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY,
coord_t slideX, coord_t slideY)
{
TRACE_WINDOWS("Widget touch slide");
if (fullscreen) { return true; }
return false;
}
#endif
void Widget::paint(BitmapBuffer * dc)
{
@@ -154,20 +120,21 @@ void Widget::update()
}
}
void Widget::setFullscreen(bool fullscreen)
void Widget::setFullscreen(bool enable)
{
if (fullscreen == this->fullscreen) return;
if (enable == fullscreen) return;
// Leave Fullscreen Mode
if (!fullscreen) {
if (!enable) {
// Reset all zones in container
Widget::update();
setWindowFlags(getWindowFlags() & ~OPAQUE);
// and give up focus
ViewMain::instance()->enableTopbar();
ViewMain::instance()->setFocus();
this->fullscreen = false;
fullscreen = false;
}
// Enter Fullscreen Mode
else {
@@ -175,7 +142,8 @@ void Widget::setFullscreen(bool fullscreen)
// Set window opaque (inhibits redraw from windows bellow)
setWindowFlags(getWindowFlags() | OPAQUE);
setRect(parent->getRect());
this->fullscreen = true;
fullscreen = true;
ViewMain::instance()->disableTopbar();
bringToTop();
}
}
+1 -5
View File
@@ -86,17 +86,13 @@ class Widget : public Button
void checkEvents() override;
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override;
#endif
void paint(BitmapBuffer * dc) override;
// Widget interface
// Set/unset fullscreen mode
void setFullscreen(bool fullscreen);
void setFullscreen(bool enable);
// Called when the widget options have changed
virtual void update();