Codechange: Add and use GetScrolledItemFromWidget to get a list item.

This function returns an iterator, either to the selected item or the
container's end.

This makes handling the result more robust as indices are not used.
This commit is contained in:
Peter Nelson
2023-05-12 12:58:31 +01:00
committed by PeterN
parent 86e5dfce3d
commit 941dbadf9e
16 changed files with 91 additions and 74 deletions

View File

@@ -1454,9 +1454,9 @@ public:
break;
case WID_BRAS_NEWST_LIST: {
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BRAS_NEWST_LIST);
if (y >= (int)this->station_classes.size()) return;
StationClassID station_class_id = this->station_classes[y];
auto it = this->vscroll->GetScrolledItemFromWidget(this->station_classes, pt.y, this, WID_BRAS_NEWST_LIST);
if (it == this->station_classes.end()) return;
StationClassID station_class_id = *it;
if (_railstation.station_class != station_class_id) {
StationClass *station_class = StationClass::Get(station_class_id);
_railstation.station_class = station_class_id;