1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

fix filter

This commit is contained in:
Michael 2023-08-09 00:13:02 +02:00 committed by GitHub
parent bbe04c747d
commit 8693dab9ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -138,7 +138,7 @@ static ESortBy getSortBySelectionScreen(ESelectionScreen Type)
}
SelectionTab::SelectionTab(ESelectionScreen Type)
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder("")
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder(""), curFilterSize(0)
{
OBJ_CONSTRUCTION;
@ -391,6 +391,10 @@ std::tuple<std::string, std::string, bool, bool> SelectionTab::checkSubfolder(st
// selMaps with the relevant data.
void SelectionTab::filter(int size, bool selectFirst)
{
if(size == -1)
size = curFilterSize;
curFilterSize = size;
curItems.clear();
for(auto elem : allItems)
@ -428,13 +432,19 @@ void SelectionTab::filter(int size, bool selectFirst)
sort();
if(selectFirst)
{
slider->scrollTo(0);
callOnSelect(curItems[0]);
selectAbs(-1);
int firstPos = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
if(firstPos < curItems.size())
{
slider->scrollTo(firstPos);
callOnSelect(curItems[firstPos]);
selectAbs(firstPos);
}
}
}
else
{
updateListItems();
redraw();
slider->block(true);
if(callOnSelect)
callOnSelect(nullptr);
@ -499,9 +509,9 @@ void SelectionTab::select(int position)
}
else
curFolder += curItems[py]->folderName + "/";
filter(0);
filter(-1);
slider->scrollTo(0);
return;
}
@ -602,7 +612,7 @@ void SelectionTab::selectFileName(std::string fname)
}
}
filter(0);
filter(-1);
selectAbs(-1);
}

View File

@ -70,6 +70,7 @@ public:
ESortBy sortingBy;
ESortBy generalSortingBy;
bool sortModeAscending;
int curFilterSize = 0;
std::shared_ptr<CTextInput> inputName;