Added on_touch on RSSI widget

This commit is contained in:
GullCode 2023-03-14 00:26:12 +01:00
parent 7a0d02cb83
commit b8c1e8c4a6
2 changed files with 27 additions and 10 deletions

View File

@ -32,6 +32,14 @@
namespace ui { namespace ui {
RSSI::RSSI(
Rect parent_rect,
bool instant_exec
) : Widget { parent_rect },
instant_exec_ { instant_exec }
{
}
void RSSI::paint(Painter& painter) { void RSSI::paint(Painter& painter) {
const auto r = screen_rect(); const auto r = screen_rect();
@ -352,6 +360,9 @@ namespace ui {
if( on_touch_press) { if( on_touch_press) {
on_touch_press(*this); on_touch_press(*this);
} }
if( on_select && instant_exec_ ) {
on_select(*this);
}
return true; return true;
case TouchEvent::Type::End: case TouchEvent::Type::End:
set_highlighted(false); set_highlighted(false);
@ -359,6 +370,9 @@ namespace ui {
if( on_touch_release) { if( on_touch_release) {
on_touch_release(*this); on_touch_release(*this);
} }
if( on_select && !instant_exec_ ) {
on_select(*this);
}
return true; return true;
default: default:
return false; return false;

View File

@ -39,12 +39,15 @@ namespace ui {
std::function<bool(RSSI&, KeyEvent)> on_dir { }; std::function<bool(RSSI&, KeyEvent)> on_dir { };
std::function<void(RSSI&)> on_highlight { }; std::function<void(RSSI&)> on_highlight { };
RSSI(Rect parent_rect, bool instant_exec); // instant_exec: Execute on_select when you touching instead of releasing
RSSI( RSSI(
const Rect parent_rect Rect parent_rect
) : Widget { parent_rect }, ) : RSSI { parent_rect, false }
min_ { 0 }, {
avg_ { 0 }, }
max_ { 0 }
RSSI(
) : RSSI { { }, { } }
{ {
} }
@ -61,12 +64,12 @@ namespace ui {
bool on_touch(const TouchEvent event) override; bool on_touch(const TouchEvent event) override;
private: private:
int32_t min_; int32_t min_ = 0;
int32_t avg_; int32_t avg_ = 0;
int32_t max_; int32_t max_ = 0;
int32_t peak_ = 0 ; int32_t peak_ = 0 ;
size_t peak_duration_ = 0 ; size_t peak_duration_ = 0 ;
bool instant_exec_ { false }; bool instant_exec_ { false };
bool pitch_rssi_enabled = false; bool pitch_rssi_enabled = false;
bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top] bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top]