1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-05 15:05:40 +02:00

max columns

This commit is contained in:
Laserlicht 2024-06-29 17:08:38 +02:00
parent b3f0bf1e1d
commit 684a9519b6
2 changed files with 5 additions and 4 deletions

View File

@ -442,7 +442,7 @@ int OptionsTab::SelectionWindow::calcLines(FactionID faction)
double additionalItems = 1; // random double additionalItems = 1; // random
if(!faction.isValid()) if(!faction.isValid())
return std::ceil(((double)allowedFactions.size() + additionalItems) / elementsPerLine); return std::ceil(((double)allowedFactions.size() + additionalItems) / MAX_ELEM_PER_LINES);
int count = 0; int count = 0;
for(auto & elemh : allowedHeroes) for(auto & elemh : allowedHeroes)
@ -452,7 +452,7 @@ int OptionsTab::SelectionWindow::calcLines(FactionID faction)
count++; count++;
} }
return std::ceil(((double)count + additionalItems) / (double)elementsPerLine); return std::ceil(((double)count + additionalItems) / (double)MAX_ELEM_PER_LINES);
} }
void OptionsTab::SelectionWindow::apply() void OptionsTab::SelectionWindow::apply()
@ -501,7 +501,7 @@ void OptionsTab::SelectionWindow::recreate()
{ {
// try to make squarish // try to make squarish
if(type == SelType::TOWN) if(type == SelType::TOWN)
elementsPerLine = floor(sqrt(allowedFactions.size())); elementsPerLine = std::min((int)allowedFactions.size(), MAX_ELEM_PER_LINES);
if(type == SelType::HERO) if(type == SelType::HERO)
{ {
int count = 0; int count = 0;
@ -513,7 +513,7 @@ void OptionsTab::SelectionWindow::recreate()
count++; count++;
} }
} }
elementsPerLine = floor(sqrt(count)); elementsPerLine = std::min(count, MAX_ELEM_PER_LINES);
} }
amountLines = calcLines((type > SelType::TOWN) ? selectedFaction : FactionID::RANDOM); amountLines = calcLines((type > SelType::TOWN) ? selectedFaction : FactionID::RANDOM);

View File

@ -107,6 +107,7 @@ private:
const int TEXT_POS_Y = 56; const int TEXT_POS_Y = 56;
const int MAX_LINES = 6; const int MAX_LINES = 6;
const int MAX_ELEM_PER_LINES = 4;
int elementsPerLine; int elementsPerLine;