OpenTTD Source 20260311-master-g511d3794ce
dropdown_func.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef DROPDOWN_FUNC_H
11#define DROPDOWN_FUNC_H
12
13#include "core/enum_type.hpp"
14#include "dropdown_type.h"
15#include "window_gui.h"
16
17/* Show drop down menu containing a fixed list of strings */
18void ShowDropDownMenu(Window *w, std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0, DropDownOptions options = {}, std::string * const persistent_filter_text = nullptr);
19
20/* Helper functions for commonly used drop down list items. */
21std::unique_ptr<DropDownListItem> MakeDropDownListDividerItem();
22std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(StringID str, int value, bool masked = false, bool shaded = false);
23std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(std::string &&str, int value, bool masked = false, bool shaded = false);
24std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false);
25std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false);
26std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked = false, bool shaded = false, uint indent = 0);
27
29template <typename EnumType> requires is_scoped_enum_v<EnumType>
30inline std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(StringID str, EnumType value, bool masked = false, bool shaded = false)
31{
32 return MakeDropDownListStringItem(str, to_underlying(value), masked, shaded);
33}
34
36template <typename EnumType> requires is_scoped_enum_v<EnumType>
37inline std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(std::string &&str, EnumType value, bool masked = false, bool shaded = false)
38{
39 return MakeDropDownListStringItem(std::move(str), to_underlying(value), masked, shaded);
40}
41
43template <typename EnumType> requires is_scoped_enum_v<EnumType>
44inline std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, EnumType value, bool masked = false, bool shaded = false)
45{
46 return MakeDropDownListIconItem(sprite, palette, str, to_underlying(value), masked, shaded);
47}
48
50template <typename EnumType> requires is_scoped_enum_v<EnumType>
51inline std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, EnumType value, bool masked = false, bool shaded = false)
52{
53 return MakeDropDownListIconItem(dim, sprite, palette, str, to_underlying(value), masked, shaded);
54}
55
57template <typename EnumType> requires is_scoped_enum_v<EnumType>
58inline std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, EnumType value, bool masked = false, bool shaded = false, uint indent = 0)
59{
60 return MakeDropDownListCheckedItem(checked, str, to_underlying(value), masked, shaded, indent);
61}
62
63#endif /* DROPDOWN_FUNC_H */
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
Definition dropdown.cpp:36
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked=false, bool shaded=false)
Creates new DropDownListIconItem.
Definition dropdown.cpp:70
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked=false, bool shaded=false)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked=false, bool shaded=false, uint indent=0)
Creates new DropDownListCheckedItem.
Definition dropdown.cpp:94
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width=0, DropDownOptions options={}, std::string *const persistent_filter_text=nullptr)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:627
Types related to the drop down widget.
Type (helpers) for enums.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
constexpr bool is_scoped_enum_v
Implementation of std::is_scoped_enum_v (from C++23).
Definition enum_type.hpp:24
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Data structure for an opened window.
Definition window_gui.h:274
Functions, definitions and such used only by the GUI.
int WidgetID
Widget ID.
Definition window_type.h:20