Select the widget when touched prior to firing up the menu

This commit is contained in:
Raphael Coeffic
2021-05-06 12:55:59 +02:00
committed by Raphael Coeffic
parent a369f83f13
commit a01a22c96f
3 changed files with 27 additions and 10 deletions
+3
View File
@@ -69,6 +69,9 @@ void TabsCarousel::paint(BitmapBuffer * dc)
bool TabsCarousel::onTouchEnd(coord_t x, coord_t y) bool TabsCarousel::onTouchEnd(coord_t x, coord_t y)
{ {
unsigned index = (x - padding_left) / MENU_HEADER_BUTTON_WIDTH; unsigned index = (x - padding_left) / MENU_HEADER_BUTTON_WIDTH;
if (index >= menu->tabs.size()) {
return false;
}
menu->setCurrentTab(index); menu->setCurrentTab(index);
setCurrentIndex(index); setCurrentIndex(index);
return true; return true;
+23 -10
View File
@@ -48,6 +48,11 @@ Widget::Widget(const WidgetFactory *factory, FormGroup *parent,
focusGainedTS = RTOS_GET_MS(); focusGainedTS = RTOS_GET_MS();
} }
}); });
setPressHandler([&]() -> uint8_t {
openWidgetMenu(this);
return 0;
});
} }
void Widget::checkEvents() void Widget::checkEvents()
@@ -60,6 +65,20 @@ void Widget::checkEvents()
} }
} }
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()) {
onPress();
return true;
}
setFocus();
return true;
}
void Widget::paint(BitmapBuffer * dc) void Widget::paint(BitmapBuffer * dc)
{ {
if (fullscreen) { if (fullscreen) {
@@ -91,17 +110,11 @@ void Widget::onEvent(event_t event)
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
TRACE("### event = 0x%x ###", event); TRACE("### event = 0x%x ###", event);
if (!fullscreen) { if (!fullscreen) {
switch(event) { if (event == EVT_KEY_BREAK(KEY_EXIT)) {
// [ENTER] -> pop-up widget menu
case EVT_KEY_BREAK(KEY_ENTER):
killEvents(event);
openWidgetMenu(this);
return;
// [EXIT] -> exit focus mode (if not fullscreen) // [EXIT] -> exit focus mode (if not fullscreen)
case EVT_KEY_BREAK(KEY_EXIT): killEvents(event);
killEvents(event); ViewMain::instance()->setFocus();
ViewMain::instance()->setFocus(); return;
return;
} }
// Forward the rest to the parent class // Forward the rest to the parent class
Button::onEvent(event); Button::onEvent(event);
+1
View File
@@ -84,6 +84,7 @@ class Widget : public Button
// Window interface // Window interface
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override; void onEvent(event_t event) override;
bool onTouchEnd(coord_t x, coord_t y) override;
void paint(BitmapBuffer * dc) override; void paint(BitmapBuffer * dc) override;
// Widget interface // Widget interface