mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-31 10:29:10 +00:00
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:
@@ -799,11 +799,11 @@ public:
|
||||
|
||||
switch (widget) {
|
||||
case WID_NCL_MATRIX: {
|
||||
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX);
|
||||
if (id_v >= this->content.size()) return; // click out of bounds
|
||||
auto it = this->vscroll->GetScrolledItemFromWidget(this->content, pt.y, this, WID_NCL_MATRIX);
|
||||
if (it == this->content.end()) return; // click out of bounds
|
||||
|
||||
this->selected = this->content[id_v];
|
||||
this->list_pos = id_v;
|
||||
this->selected = *it;
|
||||
this->list_pos = it - this->content.begin();
|
||||
|
||||
const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
|
||||
if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user