Fix dec7ff6b0c
: Dropdowns couldn't be closed by pressing the parent button. (#10954)
Since dropdowns self-close, the detection of re-clicking a dropdown button no longer worked, as the dropdown is already closed. Instead set (and then test) a flag on the parent widget to indicate that the dropdown closed. This method avoids looping windows on every click.
This commit is contained in:
@@ -191,6 +191,10 @@ struct DropdownWindow : Window {
|
||||
pt.x -= this->parent->left;
|
||||
pt.y -= this->parent->top;
|
||||
this->parent->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
|
||||
|
||||
/* Set flag on parent widget to indicate that we have just closed. */
|
||||
NWidgetCore *nwc = this->parent->GetWidget<NWidgetCore>(this->parent_button);
|
||||
if (nwc != nullptr) SetBit(nwc->disp_flags, NDB_DROPDOWN_CLOSED);
|
||||
}
|
||||
|
||||
void OnFocusLost() override
|
||||
@@ -471,25 +475,3 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
|
||||
|
||||
if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the drop-down menu from window \a pw
|
||||
* @param pw Parent window of the drop-down menu window
|
||||
* @return Parent widget number if the drop-down was found and closed, \c -1 if the window was not found.
|
||||
*/
|
||||
int HideDropDownMenu(Window *pw)
|
||||
{
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if (w->parent != pw) continue;
|
||||
if (w->window_class != WC_DROPDOWN_MENU) continue;
|
||||
|
||||
DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
|
||||
assert(dw != nullptr);
|
||||
int parent_button = dw->parent_button;
|
||||
dw->Close();
|
||||
return parent_button;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user