diff --git a/sphaira/CMakeLists.txt b/sphaira/CMakeLists.txt index dc031dd..2c244bc 100644 --- a/sphaira/CMakeLists.txt +++ b/sphaira/CMakeLists.txt @@ -51,13 +51,12 @@ add_executable(sphaira source/ui/notification.cpp source/ui/nvg_util.cpp source/ui/option_box.cpp - source/ui/option_list.cpp source/ui/popup_list.cpp source/ui/progress_box.cpp source/ui/scrollable_text.cpp - source/ui/scrollbar.cpp source/ui/sidebar.cpp source/ui/widget.cpp + source/ui/list.cpp source/app.cpp source/download.cpp diff --git a/sphaira/include/app.hpp b/sphaira/include/app.hpp index cebb2c6..1edd6a3 100644 --- a/sphaira/include/app.hpp +++ b/sphaira/include/app.hpp @@ -33,7 +33,9 @@ enum class LaunchType { Forwader_Sphaira, }; +// todo: why is this global??? void DrawElement(float x, float y, float w, float h, ThemeEntryID id); +void DrawElement(const Vec4&, ThemeEntryID id); class App { public: @@ -56,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; @@ -143,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/error_box.hpp b/sphaira/include/ui/error_box.hpp index e6e58f8..a2327e5 100644 --- a/sphaira/include/ui/error_box.hpp +++ b/sphaira/include/ui/error_box.hpp @@ -10,7 +10,6 @@ public: ErrorBox(Result code, const std::string& message); auto Update(Controller* controller, TouchInfo* touch) -> void override; - auto OnLayoutChange() -> void override; auto Draw(NVGcontext* vg, Theme* theme) -> void override; private: diff --git a/sphaira/include/ui/list.hpp b/sphaira/include/ui/list.hpp new file mode 100644 index 0000000..a30514d --- /dev/null +++ b/sphaira/include/ui/list.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "ui/object.hpp" + +namespace sphaira::ui { + +struct List final : Object { + using Callback = std::function; + using TouchCallback = std::function; + + List(s64 row, s64 page, const Vec4& pos, const Vec4& v, const Vec2& pad = {}); + + 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; + } + + 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 d31c48c..9e179c1 100644 --- a/sphaira/include/ui/menus/appstore.hpp +++ b/sphaira/include/ui/menus/appstore.hpp @@ -2,6 +2,7 @@ #include "ui/menus/menu_base.hpp" #include "ui/scrollable_text.hpp" +#include "ui/list.hpp" #include "nro.hpp" #include "fs.hpp" #include @@ -77,7 +78,7 @@ struct EntryMenu final : MenuBase { // void OnFocusGained() override; void ShowChangelogAction(); - void SetIndex(std::size_t index); + void SetIndex(s64 index); void UpdateOptions(); @@ -97,10 +98,10 @@ 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