From a49c35088d188c6d159cb367fe8fd6655df81532 Mon Sep 17 00:00:00 2001 From: heurist1 Date: Sat, 9 Oct 2021 22:46:05 +0100 Subject: [PATCH] Added back Added the ability to use the Up and Left buttons simultaneously to cause the cursor to move to the top left of the screen --- firmware/application/event_m0.cpp | 6 ++++++ firmware/common/ui.hpp | 1 + firmware/common/ui_focus.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index d9ebd42f..8c11b2fa 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -298,6 +298,12 @@ void EventDispatcher::handle_switches() { } if( in_key_event ) { + if (switches_state[(size_t)ui::KeyEvent::Left] && switches_state[(size_t)ui::KeyEvent::Up]) + { + const auto event = static_cast(ui::KeyEvent::Back); + context.focus_manager().update(top_widget, event); + } + // If we're in a key event, return. We will ignore all additional key // presses until the first key is released. We also want to ignore events // where the last key held generates a key event when other pressed keys diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index 7020e7b4..ee8610fb 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -325,6 +325,7 @@ enum class KeyEvent { Down = 2, Up = 3, Select = 4, + Back = 5, /* Left and Up together */ }; using EncoderEvent = int32_t; diff --git a/firmware/common/ui_focus.cpp b/firmware/common/ui_focus.cpp index 70e291ed..61f37a0b 100644 --- a/firmware/common/ui_focus.cpp +++ b/firmware/common/ui_focus.cpp @@ -179,7 +179,14 @@ void FocusManager::update( }; const auto nearest = std::min_element(collection.cbegin(), collection.cend(), compare_fn); - if( nearest != collection.cend() ) { + // Up and left to indicate back + if (event == KeyEvent::Back) { + collection.clear(); + widget_collect_visible(top_widget, find_back_fn, collection); + if (!collection.empty()) + set_focus_widget(collection[0].first); + } + else if( nearest != collection.cend() ) { //focus->blur(); const auto new_focus = (*nearest).first; set_focus_widget(new_focus);