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"
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)
{
@@ -44,7 +45,7 @@ Widget::Widget(const WidgetFactory *factory, FormGroup *parent,
{
setFocusHandler([&](bool focus) {
if (focus) { // gained focus
focusGainedTimestamp = RTOS_GET_MS();
focusGainedTS = RTOS_GET_MS();
}
});
}
@@ -54,7 +55,7 @@ void Widget::checkEvents()
Button::checkEvents();
// 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();
}
}
@@ -72,12 +73,17 @@ void Widget::paint(BitmapBuffer * dc)
if (hasFocus() && !fullscreen) {
// 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) {
return;
}
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)
@@ -86,21 +92,16 @@ void Widget::onEvent(event_t event)
TRACE("### event = 0x%x ###", event);
if (!fullscreen) {
switch(event) {
// [Enter LONG] -> pop-up widget menu
case EVT_KEY_LONG(KEY_ENTER):
// [ENTER] -> pop-up widget menu
case EVT_KEY_BREAK(KEY_ENTER):
killEvents(event);
openWidgetMenu(this);
return;
// [RTN / EXIT] -> exit focus mode (if not fullscreen)
// [EXIT] -> exit focus mode (if not fullscreen)
case EVT_KEY_BREAK(KEY_EXIT):
killEvents(event);
ViewMain::instance()->setFocus();
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
Button::onEvent(event);
@@ -144,6 +145,7 @@ void Widget::setFullscreen(bool fullscreen)
setWindowFlags(getWindowFlags() | OPAQUE);
setRect(parent->getRect());
this->fullscreen = true;
fsStartedTS = RTOS_GET_MS();
bringToTop();
}
}
+2 -1
View File
@@ -103,8 +103,9 @@ class Widget : public Button
protected:
const WidgetFactory * factory;
PersistentData * persistentData;
uint32_t focusGainedTimestamp = 0;
uint32_t focusGainedTS = 0;
bool fullscreen = false;
uint32_t fsStartedTS = 0;
};
void registerWidget(const WidgetFactory * factory);