From 70d2e9873cb3e2ec1b292c2abfc6e046aa8d6025 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:29:25 +0000 Subject: [PATCH] add touch scrolling, fix scrollbar, fix appstore search - when fireing an action, the action array may change. so the loop should break early as soon as an action is handled. this fixes the appstore search when pressing B. - scrollbar no longer goes oob. fixes #76 currently, scrolling has no acceleration. --- sphaira/include/app.hpp | 6 +- sphaira/include/ui/list.hpp | 41 +++++- sphaira/include/ui/menus/appstore.hpp | 18 ++- sphaira/include/ui/menus/file_viewer.hpp | 4 +- sphaira/include/ui/menus/filebrowser.hpp | 15 +- sphaira/include/ui/menus/ghdl.hpp | 6 +- sphaira/include/ui/menus/homebrew.hpp | 8 +- sphaira/include/ui/menus/irs_menu.hpp | 2 +- sphaira/include/ui/menus/main_menu.hpp | 3 +- sphaira/include/ui/menus/themezer.hpp | 14 +- sphaira/include/ui/nvg_util.hpp | 3 + sphaira/include/ui/option_box.hpp | 12 +- sphaira/include/ui/popup_list.hpp | 14 +- sphaira/include/ui/progress_box.hpp | 6 +- sphaira/include/ui/sidebar.hpp | 13 +- sphaira/include/ui/types.hpp | 1 + sphaira/include/ui/widget.hpp | 9 +- sphaira/source/app.cpp | 6 +- sphaira/source/download.cpp | 2 +- sphaira/source/ui/list.cpp | 174 ++++++++++++++++++++--- sphaira/source/ui/menus/appstore.cpp | 79 ++++------ sphaira/source/ui/menus/filebrowser.cpp | 74 ++++------ sphaira/source/ui/menus/ghdl.cpp | 38 ++--- sphaira/source/ui/menus/homebrew.cpp | 70 +++------ sphaira/source/ui/menus/irs_menu.cpp | 16 +-- sphaira/source/ui/menus/main_menu.cpp | 49 +++---- sphaira/source/ui/menus/themezer.cpp | 43 +++--- sphaira/source/ui/nvg_util.cpp | 48 ++++++- sphaira/source/ui/option_box.cpp | 12 +- sphaira/source/ui/popup_list.cpp | 74 +++++----- sphaira/source/ui/progress_box.cpp | 2 +- sphaira/source/ui/sidebar.cpp | 118 +++++++-------- sphaira/source/ui/widget.cpp | 74 ++-------- 33 files changed, 542 insertions(+), 512 deletions(-) diff --git a/sphaira/include/app.hpp b/sphaira/include/app.hpp index 697134d..1edd6a3 100644 --- a/sphaira/include/app.hpp +++ b/sphaira/include/app.hpp @@ -58,8 +58,8 @@ public: static void NotifyFlashLed(); static auto GetThemeMetaList() -> std::span; - static void SetTheme(u64 theme_index); - static auto GetThemeIndex() -> u64; + static void SetTheme(s64 theme_index); + static auto GetThemeIndex() -> s64; static auto GetDefaultImage(int* w = nullptr, int* h = nullptr) -> int; @@ -145,7 +145,7 @@ public: Theme m_theme{}; fs::FsPath theme_path{}; - std::size_t m_theme_index{}; + s64 m_theme_index{}; bool m_quit{}; diff --git a/sphaira/include/ui/list.hpp b/sphaira/include/ui/list.hpp index b511a69..a30514d 100644 --- a/sphaira/include/ui/list.hpp +++ b/sphaira/include/ui/list.hpp @@ -5,22 +5,53 @@ namespace sphaira::ui { struct List final : Object { - using Callback = std::function; + using Callback = std::function; + using TouchCallback = std::function; - List(const Vec4& pos, const Vec4& v, const Vec2& pad = {}); + List(s64 row, s64 page, const Vec4& pos, const Vec4& v, const Vec2& pad = {}); - void Do(u64 index, u64 count, Callback callback) const { - Do(nullptr, nullptr, index, count, callback); + void OnUpdate(Controller* controller, TouchInfo* touch, s64 count, TouchCallback callback); + + void Draw(NVGcontext* vg, Theme* theme, s64 count, Callback callback) const; + + auto SetScrollBarPos(float x, float y, float h) { + m_scrollbar.x = x; + m_scrollbar.y = y; + m_scrollbar.h = h; } - void Do(NVGcontext* vg, Theme* theme, u64 index, u64 count, Callback callback, float y_off = 0) const; + auto ScrollDown(s64& index, s64 step, s64 count) -> bool; + auto ScrollUp(s64& index, s64 step, s64 count) -> bool; + + auto GetYoff() const { + return m_yoff; + } + + void SetYoff(float y = 0) { + m_yoff = y; + } + + auto GetMaxY() const { + return m_v.h + m_pad.y; + } private: auto Draw(NVGcontext* vg, Theme* theme) -> void override {} + auto ClampY(float y, s64 count) const -> float; private: + const s64 m_row; + const s64 m_page; + Vec4 m_v; Vec2 m_pad; + + Vec4 m_scrollbar{}; + + // current y offset. + float m_yoff{}; + // in progress y offset, used when scrolling. + float m_y_prog{}; }; } // namespace sphaira::ui diff --git a/sphaira/include/ui/menus/appstore.hpp b/sphaira/include/ui/menus/appstore.hpp index 102943e..9e179c1 100644 --- a/sphaira/include/ui/menus/appstore.hpp +++ b/sphaira/include/ui/menus/appstore.hpp @@ -78,7 +78,7 @@ struct EntryMenu final : MenuBase { // void OnFocusGained() override; void ShowChangelogAction(); - void SetIndex(std::size_t index); + void SetIndex(s64 index); void UpdateOptions(); @@ -98,7 +98,7 @@ private: const LazyImage& m_default_icon; Menu& m_menu; - std::size_t m_index{}; // where i am in the array + s64 m_index{}; // where i am in the array std::vector