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

@@ -746,9 +746,9 @@ public:
break;
case WID_NG_MATRIX: { // Show available network games
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NG_MATRIX);
this->server = (id_v < this->servers.size()) ? this->servers[id_v] : nullptr;
this->list_pos = (server == nullptr) ? SLP_INVALID : id_v;
auto it = this->vscroll->GetScrolledItemFromWidget(this->servers, pt.y, this, WID_NG_MATRIX);
this->server = (it != this->servers.end()) ? *it : nullptr;
this->list_pos = (server == nullptr) ? SLP_INVALID : it - this->servers.begin();
this->SetDirty();
/* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */