Fixes and and a hint message on how to exit fullscreen mode.

This commit is contained in:
Raphael Coeffic
2021-05-06 12:55:59 +02:00
committed by Raphael Coeffic
parent d470092952
commit 8ff852a560
2 changed files with 15 additions and 12 deletions
+13 -11
View File
@@ -26,6 +26,7 @@
#include "lcd.h" #include "lcd.h"
constexpr uint32_t WIDGET_FOCUS_TIMEOUT = 10*1000; // 10 seconds constexpr uint32_t WIDGET_FOCUS_TIMEOUT = 10*1000; // 10 seconds
constexpr uint32_t FULLSCREEN_HINT_DELAY = 5*1000; // 5 seconds
static void openWidgetMenu(Widget * parent) static void openWidgetMenu(Widget * parent)
{ {
@@ -44,7 +45,7 @@ Widget::Widget(const WidgetFactory *factory, FormGroup *parent,
{ {
setFocusHandler([&](bool focus) { setFocusHandler([&](bool focus) {
if (focus) { // gained focus if (focus) { // gained focus
focusGainedTimestamp = RTOS_GET_MS(); focusGainedTS = RTOS_GET_MS();
} }
}); });
} }
@@ -54,7 +55,7 @@ void Widget::checkEvents()
Button::checkEvents(); Button::checkEvents();
// Give the focus back to ViewMain after WIDGET_FOCUS_TIMEOUT milliseconds // Give the focus back to ViewMain after WIDGET_FOCUS_TIMEOUT milliseconds
if (hasFocus() && (RTOS_GET_MS() - focusGainedTimestamp >= WIDGET_FOCUS_TIMEOUT)) { if (!fullscreen && hasFocus() && (RTOS_GET_MS() - focusGainedTS >= WIDGET_FOCUS_TIMEOUT)) {
ViewMain::instance()->setFocus(); ViewMain::instance()->setFocus();
} }
} }
@@ -72,12 +73,17 @@ void Widget::paint(BitmapBuffer * dc)
if (hasFocus() && !fullscreen) { if (hasFocus() && !fullscreen) {
// Blink from haft-time before expiring (5s) // Blink from haft-time before expiring (5s)
if ((RTOS_GET_MS() - focusGainedTimestamp >= WIDGET_FOCUS_TIMEOUT / 2) if ((RTOS_GET_MS() - focusGainedTS >= WIDGET_FOCUS_TIMEOUT / 2)
&& !FAST_BLINK_ON_PHASE) { && !FAST_BLINK_ON_PHASE) {
return; return;
} }
dc->drawRect(0, 0, width(), height(), 2, STASHED, CHECKBOX_COLOR); dc->drawRect(0, 0, width(), height(), 2, STASHED, CHECKBOX_COLOR);
} }
if (fullscreen && (RTOS_GET_MS() - fsStartedTS < FULLSCREEN_HINT_DELAY)) {
dc->drawText(width() / 2, height() / 2, "Press [RTN] long to exit",
FONT(XL) | CENTERED | VCENTERED | LINE_COLOR);
}
} }
void Widget::onEvent(event_t event) void Widget::onEvent(event_t event)
@@ -86,21 +92,16 @@ void Widget::onEvent(event_t event)
TRACE("### event = 0x%x ###", event); TRACE("### event = 0x%x ###", event);
if (!fullscreen) { if (!fullscreen) {
switch(event) { switch(event) {
// [Enter LONG] -> pop-up widget menu // [ENTER] -> pop-up widget menu
case EVT_KEY_LONG(KEY_ENTER): case EVT_KEY_BREAK(KEY_ENTER):
killEvents(event); killEvents(event);
openWidgetMenu(this); openWidgetMenu(this);
return; return;
// [RTN / EXIT] -> exit focus mode (if not fullscreen) // [EXIT] -> exit focus mode (if not fullscreen)
case EVT_KEY_BREAK(KEY_EXIT): case EVT_KEY_BREAK(KEY_EXIT):
killEvents(event); killEvents(event);
ViewMain::instance()->setFocus(); ViewMain::instance()->setFocus();
return; return;
// Forward [ENTER] to ViewMain (main menu)
case EVT_KEY_BREAK(KEY_ENTER):
killEvents(event);
ViewMain::instance()->onEvent(event);
return;
} }
// Forward the rest to the parent class // Forward the rest to the parent class
Button::onEvent(event); Button::onEvent(event);
@@ -144,6 +145,7 @@ void Widget::setFullscreen(bool fullscreen)
setWindowFlags(getWindowFlags() | OPAQUE); setWindowFlags(getWindowFlags() | OPAQUE);
setRect(parent->getRect()); setRect(parent->getRect());
this->fullscreen = true; this->fullscreen = true;
fsStartedTS = RTOS_GET_MS();
bringToTop(); bringToTop();
} }
} }
+2 -1
View File
@@ -103,8 +103,9 @@ class Widget : public Button
protected: protected:
const WidgetFactory * factory; const WidgetFactory * factory;
PersistentData * persistentData; PersistentData * persistentData;
uint32_t focusGainedTimestamp = 0; uint32_t focusGainedTS = 0;
bool fullscreen = false; bool fullscreen = false;
uint32_t fsStartedTS = 0;
}; };
void registerWidget(const WidgetFactory * factory); void registerWidget(const WidgetFactory * factory);