Do not auto-close main toolbar menus, disabled autoscroll for dropdown lists

This commit is contained in:
pelya
2014-11-16 04:46:17 +02:00
parent d9f14a5b79
commit 5b874adee8
2 changed files with 14 additions and 14 deletions

View File

@@ -174,7 +174,7 @@ public:
static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
{
if (!_settings_client.gui.vertical_toolbar) {
ShowDropDownList(w, list, def, widget, 0, true, true);
ShowDropDownList(w, list, def, widget, 0, true, list->Length() <= 1);
} else {
Rect wi_rect;
NWidgetCore *nwi = w->GetWidget<NWidgetCore>(widget);
@@ -182,7 +182,7 @@ static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int de
wi_rect.right = nwi->pos_x + nwi->current_x;
wi_rect.top = nwi->pos_y;
wi_rect.bottom = nwi->pos_y + nwi->current_y;
ShowDropDownListAt(w, list, def, widget, wi_rect, nwi->colour, true, true);
ShowDropDownListAt(w, list, def, widget, wi_rect, nwi->colour, true, list->Length() <= 1);
}
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
}
@@ -336,7 +336,7 @@ static CallBackFunction ToolbarOptionsClick(Window *w)
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS));
ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true);
ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
@@ -872,7 +872,7 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
static CallBackFunction ToolbarBuildRailClick(Window *w)
{
ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
@@ -909,7 +909,7 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w)
*list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
break;
}
ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true);
ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, list->Length() <= 1);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}

View File

@@ -154,7 +154,7 @@ 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;
}
@@ -341,10 +341,10 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b
{
DeleteWindowById(WC_DROPDOWN_MENU, 0);
/* The preferred position is just below the dropdown calling widget. */
/* The preferred position is just below the dropdown calling widget */
int top = w->top + wi_rect.bottom + 1;
/* The preferred width equals the calling widget. */
/* The preferred width equals the calling widget */
uint width = wi_rect.right - wi_rect.left + 1;
/* Longest item in the list, if auto_width is enabled */
@@ -371,14 +371,14 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b
int screen_bottom = GetMainViewBottom();
bool scroll = false;
enum { DISPLAY_BORDER = 20 };
enum { DISPLAY_BORDER = 20, TOP_BORDER = 4 };
/* Check if the dropdown will fully fit below the widget. */
if (top + height + DISPLAY_BORDER >= screen_bottom) {
/* If not, check if it will fit above the widget. */
int screen_top = GetMainViewTop();
if (w->top + wi_rect.top > screen_top + height) {
top = w->top + wi_rect.top - height;
if (w->top + wi_rect.top - TOP_BORDER > screen_top + height) {
top = w->top + wi_rect.top - height - TOP_BORDER;
} else {
/* ... and lastly if it won't, enable the scroll bar and fit the
* list in below the widget */
@@ -389,10 +389,10 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b
/* ... and choose whether to put the list above or below the widget. */
bool put_above = false;
int available_height = screen_bottom - w->top - wi_rect.bottom - DISPLAY_BORDER;
int available_height = screen_bottom - w->top - wi_rect.bottom;
if (w->top + wi_rect.top - screen_top > available_height) {
// Put it above.
available_height = w->top + wi_rect.top - screen_top - DISPLAY_BORDER;
available_height = w->top + wi_rect.top - screen_top - DISPLAY_BORDER - TOP_BORDER;
put_above = true;
}
@@ -408,7 +408,7 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b
/* ... and set the top position if needed. */
if (put_above) {
top = w->top + wi_rect.top - height;
top = w->top + wi_rect.top - height - TOP_BORDER;
}
}
}