From 7d56c8a38162727b350f7dda434c5205b4960a7f Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Tue, 7 Oct 2025 07:05:38 +0100 Subject: [PATCH] increase list scroll speed. add list jump start/end. add L2 + scroll to select multiple enrties. --- sphaira/include/ui/types.hpp | 24 +++++++++++++++++++++--- sphaira/source/ui/list.cpp | 24 ++++++++++-------------- sphaira/source/ui/menus/filebrowser.cpp | 21 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/sphaira/include/ui/types.hpp b/sphaira/include/ui/types.hpp index b849a49..5b66f49 100644 --- a/sphaira/include/ui/types.hpp +++ b/sphaira/include/ui/types.hpp @@ -474,15 +474,29 @@ struct Controller { void UpdateButtonHeld(u64 buttons, double delta) { if (m_kdown & buttons) { - m_step = 50; + m_step_max = m_MAX_STEP; + m_step = m_INC_STEP; m_counter = 0; + m_step_max_counter = 0; } else if (m_kheld & buttons) { m_counter += m_step * delta; + // if we are at the max, ignore the delta and go as fast as the frame rate. + if (m_step_max == m_MAX) { + m_counter = m_MAX; + } + if (m_counter >= m_MAX) { m_kdown |= m_kheld & buttons; m_counter = 0; - m_step = std::min(m_step + 50, m_MAX_STEP); + m_step = std::min(m_step + m_INC_STEP, m_step_max); + + // slowly speed up until we reach 1 button down per frame. + m_step_max_counter++; + if (m_step_max_counter >= 5) { + m_step_max_counter = 0; + m_step_max = std::min(m_step_max + m_INC_STEP, m_MAX); + } } } } @@ -490,8 +504,12 @@ struct Controller { private: static constexpr double m_MAX = 1000; static constexpr double m_MAX_STEP = 250; - double m_step = 50; + static constexpr double m_INC_STEP = 50; + + double m_step_max = m_MAX_STEP; + double m_step = m_INC_STEP; double m_counter = 0; + int m_step_max_counter = 0; }; } // namespace sphaira diff --git a/sphaira/source/ui/list.cpp b/sphaira/source/ui/list.cpp index a99cea3..77c1e0b 100644 --- a/sphaira/source/ui/list.cpp +++ b/sphaira/source/ui/list.cpp @@ -65,11 +65,7 @@ auto List::ScrollDown(s64& index, s64 step, s64 count) -> bool { return false; } - if (index + step < count) { - index += step; - } else { - index = count - 1; - } + index = std::min(index + step, count - 1); if (index != old_index) { App::PlaySoundEffect(SoundEffect::Scroll); @@ -103,11 +99,7 @@ auto List::ScrollUp(s64& index, s64 step, s64 count) -> bool { return false; } - if (index >= step) { - index -= step; - } else { - index = 0; - } + index = std::max(0, index - step); if (index != old_index) { App::PlaySoundEffect(SoundEffect::Scroll); @@ -169,20 +161,24 @@ void List::OnUpdateGrid(Controller* controller, TouchInfo* touch, s64 index, s64 const auto page_up_button = GetPageJump() ? (m_row == 1 ? Button::DPAD_LEFT : Button::L2) : (Button::NONE); const auto page_down_button = GetPageJump() ? (m_row == 1 ? Button::DPAD_RIGHT : Button::R2) : (Button::NONE); + const auto hotkey = m_row == 1 ? controller->GotHeld(Button::R2) : false; + const auto end_page = INT32_MAX; + const auto hot_page = m_page * 4; + if (controller->GotDown(Button::DOWN)) { - if (ScrollDown(index, m_row, count)) { + if (ScrollDown(index, hotkey ? end_page : m_row, count)) { callback(false, index); } } else if (controller->GotDown(Button::UP)) { - if (ScrollUp(index, m_row, count)) { + if (ScrollUp(index, hotkey ? end_page : m_row, count)) { callback(false, index); } } else if (controller->GotDown(page_down_button)) { - if (ScrollDown(index, m_page, count)) { + if (ScrollDown(index, hotkey ? hot_page : m_page, count)) { callback(false, index); } } else if (controller->GotDown(page_up_button)) { - if (ScrollUp(index, m_page, count)) { + if (ScrollUp(index, hotkey ? hot_page : m_page, count)) { callback(false, index); } } else if (m_row > 1 && controller->GotDown(Button::RIGHT)) { diff --git a/sphaira/source/ui/menus/filebrowser.cpp b/sphaira/source/ui/menus/filebrowser.cpp index 710934c..08c28de 100644 --- a/sphaira/source/ui/menus/filebrowser.cpp +++ b/sphaira/source/ui/menus/filebrowser.cpp @@ -529,12 +529,31 @@ FsView::~FsView() { } void FsView::Update(Controller* controller, TouchInfo* touch) { - m_list->OnUpdate(controller, touch, m_index, m_entries_current.size(), [this](bool touch, auto i) { + m_list->OnUpdate(controller, touch, m_index, m_entries_current.size(), [this, controller](bool touch, auto i) { if (touch && m_index == i) { FireAction(Button::A); } else { App::PlaySoundEffect(SoundEffect::Focus); + auto old_index = m_index; SetIndex(i); + const auto new_index = m_index; + + // if L2 is helt, select all between old and new index. + if (old_index != new_index && controller->GotHeld(Button::L2)) { + const auto inc = old_index < new_index ? +1 : -1; + + while (old_index != new_index) { + old_index += inc; + + auto& e = GetEntry(old_index); + e.selected ^= 1; + if (e.selected) { + m_selected_count++; + } else { + m_selected_count--; + } + } + } } }); }