Changeset - r27083:acaaba32287a
[Not reviewed]
master
0 10 0
Peter Nelson - 20 months ago 2023-04-11 19:07:50
peter1138@openttd.org
Change: Make all dropdown lists extend width if necessary.

This removes the auto_width parameter from ShowDropDown(At).
10 files changed with 32 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/game/game_gui.cpp
Show inline comments
 
@@ -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)) {
src/industry_gui.cpp
Show inline comments
 
@@ -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;
 
			}
src/music_gui.cpp
Show inline comments
 
@@ -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;
 
			}
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -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.
src/newgrf_gui.cpp
Show inline comments
 
@@ -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)) {
src/script/script_gui.cpp
Show inline comments
 
@@ -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)) {
src/settings_gui.cpp
Show inline comments
 
@@ -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();
src/toolbar_gui.cpp
Show inline comments
 
@@ -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;
 
}
src/widgets/dropdown.cpp
Show inline comments
 
@@ -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)
 
{
src/widgets/dropdown_type.h
Show inline comments
 
@@ -98,8 +98,8 @@ public:
 
 */
 
typedef std::vector<std::unique_ptr<const DropDownListItem>> 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 */
0 comments (0 inline, 0 general)