Merge remote-tracking branch 'origin/master' into HEAD
This commit is contained in:
@@ -41,7 +41,7 @@ uint DropDownListStringItem::Width() const
|
||||
|
||||
void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
|
||||
{
|
||||
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), sel ? TC_WHITE : TC_BLACK);
|
||||
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, Center(top, bottom - top), this->String(), sel ? TC_WHITE : TC_BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +97,7 @@ struct DropdownWindow : Window {
|
||||
byte click_delay; ///< Timer to delay selection.
|
||||
bool drag_mode;
|
||||
bool instant_close; ///< Close the window when the mouse button is raised.
|
||||
bool left_button_state; ///< Close the window when the mouse button is clicked outside the window.
|
||||
int scrolling; ///< If non-zero, auto-scroll the item list (one time).
|
||||
GUITimer scrolling_timer; ///< Timer for auto-scroll of the item list.
|
||||
Point position; ///< Position of the topleft corner of the window.
|
||||
@@ -155,9 +156,10 @@ struct DropdownWindow : Window {
|
||||
this->list = list;
|
||||
this->selected_index = selected;
|
||||
this->click_delay = 0;
|
||||
this->drag_mode = true;
|
||||
this->drag_mode = instant_close;
|
||||
this->instant_close = instant_close;
|
||||
this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
|
||||
this->left_button_state = _left_button_down;
|
||||
}
|
||||
|
||||
~DropdownWindow()
|
||||
@@ -265,8 +267,11 @@ struct DropdownWindow : Window {
|
||||
if (this->scrolling != 0) {
|
||||
int pos = this->vscroll->GetPosition();
|
||||
|
||||
this->vscroll->UpdatePosition(this->scrolling);
|
||||
this->scrolling = 0;
|
||||
if (_scroller_click_timeout <= 1) {
|
||||
_scroller_click_timeout = SCROLLER_CLICK_DELAY;
|
||||
this->vscroll->UpdatePosition(this->scrolling);
|
||||
this->scrolling = 0;
|
||||
}
|
||||
|
||||
if (pos != this->vscroll->GetPosition()) {
|
||||
this->SetDirty();
|
||||
@@ -322,6 +327,16 @@ struct DropdownWindow : Window {
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
|
||||
// Close dropdown if user clicks outside of it
|
||||
if (_left_button_down && !this->left_button_state && (
|
||||
_cursor.pos.x < this->left || _cursor.pos.x > this->left + this->width ||
|
||||
_cursor.pos.y < this->top || _cursor.pos.y > this->top + this->height)) {
|
||||
delete this;
|
||||
return;
|
||||
} else {
|
||||
this->left_button_state = _left_button_down;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -368,7 +383,7 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b
|
||||
bool above = false;
|
||||
|
||||
/* Available height below (or above, if the dropdown is placed above the widget). */
|
||||
uint available_height = (uint)max(GetMainViewBottom() - top - 4, 0);
|
||||
uint available_height = (uint)max(_screen.height - top - 4, 0);
|
||||
|
||||
/* If the dropdown doesn't fully fit below the widget... */
|
||||
if (height > available_height) {
|
||||
|
||||
Reference in New Issue
Block a user