Codechange: Use GetScrolled(Row/Item)FromWidget in more places.

In many instances the clicked row position is 'manually' calculated
instead of using the GetScrolledRowFromWidget helper function, with
variations on checks. Replace with the two helpers where possible.
This commit is contained in:
2023-05-03 11:17:52 +01:00
committed by PeterN
parent 941dbadf9e
commit 531d1ae8bc
9 changed files with 34 additions and 40 deletions

View File

@@ -517,10 +517,10 @@ public:
{
switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: {
int num_clicked = this->vscroll->GetPosition() + (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / this->line_height;
if (num_clicked >= (int)this->object_classes.size()) break;
auto it = this->vscroll->GetScrolledItemFromWidget(this->object_classes, widget, this, pt.y);
if (it == this->object_classes.end()) break;
this->SelectOtherClass(this->object_classes[num_clicked]);
this->SelectOtherClass(*it);
this->SelectFirstAvailableObject(false);
break;
}