diff --git a/src/Interface/Controls/Pagination.as b/src/Interface/Controls/Pagination.as new file mode 100644 index 0000000..a5a3c6b --- /dev/null +++ b/src/Interface/Controls/Pagination.as @@ -0,0 +1,53 @@ +namespace Controls +{ + class Pagination { + + int page = 0; + int total = 0; + int pageCount = 0; + + int m_limit = 3; + + bool isPageRequested = false; + int requestedPageIndex = 0; + + void Render() { + isPageRequested = false; + requestedPageIndex = 0; + + if (page > 0) { + PageButton(page - 1, "Prev Page"); + } + + UI::BeginGroup(); + for (uint i = Math::Max(0, page - m_limit); i < page; i++) { + PageButton(i); + } + + UI::BeginDisabled(); + PageButton(page); + + UI::EndDisabled(); + + for (uint i = page + 1; i < Math::Min(pageCount, page + m_limit + 1); i++) { + PageButton(i); + } + + if (pageCount > page + 1) { + PageButton(page + 1, "Next Page"); + } + UI::EndGroup(); + } + + void PageButton(int pageIndex, string label = "") { + if (label == "") { + label = "" + (pageIndex + 1); + } + if (UI::Button(label)) { + isPageRequested = true; + requestedPageIndex = pageIndex; + } + UI::SameLine(); + } + } +} \ No newline at end of file diff --git a/src/Interface/Tabs/PluginList.as b/src/Interface/Tabs/PluginList.as index 40a1440..44c8a16 100644 --- a/src/Interface/Tabs/PluginList.as +++ b/src/Interface/Tabs/PluginList.as @@ -10,6 +10,8 @@ class PluginListTab : Tab int m_pageCount; uint m_lastPageRequestFinished = 0; + Controls::Pagination m_pagination; + array m_plugins; string GetLabel() override { return "Plugins"; } @@ -59,7 +61,11 @@ class PluginListTab : Tab void StartRequest() { Clear(); - StartRequestForPage(0); + int defaultPage = 0; + if (Setting_TabsPagination) { + defaultPage = m_pagination.page; + } + StartRequestForPage(defaultPage); } void StartRequestForPage(int page) @@ -121,7 +127,17 @@ class PluginListTab : Tab m_page = js["page"]; m_pageCount = js["pages"]; + m_pagination.total = m_total; + m_pagination.page = m_page; + m_pagination.pageCount = m_pageCount; + auto jsItems = js["items"]; + + if (Setting_TabsPagination) { + UI::SetScrollY(0); + m_plugins.Resize(0); + } + for (uint i = 0; i < jsItems.Length; i++) { PluginInfo pi(jsItems[i]); if (Setting_ChangelogTooltips && pi.GetInstalledVersion() < pi.m_version) { @@ -188,17 +204,26 @@ class PluginListTab : Tab if (haveMorePages) { UI::TableNextRow(UI::TableRowFlags::None, rowHeight); UI::TableNextColumn(); - string infiniteScrollMsg = (m_request is null ? "Scroll to load" : "Loading") + " page " + (m_page + 2); - UI::Dummy(vec2(0, rowHeight / 3.0)); - UI::Text(infiniteScrollMsg); + if (!Setting_TabsPagination) { + string infiniteScrollMsg = (m_request is null ? "Scroll to load" : "Loading") + " page " + (m_page + 2); + UI::Dummy(vec2(0, rowHeight / 3.0)); + UI::Text(infiniteScrollMsg); + } } UI::EndTable(); - // after >500ms since the last request, get the next page if there is excess vertical space or when we scroll to just a bit before the final row is in view - bool waitedLongEnough = m_lastPageRequestFinished + 500 < Time::Now; - bool scrolledNearEnd = UI::GetScrollMaxY() == 0 || UI::GetScrollY() > (UI::GetScrollMaxY() - rowHeight); - if (waitedLongEnough && scrolledNearEnd && haveMorePages && m_request is null) { - StartRequestForPage(m_page + 1); + if (Setting_TabsPagination) { + m_pagination.Render(); + if (m_pagination.isPageRequested) { + StartRequestForPage(m_pagination.requestedPageIndex); + } + } else { + // after >500ms since the last request, get the next page if there is excess vertical space or when we scroll to just a bit before the final row is in view + bool waitedLongEnough = m_lastPageRequestFinished + 500 < Time::Now; + bool scrolledNearEnd = UI::GetScrollMaxY() == 0 || UI::GetScrollY() > (UI::GetScrollMaxY() - rowHeight); + if (waitedLongEnough && scrolledNearEnd && haveMorePages && m_request is null) { + StartRequestForPage(m_page + 1); + } } } } diff --git a/src/Settings.as b/src/Settings.as index 9b596e9..686225d 100644 --- a/src/Settings.as +++ b/src/Settings.as @@ -10,6 +10,9 @@ int Setting_PluginsPerRow = 3; [Setting category="Interface" name="Display changelog when hovering over updatable plugins."] bool Setting_ChangelogTooltips = true; +[Setting category="Interface" name="Enable tabs pagination"] +bool Setting_TabsPagination = false; + [Setting category="Advanced" name="Base URL" description="Only change if you know what you're doing!"] string Setting_BaseURL = "https://openplanet.dev/";