Change: Make all dropdown lists extend width if necessary.

This removes the auto_width parameter from ShowDropDown(At).
pull/510/head
Peter Nelson 1 year ago committed by PeterN
parent 5bc9d00735
commit e5af5907ec

@ -314,7 +314,7 @@ struct GSConfigWindow : public Window {
list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); 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)) { } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {

@ -3078,7 +3078,7 @@ struct IndustryCargoesWindow : public Window {
} }
if (!lst.empty()) { if (!lst.empty()) {
int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1; 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; break;
} }
@ -3092,7 +3092,7 @@ struct IndustryCargoesWindow : public Window {
} }
if (!lst.empty()) { if (!lst.empty()) {
int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1; 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; break;
} }

@ -577,7 +577,7 @@ struct MusicTrackSelectionWindow : public Window {
case WID_MTS_MUSICSET: { case WID_MTS_MUSICSET: {
int selected = 0; int selected = 0;
ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget, 0, true, false); ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget);
break; break;
} }

@ -1571,7 +1571,7 @@ private:
wi_rect.bottom = pt.y; wi_rect.bottom = pt.y;
w->dd_client_id = client_id; 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; wi_rect.bottom = pt.y;
w->dd_company_id = company_id; 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. * Chat button on a Client is clicked.

@ -382,7 +382,7 @@ struct NewGRFParametersWindow : public Window {
list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false)); 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)) { } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {

@ -477,7 +477,7 @@ struct ScriptSettingsWindow : public Window {
list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); 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)) { } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {

@ -2257,7 +2257,7 @@ struct GameSettingsWindow : Window {
list.emplace_back(new DropDownListStringItem(sd->str_val + i - sd->min, i, false)); 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(); this->SetDirty();

@ -190,7 +190,7 @@ public:
*/ */
static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def) 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); 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_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS))); 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -715,7 +715,7 @@ static CallBackFunction ToolbarGraphsClick(Window *w)
if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list); 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
@ -728,7 +728,7 @@ static CallBackFunction ToolbarLeagueClick(Window *w)
AddDropDownLeagueTableOptions(list); AddDropDownLeagueTableOptions(list);
int selected = list[0]->result; 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
@ -905,7 +905,7 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
static CallBackFunction ToolbarBuildRailClick(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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -927,7 +927,7 @@ static CallBackFunction MenuClickBuildRail(int index)
static CallBackFunction ToolbarBuildRoadClick(Window *w) 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -949,7 +949,7 @@ static CallBackFunction MenuClickBuildRoad(int index)
static CallBackFunction ToolbarBuildTramClick(Window *w) 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -973,7 +973,7 @@ static CallBackFunction ToolbarBuildWaterClick(Window *w)
{ {
DropDownList list; DropDownList list;
list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false)); 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -996,7 +996,7 @@ static CallBackFunction ToolbarBuildAirClick(Window *w)
{ {
DropDownList list; DropDownList list;
list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false)); 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; 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_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_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)); 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -1255,7 +1255,7 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w)
static CallBackFunction ToolbarScenBuildRoadClick(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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }
@ -1275,7 +1275,7 @@ static CallBackFunction ToolbarScenBuildRoad(int index)
static CallBackFunction ToolbarScenBuildTramClick(Window *w) 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); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE; return CBF_NONE;
} }

@ -351,12 +351,10 @@ struct DropdownWindow : Window {
* @param button The widget which is passed to Window::OnDropdownSelect and OnDropdownClose. * @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. * 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 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 * @param instant_close Set to true if releasing mouse button should close the
* list regardless of where the cursor is. * 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); 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 */ /* The preferred width equals the calling widget */
uint width = wi_rect.Width(); 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; uint max_item_width = 0;
/* Total height of list */ /* Total height of list */
@ -374,10 +372,10 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
for (const auto &item : list) { for (const auto &item : list) {
height += item->Height(width); 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? */ /* Scrollbar needed? */
bool scroll = false; 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}; 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}; 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 selected The initially selected list item.
* @param button The widget within the parent window that is used to determine * @param button The widget within the parent window that is used to determine
* the list's location. * the list's location.
* @param width Override the width determined by the selected widget. * @param width Override the minimum width determined by the selected widget and list contents.
* @param auto_width Maximum width is determined by the widest item in the list.
* @param instant_close Set to true if releasing mouse button should close the * @param instant_close Set to true if releasing mouse button should close the
* list regardless of where the cursor is. * 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 /* Our parent's button widget is used to determine where to place the drop
* down list window. */ * 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 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 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 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) void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
{ {

@ -98,8 +98,8 @@ public:
*/ */
typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList; 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 */ #endif /* WIDGETS_DROPDOWN_TYPE_H */

Loading…
Cancel
Save