diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index b145e34696..891e9febc6 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -402,7 +402,7 @@ public: break; case WID_RV_SORT_DROPDOWN: - SetDParam(0, _engine_sort_listing[this->window_number][this->sort_criteria]); + SetDParam(0, std::data(_engine_sort_listing[this->window_number])[this->sort_criteria]); break; case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: { diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 9b5daa0f43..6c587e794b 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -484,7 +484,7 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{ }}; /** Dropdown menu strings for the vehicle sort criteria. */ -const StringID _engine_sort_listing[][12] = {{ +const std::initializer_list _engine_sort_listing[] = {{ /* Trains */ STR_SORT_BY_ENGINE_ID, STR_SORT_BY_COST, @@ -1747,7 +1747,7 @@ struct BuildVehicleWindow : Window { break; case WID_BV_SORT_DROPDOWN: - SetDParam(0, _engine_sort_listing[this->vehicle_type][this->sort_criteria]); + SetDParam(0, std::data(_engine_sort_listing[this->vehicle_type])[this->sort_criteria]); break; case WID_BV_CARGO_FILTER_DROPDOWN: diff --git a/src/dropdown.cpp b/src/dropdown.cpp index 6366090b88..da92a0c765 100644 --- a/src/dropdown.cpp +++ b/src/dropdown.cpp @@ -438,7 +438,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID but * @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list). * @param width Minimum width of the dropdown menu. */ -void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width) +void ShowDropDownMenu(Window *w, std::span strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width) { DropDownList list; diff --git a/src/dropdown_func.h b/src/dropdown_func.h index dee640e00f..6aee0066f7 100644 --- a/src/dropdown_func.h +++ b/src/dropdown_func.h @@ -13,7 +13,7 @@ #include "window_gui.h" /* Show drop down menu containing a fixed list of strings */ -void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0); +void ShowDropDownMenu(Window *w, std::span strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0); /* Helper functions for commonly used drop down list items. */ std::unique_ptr MakeDropDownListDividerItem(); diff --git a/src/engine_gui.h b/src/engine_gui.h index ba7e41715f..5e2d5fe336 100644 --- a/src/engine_gui.h +++ b/src/engine_gui.h @@ -49,7 +49,7 @@ extern bool _engine_sort_direction; extern uint8_t _engine_sort_last_criteria[]; extern bool _engine_sort_last_order[]; extern bool _engine_sort_show_hidden_engines[]; -extern const StringID _engine_sort_listing[][12]; +extern const std::initializer_list _engine_sort_listing[]; extern EngList_SortTypeFunction * const _engine_sort_functions[][11]; /* Functions in build_vehicle_gui.cpp */ diff --git a/src/gfx.cpp b/src/gfx.cpp index 0292dff16a..b3bdc79998 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -868,10 +868,10 @@ Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize) * @param fontsize Font size to use. * @return Width of longest string within the list. */ -uint GetStringListWidth(const StringID *list, FontSize fontsize) +uint GetStringListWidth(std::span list, FontSize fontsize) { uint width = 0; - for (const StringID *str = list; *str != INVALID_STRING_ID; str++) { + for (const StringID *str = list.data(); *str != INVALID_STRING_ID; str++) { width = std::max(width, GetStringBoundingBox(*str, fontsize).width); } return width; diff --git a/src/gfx_func.h b/src/gfx_func.h index 7d6aff7c07..592bcc5a8d 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -133,7 +133,7 @@ inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_ Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL); -uint GetStringListWidth(const StringID *list, FontSize fontsize = FS_NORMAL); +uint GetStringListWidth(std::span list, FontSize fontsize = FS_NORMAL); int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMAL); int GetStringHeight(StringID str, int maxw); int GetStringLineCount(StringID str, int maxw); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 64b81228fb..b355e9f98f 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -588,7 +588,7 @@ public: this->GetWidget(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype; /* Set text of "group by" dropdown widget. */ - this->GetWidget(WID_GL_GROUP_BY_DROPDOWN)->widget_data = this->vehicle_group_by_names[this->grouping]; + this->GetWidget(WID_GL_GROUP_BY_DROPDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping]; /* Set text of "sort by" dropdown widget. */ this->GetWidget(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()]; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 240a5cb9c5..6d85048134 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -94,7 +94,7 @@ const std::initializer_list, }; -const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[] = { +const std::initializer_list BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar = { STR_SORT_BY_NUMBER, STR_SORT_BY_NAME, STR_SORT_BY_AGE, @@ -111,7 +111,7 @@ const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[] INVALID_STRING_ID }; -const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock[] = { +const std::initializer_list BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock = { STR_SORT_BY_NUMBER, STR_SORT_BY_NAME, STR_SORT_BY_AGE, @@ -136,7 +136,7 @@ const std::initializer_list BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar = { STR_SORT_BY_NUM_VEHICLES, STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR, STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR, @@ -145,7 +145,7 @@ const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_c INVALID_STRING_ID }; -const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock[] = { +const std::initializer_list BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock = { STR_SORT_BY_NUM_VEHICLES, STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD, STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD, @@ -154,7 +154,7 @@ const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_w INVALID_STRING_ID }; -const StringID BaseVehicleListWindow::vehicle_group_by_names[] = { +const std::initializer_list BaseVehicleListWindow::vehicle_group_by_names = { STR_GROUP_BY_NONE, STR_GROUP_BY_SHARED_ORDERS, INVALID_STRING_ID @@ -174,7 +174,7 @@ BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) this->UpdateSortingFromGrouping(); } -const StringID *BaseVehicleListWindow::GetVehicleSorterNames() +std::span BaseVehicleListWindow::GetVehicleSorterNames() { switch (this->grouping) { case GB_NONE: @@ -2048,7 +2048,7 @@ public: } /* Set text of group by dropdown widget. */ - this->GetWidget(WID_VL_GROUP_BY_PULLDOWN)->widget_data = this->vehicle_group_by_names[this->grouping]; + this->GetWidget(WID_VL_GROUP_BY_PULLDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping]; /* Set text of sort by dropdown widget. */ this->GetWidget(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()]; diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 4b4519b225..73036fefe3 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -98,11 +98,11 @@ struct BaseVehicleListWindow : public Window { }; static const StringID vehicle_depot_name[]; - static const StringID vehicle_group_by_names[]; - static const StringID vehicle_group_none_sorter_names_calendar[]; - static const StringID vehicle_group_none_sorter_names_wallclock[]; - static const StringID vehicle_group_shared_orders_sorter_names_calendar[]; - static const StringID vehicle_group_shared_orders_sorter_names_wallclock[]; + static const std::initializer_list vehicle_group_by_names; + static const std::initializer_list vehicle_group_none_sorter_names_calendar; + static const std::initializer_list vehicle_group_none_sorter_names_wallclock; + static const std::initializer_list vehicle_group_shared_orders_sorter_names_calendar; + static const std::initializer_list vehicle_group_shared_orders_sorter_names_wallclock; static const std::initializer_list vehicle_group_none_sorter_funcs; static const std::initializer_list vehicle_group_shared_orders_sorter_funcs; @@ -124,7 +124,7 @@ struct BaseVehicleListWindow : public Window { Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create); DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create); - const StringID *GetVehicleSorterNames(); + std::span GetVehicleSorterNames(); std::span GetVehicleSorterFuncs() {