mirror of https://github.com/OpenTTD/OpenTTD
(svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
parent
6bae045b4a
commit
3c2f69bf62
|
@ -71,6 +71,7 @@ struct DropdownWindow : Window {
|
||||||
int selected_index;
|
int selected_index;
|
||||||
byte click_delay;
|
byte click_delay;
|
||||||
bool drag_mode;
|
bool drag_mode;
|
||||||
|
bool instant_close;
|
||||||
int scrolling;
|
int scrolling;
|
||||||
|
|
||||||
DropdownWindow(int x, int y, int width, int height, const Widget *widget) : Window(x, y, width, height, WC_DROPDOWN_MENU, widget)
|
DropdownWindow(int x, int y, int width, int height, const Widget *widget) : Window(x, y, width, height, WC_DROPDOWN_MENU, widget)
|
||||||
|
@ -196,7 +197,17 @@ struct DropdownWindow : Window {
|
||||||
|
|
||||||
if (!_left_button_clicked) {
|
if (!_left_button_clicked) {
|
||||||
this->drag_mode = false;
|
this->drag_mode = false;
|
||||||
if (!this->GetDropDownItem(item)) return;
|
if (!this->GetDropDownItem(item)) {
|
||||||
|
if (this->instant_close) {
|
||||||
|
if (GetWidgetFromPos(w2, _cursor.pos.x - w2->left, _cursor.pos.y - w2->top) == this->parent_button) {
|
||||||
|
/* Send event for selected option if we're still
|
||||||
|
* on the parent button of the list. */
|
||||||
|
w2->OnDropdownSelect(this->parent_button, this->selected_index);
|
||||||
|
}
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
this->click_delay = 2;
|
this->click_delay = 2;
|
||||||
} else {
|
} else {
|
||||||
if (_cursor.pos.y <= this->top + 2) {
|
if (_cursor.pos.y <= this->top + 2) {
|
||||||
|
@ -218,7 +229,7 @@ struct DropdownWindow : Window {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width)
|
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool instant_close)
|
||||||
{
|
{
|
||||||
bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
|
bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
|
||||||
|
|
||||||
|
@ -327,6 +338,7 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
|
||||||
dw->selected_index = selected;
|
dw->selected_index = selected;
|
||||||
dw->click_delay = 0;
|
dw->click_delay = 0;
|
||||||
dw->drag_mode = true;
|
dw->drag_mode = true;
|
||||||
|
dw->instant_close = instant_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
|
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
|
||||||
|
|
|
@ -72,7 +72,9 @@ typedef std::list<DropDownListItem *> DropDownList;
|
||||||
* @param width Override the width determined by the selected widget.
|
* @param width Override the width determined by the selected widget.
|
||||||
* If UINT_MAX then the width is determined by the widest item
|
* If UINT_MAX then the width is determined by the widest item
|
||||||
* in the list.
|
* in the list.
|
||||||
|
* @param instant_close Set to true if releasing mouse button should close the
|
||||||
|
* list regardless of where the cursor is.
|
||||||
*/
|
*/
|
||||||
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0);
|
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool instant_close = false);
|
||||||
|
|
||||||
#endif /* WIDGETS_DROPDOWN_TYPE_H */
|
#endif /* WIDGETS_DROPDOWN_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue