mirror of https://github.com/OpenTTD/OpenTTD
Change: Determine industry directory width only on visible rows. (#13097)
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/13118/head
parent
9399a92a4f
commit
1f18894408
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue