diff --git a/firmware/application/apps/ui_freqman.hpp b/firmware/application/apps/ui_freqman.hpp index a1f32f45d..6f301cb77 100644 --- a/firmware/application/apps/ui_freqman.hpp +++ b/firmware/application/apps/ui_freqman.hpp @@ -65,7 +65,7 @@ class FreqManBaseView : public View { OptionsField options_category{ {3 * 8, 2}, - 20 /* length */, + 19 /* length */, {}}; FreqManUIList freqlist_view{ diff --git a/firmware/application/ui/ui_freqlist.cpp b/firmware/application/ui/ui_freqlist.cpp index ce169e136..fb4f01677 100644 --- a/firmware/application/ui/ui_freqlist.cpp +++ b/firmware/application/ui/ui_freqlist.cpp @@ -93,6 +93,33 @@ void FreqManUIList::on_blur() { set_dirty(); } +bool FreqManUIList::on_touch(const TouchEvent event) { + if (!db_ || db_->empty()) + return false; + if (event.type == TouchEvent::Type::Start) { + focus(); + set_dirty(); + int16_t rel_y = event.point.y() - screen_rect().top(); + size_t new_selected = rel_y / char_height; + if (new_selected + start_index_ >= db_->entry_count()) { + return true; // clicked, where there is no entry, skip it + } + // selected_index_ is the current + if (selected_index_ == new_selected) { + // already selected, trigger on_select + if (on_select) { + // on_select(new_selected); //causes strange behavior, not so confident to use it + } + return true; + } else { + // just change selection + selected_index_ = new_selected; + } + return true; + } + return true; +} + bool FreqManUIList::on_keyboard(const KeyboardEvent key) { if (!db_ || db_->empty()) return false; diff --git a/firmware/application/ui/ui_freqlist.hpp b/firmware/application/ui/ui_freqlist.hpp index a29eca655..5589e85b6 100644 --- a/firmware/application/ui/ui_freqlist.hpp +++ b/firmware/application/ui/ui_freqlist.hpp @@ -50,6 +50,7 @@ class FreqManUIList : public Widget { bool on_key(const KeyEvent key) override; bool on_encoder(EncoderEvent delta) override; bool on_keyboard(const KeyboardEvent event) override; + bool on_touch(const TouchEvent event) override; void set_parent_rect(Rect new_parent_rect) override; diff --git a/firmware/application/ui/ui_menu.cpp b/firmware/application/ui/ui_menu.cpp index 06685a141..fc954e855 100644 --- a/firmware/application/ui/ui_menu.cpp +++ b/firmware/application/ui/ui_menu.cpp @@ -243,6 +243,18 @@ void MenuView::on_blur() { item_view(highlighted_item - offset)->unhighlight(); } +bool MenuView::on_touch(const TouchEvent event) { + size_t i = 0; + for (const auto child : children_) { + if (i >= menu_item_views.size()) break; + if (child->screen_rect().contains(event.point)) { + return set_highlighted(i + offset); + } + i++; + } + return false; +} + bool MenuView::on_key(const KeyEvent key) { switch (key) { case KeyEvent::Up: diff --git a/firmware/application/ui/ui_menu.hpp b/firmware/application/ui/ui_menu.hpp index dd83c3b6c..2fc2b5be3 100644 --- a/firmware/application/ui/ui_menu.hpp +++ b/firmware/application/ui/ui_menu.hpp @@ -99,6 +99,7 @@ class MenuView : public View { bool on_key(const KeyEvent event) override; bool on_encoder(const EncoderEvent event) override; bool on_keyboard(const KeyboardEvent event) override; + bool on_touch(const TouchEvent event) override; private: void update_items();