OpenTTD Source 20260311-master-g511d3794ce
dropdown_func.h File Reference

Functions related to the drop down widget. More...

#include "core/enum_type.hpp"
#include "dropdown_type.h"
#include "window_gui.h"

Go to the source code of this file.

Functions

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.
std::unique_ptr< DropDownListItemMakeDropDownListDividerItem ()
 Creates new DropDownListDividerItem.
std::unique_ptr< DropDownListItemMakeDropDownListStringItem (StringID str, int value, bool masked=false, bool shaded=false)
 Creates new DropDownListStringItem.
std::unique_ptr< DropDownListItemMakeDropDownListStringItem (std::string &&str, int value, bool masked=false, bool shaded=false)
 Creates new DropDownListStringItem.
std::unique_ptr< DropDownListItemMakeDropDownListIconItem (SpriteID sprite, PaletteID palette, StringID str, int value, bool masked=false, bool shaded=false)
 Creates new DropDownListIconItem.
std::unique_ptr< DropDownListItemMakeDropDownListIconItem (const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked=false, bool shaded=false)
 Creates new DropDownListIconItem.
std::unique_ptr< DropDownListItemMakeDropDownListCheckedItem (bool checked, StringID str, int value, bool masked=false, bool shaded=false, uint indent=0)
 Creates new DropDownListCheckedItem.
template<typename EnumType>
std::unique_ptr< DropDownListItemMakeDropDownListStringItem (StringID str, EnumType value, bool masked=false, bool shaded=false)
 Creates new DropDownListStringItem.
template<typename EnumType>
std::unique_ptr< DropDownListItemMakeDropDownListStringItem (std::string &&str, EnumType value, bool masked=false, bool shaded=false)
 Creates new DropDownListStringItem.
template<typename EnumType>
std::unique_ptr< DropDownListItemMakeDropDownListIconItem (SpriteID sprite, PaletteID palette, StringID str, EnumType value, bool masked=false, bool shaded=false)
 Creates new DropDownListIconItem.
template<typename EnumType>
std::unique_ptr< DropDownListItemMakeDropDownListIconItem (const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, EnumType value, bool masked=false, bool shaded=false)
 Creates new DropDownListIconItem.
template<typename EnumType>
std::unique_ptr< DropDownListItemMakeDropDownListCheckedItem (bool checked, StringID str, EnumType value, bool masked=false, bool shaded=false, uint indent=0)
 Creates new DropDownListCheckedItem.

Detailed Description

Functions related to the drop down widget.

Definition in file dropdown_func.h.

Function Documentation

◆ MakeDropDownListCheckedItem() [1/2]

template<typename EnumType>
std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem ( bool checked,
StringID str,
EnumType value,
bool masked = false,
bool shaded = false,
uint indent = 0 )
inline

Creates new DropDownListCheckedItem.

Parameters
checkedWhether the tick before the string should be visible or not.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
indentBy what factor the tick and string should be indent.
Returns
Unique pointer to newly created drop down item.

Definition at line 58 of file dropdown_func.h.

References MakeDropDownListCheckedItem(), and to_underlying().

◆ MakeDropDownListCheckedItem() [2/2]

std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem ( bool checked,
StringID str,
int value,
bool masked,
bool shaded,
uint indent )

Creates new DropDownListCheckedItem.

Parameters
checkedWhether the tick before the string should be visible or not.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
indentBy what factor the tick and string should be indent.
Returns
Unique pointer to newly created drop down item.

Definition at line 94 of file dropdown.cpp.

References GetString().

Referenced by MakeDropDownListCheckedItem(), and ToolbarOptionsClick().

◆ MakeDropDownListDividerItem()

std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem ( )

◆ MakeDropDownListIconItem() [1/4]

template<typename EnumType>
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem ( const Dimension & dim,
SpriteID sprite,
PaletteID palette,
StringID str,
EnumType value,
bool masked = false,
bool shaded = false )
inline

Creates new DropDownListIconItem.

Parameters
spriteThe sprite id to use as an icon on the side of the string.
paletteThe palette to use when drawing icon.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.
Parameters
dimThe rect specifying what part from the sprite should be used as an icon.

Definition at line 51 of file dropdown_func.h.

References MakeDropDownListIconItem(), and to_underlying().

◆ MakeDropDownListIconItem() [2/4]

std::unique_ptr< DropDownListItem > MakeDropDownListIconItem ( const Dimension & dim,
SpriteID sprite,
PaletteID palette,
StringID str,
int value,
bool masked,
bool shaded )

Creates new DropDownListIconItem.

Parameters
spriteThe sprite id to use as an icon on the side of the string.
paletteThe palette to use when drawing icon.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.
Parameters
dimThe rect specifying what part from the sprite should be used as an icon.

Definition at line 79 of file dropdown.cpp.

References GetString().

◆ MakeDropDownListIconItem() [3/4]

template<typename EnumType>
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem ( SpriteID sprite,
PaletteID palette,
StringID str,
EnumType value,
bool masked = false,
bool shaded = false )
inline

Creates new DropDownListIconItem.

Parameters
spriteThe sprite id to use as an icon on the side of the string.
paletteThe palette to use when drawing icon.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.

Definition at line 44 of file dropdown_func.h.

References MakeDropDownListIconItem(), and to_underlying().

◆ MakeDropDownListIconItem() [4/4]

std::unique_ptr< DropDownListItem > MakeDropDownListIconItem ( SpriteID sprite,
PaletteID palette,
StringID str,
int value,
bool masked,
bool shaded )

Creates new DropDownListIconItem.

Parameters
spriteThe sprite id to use as an icon on the side of the string.
paletteThe palette to use when drawing icon.
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.

Definition at line 70 of file dropdown.cpp.

References GetString().

Referenced by BaseVehicleListWindow::BuildCargoDropDownList(), NWidgetBadgeFilter::GetDropDownList(), MakeDropDownListIconItem(), MakeDropDownListIconItem(), and IndustryCargoesWindow::OnClick().

◆ MakeDropDownListStringItem() [1/4]

template<typename EnumType>
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem ( std::string && str,
EnumType value,
bool masked = false,
bool shaded = false )
inline

Creates new DropDownListStringItem.

Parameters
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.

Definition at line 37 of file dropdown_func.h.

References MakeDropDownListStringItem(), and to_underlying().

◆ MakeDropDownListStringItem() [2/4]

std::unique_ptr< DropDownListItem > MakeDropDownListStringItem ( std::string && str,
int value,
bool masked,
bool shaded )

Creates new DropDownListStringItem.

Parameters
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.

Definition at line 55 of file dropdown.cpp.

◆ MakeDropDownListStringItem() [3/4]

template<typename EnumType>
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem ( StringID str,
EnumType value,
bool masked = false,
bool shaded = false )
inline

Creates new DropDownListStringItem.

Parameters
strThe string to show on this item in the drop down menu.
valueThe value to use when the item becomes selected.
maskedWhether the item should be masked out.
shadedWhether the item should be shaded.
Returns
Unique pointer to newly created drop down item.

Definition at line 30 of file dropdown_func.h.

References MakeDropDownListStringItem(), and to_underlying().

◆ MakeDropDownListStringItem() [4/4]

◆ ShowDropDownMenu()

void ShowDropDownMenu ( Window * w,
std::span< const StringID > strings,
int selected,
WidgetID button,
uint32_t disabled_mask,
uint32_t hidden_mask,
uint width,
DropDownOptions options,
std::string *const persistent_filter_text )

Show a dropdown menu window near a widget of the parent window.

The result code of the items is their index in the strings list.

Parameters
wParent window that wants the dropdown menu.
stringsMenu list.
selectedIndex of initial selected item.
buttonButton widget number of the parent window w that wants the dropdown menu.
disabled_maskBitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
hidden_maskBitmask for hidden items (items with their bit set are not copied to the dropdown list).
widthMinimum width of the dropdown menu.
optionsDrop Down options for this menu
persistent_filter_textOptional pointer to string for retaining filter text.

Definition at line 627 of file dropdown.cpp.

References HasBit(), MakeDropDownListStringItem(), and ShowDropDownList().

Referenced by DisplayVehicleSortDropDown(), BuildBridgeWindow::OnClick(), CompanyStationsWindow::OnClick(), GenerateLandscapeWindow::OnClick(), IndustryDirectoryWindow::OnClick(), OrdersWindow::OnClick(), ReplaceVehicleWindow::OnClick(), StationViewWindow::OnClick(), TownDirectoryWindow::OnClick(), VehicleDetailsWindow::OnClick(), VehicleGroupWindow::OnClick(), and VehicleListWindow::OnClick().