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:
PeterN
2023-06-07 19:01:30 +01:00
committed by GitHub
parent b2a8d8aea4
commit b49bd86a46
4 changed files with 11 additions and 29 deletions

View File

@@ -22,7 +22,6 @@
#include "tilehighlight_func.h"
#include "network/network.h"
#include "querystring_gui.h"
#include "widgets/dropdown_func.h"
#include "strings_func.h"
#include "settings_type.h"
#include "settings_func.h"
@@ -679,6 +678,9 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
WidgetType widget_type = (nw != nullptr) ? nw->type : WWT_EMPTY;
/* Allow dropdown close flag detection to work. */
if (nw != nullptr) ClrBit(nw->disp_flags, NDB_DROPDOWN_CLOSED);
bool focused_widget_changed = false;
/* If clicked on a window that previously did not have focus */
if (_focused_window != w && // We already have focus, right?
@@ -711,9 +713,8 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
focused_widget_changed |= w->SetFocusedWidget(widget_index);
}
/* Close any child drop down menus. If the button pressed was the drop down
* list's own button, then we should not process the click any further. */
if (HideDropDownMenu(w) == widget_index && widget_index >= 0) return;
/* Dropdown window of this widget was closed so don't process click this time. */
if (HasBit(nw->disp_flags, NDB_DROPDOWN_CLOSED)) return;
if ((widget_type & ~WWB_PUSHBUTTON) < WWT_LAST && (widget_type & WWB_PUSHBUTTON)) w->HandleButtonClick(widget_index);