From 2199543fbcf0b9ae4e5a39b917d3942007c2c64e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 17 Jul 2024 10:04:10 +0100 Subject: [PATCH] Codechange: Use GetVisibleRangeIterators when drawing airport specs. --- src/airport_gui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index a09bc82a89..b73ef24901 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -384,13 +384,14 @@ public: case WID_AP_AIRPORT_LIST: { Rect row = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.bevel); Rect text = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.matrix); - AirportClass *apclass = AirportClass::Get(_selected_airport_class); - for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) { - const AirportSpec *as = apclass->GetSpec(i); + const auto specs = AirportClass::Get(_selected_airport_class)->Specs(); + auto [first, last] = this->vscroll->GetVisibleRangeIterators(specs); + for (auto it = first; it != last; ++it) { + const AirportSpec *as = *it; if (!as->IsAvailable()) { GfxFillRect(row, PC_BLACK, FILLRECT_CHECKER); } - DrawString(text, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK); + DrawString(text, as->name, (static_cast(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK); row = row.Translate(0, this->line_height); text = text.Translate(0, this->line_height); }