# HG changeset patch # User Peter Nelson # Date 2023-04-11 19:07:50 # Node ID acaaba32287a15636df65427965bdf3272c3f537 # Parent fad11ce90187e190f2bb623ffdb63b5ddf41757e Change: Make all dropdown lists extend width if necessary. This removes the auto_width parameter from ShowDropDown(At). diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp --- 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 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3078,7 +3078,7 @@ struct IndustryCargoesWindow : public Wi } 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 Wi } 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 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -577,7 +577,7 @@ struct MusicTrackSelectionWindow : publi 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 --- 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 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -382,7 +382,7 @@ struct NewGRFParametersWindow : public W 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 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -477,7 +477,7 @@ struct ScriptSettingsWindow : public Win 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 --- 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 --- 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 ToolbarOptionsCl 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 ToolbarGraphsCli 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 ToolbarLeagueCli 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 ToolbarZoomOutCl 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 MenuClickBuildRa 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 MenuClickBuildRo 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 ToolbarBuildWate { 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 ToolbarBuildAirC { 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 ToolbarForestCli 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 ToolbarScenGenIn 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 ToolbarScenBuild 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 --- 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, DropD /* 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, DropD 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, DropD } } - 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, DropD * @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, DropDow } } - 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, DropDow * @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 --- 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 */