From 24ab2f29faadcb66c17cf075aa2325f4b376ebe0 Mon Sep 17 00:00:00 2001 From: zxkmm <24917424+zxkmm@users.noreply.github.com> Date: Tue, 24 Sep 2024 02:57:15 +0800 Subject: [PATCH] touch to pop splash (#2260) * touch to pop * debug * have to add another var * works but since touch screen is laggy, it's tricky * tune to single touch * remove debug things * safer with sleep * textual * @HTotoo resolved the sleep issue * use pop handler in another place (button) --- firmware/application/ui_navigation.cpp | 37 +++++++++++++++++++++++--- firmware/application/ui_navigation.hpp | 4 +++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 9d66e4378..507b60d64 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -996,11 +996,12 @@ void BMPView::focus() { button_done.focus(); } -BMPView::BMPView(NavigationView& nav) { +BMPView::BMPView(NavigationView& nav) + : nav_(nav) { add_children({&button_done}); - button_done.on_select = [this, &nav](Button&) { - nav.pop(); + button_done.on_select = [this](Button&) { + handle_pop(); }; } @@ -1009,6 +1010,36 @@ void BMPView::paint(Painter&) { portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, true); } +bool BMPView::on_touch(const TouchEvent event) { + /* the event thing were resolved by HTotoo, talked here https://discord.com/channels/719669764804444213/956561375155589192/1287756910950486027 + * the touch screen policy can be better, talked here https://discord.com/channels/719669764804444213/956561375155589192/1198926225897443328 + */ + + if (!nav_.is_valid()) { + return false; + } + + switch (event.type) { + case TouchEvent::Type::Start: + return true; + + case TouchEvent::Type::End: + handle_pop(); + return true; + + default: + break; + } + + return false; +} + +void BMPView::handle_pop() { + if (nav_.is_valid()) { + nav_.pop(); + } +} + /* NotImplementedView ****************************************************/ /*NotImplementedView::NotImplementedView(NavigationView& nav) { diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index 2311b17e3..8f9d4791f 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -343,7 +343,11 @@ class BMPView : public View { void paint(Painter&) override; void focus() override; + bool on_touch(const TouchEvent event) override; + void handle_pop(); + private: + NavigationView& nav_; Button button_done{ {240, 0, 1, 1}, ""};