diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index cdac18e94c..fc53f9a43a 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -314,7 +314,7 @@ struct GSConfigWindow : public Window { list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); } - ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true); + ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE); } } } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) { diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 0508acd5a7..b1aa3dc4e1 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3078,7 +3078,7 @@ struct IndustryCargoesWindow : public Window { } if (!lst.empty()) { int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1; - ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN, 0, true); + ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN); } break; } @@ -3092,7 +3092,7 @@ struct IndustryCargoesWindow : public Window { } if (!lst.empty()) { int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1; - ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN, 0, true); + ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN); } break; } diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 7841bbf0d2..c10979041e 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -577,7 +577,7 @@ struct MusicTrackSelectionWindow : public Window { case WID_MTS_MUSICSET: { int selected = 0; - ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget, 0, true, false); + ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget); break; } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 40f1bb64e6..cf79efea32 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1571,7 +1571,7 @@ private: wi_rect.bottom = pt.y; w->dd_client_id = client_id; - ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true, true); + ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true); } /** @@ -1593,7 +1593,7 @@ private: wi_rect.bottom = pt.y; w->dd_company_id = company_id; - ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true, true); + ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true); } /** * Chat button on a Client is clicked. diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index bb671f1e2a..23f8816ec1 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -382,7 +382,7 @@ struct NewGRFParametersWindow : public Window { list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false)); } - ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true); + ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE); } } } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) { diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 78f34f7646..fd4017c48b 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -477,7 +477,7 @@ struct ScriptSettingsWindow : public Window { list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); } - ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true); + ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE); } } } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 36318d0a94..f5f1002164 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2257,7 +2257,7 @@ struct GameSettingsWindow : Window { list.emplace_back(new DropDownListStringItem(sd->str_val + i - sd->min, i, false)); } - ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE, true); + ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE); } } this->SetDirty(); diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 554adf9ba5..b00a8154c2 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -190,7 +190,7 @@ public: */ static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def) { - ShowDropDownList(w, std::move(list), def, widget, 0, true, true); + ShowDropDownList(w, std::move(list), def, widget, 0, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); } @@ -344,7 +344,7 @@ static CallBackFunction ToolbarOptionsClick(Window *w) list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES))); list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS))); - ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true, true); + ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -715,7 +715,7 @@ static CallBackFunction ToolbarGraphsClick(Window *w) if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list); - ShowDropDownList(w, std::move(list), GRMN_OPERATING_PROFIT_GRAPH, WID_TN_GRAPHS, 140, true, true); + ShowDropDownList(w, std::move(list), GRMN_OPERATING_PROFIT_GRAPH, WID_TN_GRAPHS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; @@ -728,7 +728,7 @@ static CallBackFunction ToolbarLeagueClick(Window *w) AddDropDownLeagueTableOptions(list); int selected = list[0]->result; - ShowDropDownList(w, std::move(list), selected, WID_TN_LEAGUE, 140, true, true); + ShowDropDownList(w, std::move(list), selected, WID_TN_LEAGUE, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; @@ -905,7 +905,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; } @@ -927,7 +927,7 @@ static CallBackFunction MenuClickBuildRail(int index) static CallBackFunction ToolbarBuildRoadClick(Window *w) { - ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true, true); + ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -949,7 +949,7 @@ static CallBackFunction MenuClickBuildRoad(int index) static CallBackFunction ToolbarBuildTramClick(Window *w) { - ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true, true); + ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -973,7 +973,7 @@ static CallBackFunction ToolbarBuildWaterClick(Window *w) { DropDownList list; list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false)); - ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true); + ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -996,7 +996,7 @@ static CallBackFunction ToolbarBuildAirClick(Window *w) { DropDownList list; list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false)); - ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true); + ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -1021,7 +1021,7 @@ static CallBackFunction ToolbarForestClick(Window *w) list.emplace_back(new DropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false)); list.emplace_back(new DropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false)); list.emplace_back(new DropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false)); - ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true, true); + ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -1255,7 +1255,7 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w) static CallBackFunction ToolbarScenBuildRoadClick(Window *w) { - ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true, true); + ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -1275,7 +1275,7 @@ static CallBackFunction ToolbarScenBuildRoad(int index) static CallBackFunction ToolbarScenBuildTramClick(Window *w) { - ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true, true); + ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 165c2b2f52..d036f3f694 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -351,12 +351,10 @@ struct DropdownWindow : Window { * @param button The widget which is passed to Window::OnDropdownSelect and OnDropdownClose. * Unless you override those functions, this should be then widget index of the dropdown button. * @param wi_rect Coord of the parent drop down button, used to position the dropdown menu. - * @param auto_width The width is determined by the widest item in the list, - * in this case only one of \a left or \a right is used (depending on text direction). * @param instant_close Set to true if releasing mouse button should close the * list regardless of where the cursor is. */ -void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close) +void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool instant_close) { CloseWindowById(WC_DROPDOWN_MENU, 0); @@ -366,7 +364,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button /* The preferred width equals the calling widget */ uint width = wi_rect.Width(); - /* Longest item in the list, if auto_width is enabled */ + /* Longest item in the list */ uint max_item_width = 0; /* Total height of list */ @@ -374,10 +372,10 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button for (const auto &item : list) { height += item->Height(width); - if (auto_width) max_item_width = std::max(max_item_width, item->Width()); + max_item_width = std::max(max_item_width, item->Width()); } - if (auto_width) max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal(); + max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal(); /* Scrollbar needed? */ bool scroll = false; @@ -421,7 +419,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button } } - if (auto_width) width = std::max(width, max_item_width); + width = std::max(width, max_item_width); Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top}; Dimension dw_size = {width, height}; @@ -440,12 +438,11 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button * @param selected The initially selected list item. * @param button The widget within the parent window that is used to determine * the list's location. - * @param width Override the width determined by the selected widget. - * @param auto_width Maximum width is determined by the widest item in the list. + * @param width Override the minimum width determined by the selected widget and list contents. * @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, bool auto_width, bool instant_close) +void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool instant_close) { /* Our parent's button widget is used to determine where to place the drop * down list window. */ @@ -468,7 +465,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, } } - ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close); + ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, instant_close); } /** @@ -480,7 +477,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, * @param button Button widget number of the parent window \a w that wants the dropdown menu. * @param disabled_mask Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list). * @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list). - * @param width Width of the dropdown menu. If \c 0, use the width of parent widget \a button. + * @param width Minimum width of the dropdown menu. */ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) { diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h index 2e95b407d7..1414a03080 100644 --- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -98,8 +98,8 @@ public: */ typedef std::vector> DropDownList; -void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false); +void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool instant_close = false); -void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false); +void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool instant_close = false); #endif /* WIDGETS_DROPDOWN_TYPE_H */