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:
Peter Nelson
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

@@ -425,13 +425,13 @@ struct ScriptSettingsWindow : public Window {
{
switch (widget) {
case WID_SCRS_BACKGROUND: {
Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
if (num >= (int)this->visible_settings.size()) break;
auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
if (it == this->visible_settings.end()) break;
const ScriptConfigItem &config_item = *this->visible_settings[num];
const ScriptConfigItem &config_item = **it;
if (!this->IsEditableItem(config_item)) return;
int num = it - this->visible_settings.begin();
if (this->clicked_row != num) {
this->CloseChildWindows(WC_QUERY_STRING);
HideDropDownMenu(this);
@@ -441,6 +441,7 @@ struct ScriptSettingsWindow : public Window {
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
int x = pt.x - r.left;
if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;