widget: fixed full screen mode
This commit is contained in:
committed by
Raphael Coeffic
parent
12f51350ce
commit
52e988205e
@@ -155,6 +155,20 @@ static bool hasTopbar(unsigned view)
|
|||||||
return false;
|
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()
|
void ViewMain::updateTopbarVisibility()
|
||||||
{
|
{
|
||||||
if (!tile_view) return;
|
if (!tile_view) return;
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ class ViewMain: public Window
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void addMainView(Window* view, uint32_t viewId);
|
void addMainView(Window* view, uint32_t viewId);
|
||||||
|
|
||||||
|
void enableTopbar();
|
||||||
|
void disableTopbar();
|
||||||
void updateTopbarVisibility();
|
void updateTopbarVisibility();
|
||||||
|
|
||||||
// Get the available space in the middle of the screen
|
// Get the available space in the middle of the screen
|
||||||
|
|||||||
@@ -35,13 +35,10 @@ constexpr uint32_t WIDGET_FOCUS_TIMEOUT = 10*1000; // 10 seconds
|
|||||||
static void openWidgetMenu(Widget * parent)
|
static void openWidgetMenu(Widget * parent)
|
||||||
{
|
{
|
||||||
Menu *menu = new Menu(parent);
|
Menu *menu = new Menu(parent);
|
||||||
menu->addLine("Full screen", [=]() {
|
menu->addLine("Full screen", [=]() { parent->setFullscreen(true); });
|
||||||
parent->setFullscreen(true);
|
if (parent->getOptions() && parent->getOptions()->name)
|
||||||
});
|
menu->addLine(TR_WIDGET_SETTINGS,
|
||||||
if(parent->getOptions() && parent->getOptions()->name)
|
[=]() { new WidgetSettings(parent, parent); });
|
||||||
menu->addLine(TR_WIDGET_SETTINGS, [=]() {
|
|
||||||
new WidgetSettings(parent, parent);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::Widget(const WidgetFactory *factory, FormGroup *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)
|
Button(parent, rect), factory(factory), persistentData(persistentData)
|
||||||
{
|
{
|
||||||
setFocusHandler([&](bool focus) {
|
setFocusHandler([&](bool focus) {
|
||||||
if (focus) { // gained focus
|
if (focus) { // gained focus
|
||||||
focusGainedTS = RTOS_GET_MS();
|
focusGainedTS = RTOS_GET_MS();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setPressHandler([&]() -> uint8_t {
|
setPressHandler([&]() -> uint8_t {
|
||||||
openWidgetMenu(this);
|
if (!fullscreen) openWidgetMenu(this);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::checkEvents()
|
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)
|
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
|
// Leave Fullscreen Mode
|
||||||
if (!fullscreen) {
|
if (!enable) {
|
||||||
|
|
||||||
// Reset all zones in container
|
// Reset all zones in container
|
||||||
Widget::update();
|
Widget::update();
|
||||||
setWindowFlags(getWindowFlags() & ~OPAQUE);
|
setWindowFlags(getWindowFlags() & ~OPAQUE);
|
||||||
|
|
||||||
// and give up focus
|
// and give up focus
|
||||||
|
ViewMain::instance()->enableTopbar();
|
||||||
ViewMain::instance()->setFocus();
|
ViewMain::instance()->setFocus();
|
||||||
this->fullscreen = false;
|
fullscreen = false;
|
||||||
}
|
}
|
||||||
// Enter Fullscreen Mode
|
// Enter Fullscreen Mode
|
||||||
else {
|
else {
|
||||||
@@ -175,7 +142,8 @@ void Widget::setFullscreen(bool fullscreen)
|
|||||||
// Set window opaque (inhibits redraw from windows bellow)
|
// Set window opaque (inhibits redraw from windows bellow)
|
||||||
setWindowFlags(getWindowFlags() | OPAQUE);
|
setWindowFlags(getWindowFlags() | OPAQUE);
|
||||||
setRect(parent->getRect());
|
setRect(parent->getRect());
|
||||||
this->fullscreen = true;
|
fullscreen = true;
|
||||||
|
ViewMain::instance()->disableTopbar();
|
||||||
bringToTop();
|
bringToTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,17 +86,13 @@ class Widget : public Button
|
|||||||
void checkEvents() override;
|
void checkEvents() override;
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void onEvent(event_t event) override;
|
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
|
#endif
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
// Widget interface
|
// Widget interface
|
||||||
|
|
||||||
// Set/unset fullscreen mode
|
// Set/unset fullscreen mode
|
||||||
void setFullscreen(bool fullscreen);
|
void setFullscreen(bool enable);
|
||||||
|
|
||||||
// Called when the widget options have changed
|
// Called when the widget options have changed
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|||||||
Reference in New Issue
Block a user