From b8c1e8c4a6a6c95dac82c3f8d026491655ac0457 Mon Sep 17 00:00:00 2001 From: GullCode Date: Tue, 14 Mar 2023 00:26:12 +0100 Subject: [PATCH] Added on_touch on RSSI widget --- firmware/application/ui/ui_rssi.cpp | 14 ++++++++++++++ firmware/application/ui/ui_rssi.hpp | 23 +++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/firmware/application/ui/ui_rssi.cpp b/firmware/application/ui/ui_rssi.cpp index 1cfc2d0ff..8721c7151 100644 --- a/firmware/application/ui/ui_rssi.cpp +++ b/firmware/application/ui/ui_rssi.cpp @@ -32,6 +32,14 @@ namespace ui { + RSSI::RSSI( + Rect parent_rect, + bool instant_exec + ) : Widget { parent_rect }, + instant_exec_ { instant_exec } + { + } + void RSSI::paint(Painter& painter) { const auto r = screen_rect(); @@ -352,6 +360,9 @@ namespace ui { if( on_touch_press) { on_touch_press(*this); } + if( on_select && instant_exec_ ) { + on_select(*this); + } return true; case TouchEvent::Type::End: set_highlighted(false); @@ -359,6 +370,9 @@ namespace ui { if( on_touch_release) { on_touch_release(*this); } + if( on_select && !instant_exec_ ) { + on_select(*this); + } return true; default: return false; diff --git a/firmware/application/ui/ui_rssi.hpp b/firmware/application/ui/ui_rssi.hpp index bd64244f1..d4adf6ce5 100644 --- a/firmware/application/ui/ui_rssi.hpp +++ b/firmware/application/ui/ui_rssi.hpp @@ -39,12 +39,15 @@ namespace ui { std::function on_dir { }; std::function on_highlight { }; + RSSI(Rect parent_rect, bool instant_exec); // instant_exec: Execute on_select when you touching instead of releasing RSSI( - const Rect parent_rect - ) : Widget { parent_rect }, - min_ { 0 }, - avg_ { 0 }, - max_ { 0 } + Rect parent_rect + ) : RSSI { parent_rect, false } + { + } + + RSSI( + ) : RSSI { { }, { } } { } @@ -54,19 +57,19 @@ namespace ui { int32_t get_delta(); void set_vertical_rssi(bool enabled); void set_peak(bool enabled, size_t duration); - + void paint(Painter& painter) override; void on_focus() override; bool on_key(const KeyEvent key) override; bool on_touch(const TouchEvent event) override; private: - int32_t min_; - int32_t avg_; - int32_t max_; + int32_t min_ = 0; + int32_t avg_ = 0; + int32_t max_ = 0; int32_t peak_ = 0 ; size_t peak_duration_ = 0 ; - bool instant_exec_ { false }; + bool instant_exec_ { false }; bool pitch_rssi_enabled = false; bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top]