1
0
Fork 0

Change: Determine industry directory width only on visible rows.

When rebuilding the industry directory list, the width of every item in the list is obtained to get the maximum width required for the horizontal scrollbar. This can take considerable time if there are a lot of industries.

Instead, calculate only for the visible rows, and grow as needed.
pull/13097/head
Peter Nelson 2024-11-19 01:07:57 +00:00
parent d2496b6ec4
commit 13c60adbbc
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
1 changed files with 7 additions and 5 deletions

View File

@ -1437,11 +1437,12 @@ protected:
*/
uint GetIndustryListWidth() const
{
uint width = 0;
for (const Industry *i : this->industries) {
width = std::max(width, GetStringBoundingBox(this->GetIndustryString(i)).width);
uint width = this->hscroll->GetCount();
auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->industries);
for (auto it = first; it != last; ++it) {
width = std::max(width, GetStringBoundingBox(this->GetIndustryString(*it)).width);
}
return width + WidgetDimensions::scaled.framerect.Horizontal();
return width;
}
/** (Re)Build industries list */
@ -1467,7 +1468,6 @@ protected:
this->industries.Filter(filter);
this->hscroll->SetCount(this->GetIndustryListWidth());
this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
}
@ -1682,6 +1682,7 @@ public:
void OnInit() override
{
this->SetCargoFilterArray();
this->hscroll->SetCount(0);
}
void SetStringParameters(WidgetID widget) const override
@ -1875,6 +1876,7 @@ public:
void OnPaint() override
{
if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
this->hscroll->SetCount(this->GetIndustryListWidth());
this->DrawWidgets();
}