From a01a22c96f17ae3fd7c01d3fcc06fe72139fd112 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 25 Apr 2021 23:09:25 +0200 Subject: [PATCH] Select the widget when touched prior to firing up the menu --- radio/src/gui/colorlcd/tabsgroup.cpp | 3 +++ radio/src/gui/colorlcd/widget.cpp | 33 +++++++++++++++++++--------- radio/src/gui/colorlcd/widget.h | 1 + 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/radio/src/gui/colorlcd/tabsgroup.cpp b/radio/src/gui/colorlcd/tabsgroup.cpp index eab15ee3f..240ff1ba5 100644 --- a/radio/src/gui/colorlcd/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/tabsgroup.cpp @@ -69,6 +69,9 @@ void TabsCarousel::paint(BitmapBuffer * dc) bool TabsCarousel::onTouchEnd(coord_t x, coord_t y) { unsigned index = (x - padding_left) / MENU_HEADER_BUTTON_WIDTH; + if (index >= menu->tabs.size()) { + return false; + } menu->setCurrentTab(index); setCurrentIndex(index); return true; diff --git a/radio/src/gui/colorlcd/widget.cpp b/radio/src/gui/colorlcd/widget.cpp index 8499b14cc..455443f23 100644 --- a/radio/src/gui/colorlcd/widget.cpp +++ b/radio/src/gui/colorlcd/widget.cpp @@ -48,6 +48,11 @@ Widget::Widget(const WidgetFactory *factory, FormGroup *parent, focusGainedTS = RTOS_GET_MS(); } }); + + setPressHandler([&]() -> uint8_t { + openWidgetMenu(this); + return 0; + }); } 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) { if (fullscreen) { @@ -91,17 +110,11 @@ void Widget::onEvent(event_t event) #if defined(HARDWARE_KEYS) TRACE("### event = 0x%x ###", event); if (!fullscreen) { - switch(event) { - // [ENTER] -> pop-up widget menu - case EVT_KEY_BREAK(KEY_ENTER): - killEvents(event); - openWidgetMenu(this); - return; + if (event == EVT_KEY_BREAK(KEY_EXIT)) { // [EXIT] -> exit focus mode (if not fullscreen) - case EVT_KEY_BREAK(KEY_EXIT): - killEvents(event); - ViewMain::instance()->setFocus(); - return; + killEvents(event); + ViewMain::instance()->setFocus(); + return; } // Forward the rest to the parent class Button::onEvent(event); diff --git a/radio/src/gui/colorlcd/widget.h b/radio/src/gui/colorlcd/widget.h index ec89f00f7..4c521b72e 100644 --- a/radio/src/gui/colorlcd/widget.h +++ b/radio/src/gui/colorlcd/widget.h @@ -84,6 +84,7 @@ class Widget : public Button // Window interface void checkEvents() override; void onEvent(event_t event) override; + bool onTouchEnd(coord_t x, coord_t y) override; void paint(BitmapBuffer * dc) override; // Widget interface