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