From b3d444a0f3b840f29604e8d4176ad21b1b5aeb91 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:25:55 +0300 Subject: [PATCH] Keep scroll value when refreshing the list --- loader/src/ui/internal/list/ModListLayer.cpp | 15 +++++++++++++-- loader/src/ui/internal/list/ModListLayer.hpp | 2 +- loader/src/ui/internal/list/SearchFilterPopup.cpp | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/loader/src/ui/internal/list/ModListLayer.cpp b/loader/src/ui/internal/list/ModListLayer.cpp index 3a5cf1d3..ae936bed 100644 --- a/loader/src/ui/internal/list/ModListLayer.cpp +++ b/loader/src/ui/internal/list/ModListLayer.cpp @@ -444,13 +444,18 @@ void ModListLayer::createSearchControl() { this->addChild(m_searchInput); } -void ModListLayer::reloadList(std::optional const& query) { +void ModListLayer::reloadList(bool keepScroll, std::optional const& query) { auto winSize = CCDirector::sharedDirector()->getWinSize(); if (query) { m_query = query.value(); } + float scroll = 0.0f; + if (keepScroll && m_list) { + scroll = m_list->m_listView->m_tableView->m_contentLayer->getPositionY(); + } + // set search query m_query.keywords = m_searchInput && @@ -489,6 +494,12 @@ void ModListLayer::reloadList(std::optional const& query) { m_listLabel->setVisible(false); } + if (keepScroll) { + list->m_tableView->m_contentLayer->setPosition( + { 0.0f, scroll } + ); + } + // update index if needed if (g_tab == ModListType::Download && !Index::get()->hasTriedToUpdate()) { m_listLabel->setVisible(true); @@ -686,7 +697,7 @@ void ModListLayer::keyDown(enumKeyCodes key) { } void ModListLayer::textChanged(CCTextInputNode* input) { - this->reloadList(); + this->reloadList(false); } // Constructors etc. diff --git a/loader/src/ui/internal/list/ModListLayer.hpp b/loader/src/ui/internal/list/ModListLayer.hpp index 648e8309..0afa2839 100644 --- a/loader/src/ui/internal/list/ModListLayer.hpp +++ b/loader/src/ui/internal/list/ModListLayer.hpp @@ -94,5 +94,5 @@ public: ModListDisplay getDisplay() const; ModListQuery& getQuery(); - void reloadList(std::optional const& query = std::nullopt); + void reloadList(bool keepScroll = true, std::optional const& query = std::nullopt); }; diff --git a/loader/src/ui/internal/list/SearchFilterPopup.cpp b/loader/src/ui/internal/list/SearchFilterPopup.cpp index 61353a7e..e64ed651 100644 --- a/loader/src/ui/internal/list/SearchFilterPopup.cpp +++ b/loader/src/ui/internal/list/SearchFilterPopup.cpp @@ -175,7 +175,7 @@ void SearchFilterPopup::onPlatformToggle(CCObject* sender) { void SearchFilterPopup::onClose(CCObject* sender) { Popup::onClose(sender); - m_modLayer->reloadList(); + m_modLayer->reloadList(false); } SearchFilterPopup* SearchFilterPopup::create(ModListLayer* layer, ModListType type) {