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

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

#include "core/enum_type.hpp"
#include "stringfilter_type.h"
#include "window_type.h"
#include "gfx_func.h"
#include "gfx_type.h"
#include "palette_func.h"
#include "window_gui.h"

Go to the source code of this file.

Data Structures

class  DropDownListItem
 Base list item class from which others are derived. More...

Typedefs

typedef std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
 A drop down list is a collection of drop down list items.
using DropDownOptions = EnumBitSet<DropDownOption, uint8_t>

Enumerations

enum class  DropDownOption : uint8_t { InstantClose , Persist , Filterable }
 Configuration options for the created DropDownLists. More...

Functions

void ShowDropDownListAt (Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options={}, std::string *const persistent_filter_text=nullptr)
 Show a drop down list.
void ShowDropDownList (Window *w, DropDownList &&list, int selected, WidgetID button, uint width=0, DropDownOptions options={}, std::string *const persistent_filter_text=nullptr)
 Show a drop down list.
Dimension GetDropDownListDimension (const DropDownList &list)
 Determine width and height required to fully display a DropDownList.
void ReplaceDropDownList (Window *parent, DropDownList &&list, std::optional< int > selected_result=std::nullopt)

Detailed Description

Types related to the drop down widget.

Definition in file dropdown_type.h.

Typedef Documentation

◆ DropDownList

typedef std::vector<std::unique_ptr<const DropDownListItem> > DropDownList

A drop down list is a collection of drop down list items.

Definition at line 97 of file dropdown_type.h.

◆ DropDownOptions

using DropDownOptions = EnumBitSet<DropDownOption, uint8_t>

Definition at line 105 of file dropdown_type.h.

Enumeration Type Documentation

◆ DropDownOption

enum class DropDownOption : uint8_t
strong

Configuration options for the created DropDownLists.

Enumerator
InstantClose 

Set if releasing mouse button should close the list regardless of where the cursor is.

Persist 

Set if this dropdown should stay open after an option is selected.

Filterable 

Set if the dropdown is filterable.

Definition at line 100 of file dropdown_type.h.

Function Documentation

◆ GetDropDownListDimension()

Dimension GetDropDownListDimension ( const DropDownList & list)

Determine width and height required to fully display a DropDownList.

Parameters
listThe list.
Returns
Dimension required to display the list.

Definition at line 545 of file dropdown.cpp.

References WidgetDimensions::scaled.

Referenced by DropdownWindow::UpdateSizeAndPosition(), BuildVehicleWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), and VehicleListWindow::UpdateWidgetSize().

◆ ReplaceDropDownList()

void ReplaceDropDownList ( Window * parent,
DropDownList && list,
std::optional< int > selected_result = std::nullopt )

Definition at line 534 of file dropdown.cpp.

◆ ShowDropDownList()

void ShowDropDownList ( Window * w,
DropDownList && list,
int selected,
WidgetID button,
uint width,
DropDownOptions options,
std::string *const persistent_filter_text )

Show a drop down list.

Parameters
wParent window for the list.
listPrepopulated DropDownList.
selectedThe initially selected list item.
buttonThe widget within the parent window that is used to determine the list's location.
widthOverride the minimum width determined by the selected widget and list contents.
optionsDrop Down options for this menu.
persistent_filter_textOptional pointer to string for retaining filter text.

Definition at line 585 of file dropdown.cpp.

References _current_text_dir, NWidgetCore::colour, NWidgetCore::disp_flags, DropdownActive, Window::GetWidget(), NWID_BUTTON_DROPDOWN, Rect, ScaleGUITrad(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), NWidgetBase::SetDirty(), NWidgetCore::SetLowered(), ShowDropDownListAt(), SndClickBeep(), TD_RTL, and NWidgetBase::type.

Referenced by BuildAirportWindow::OnClick(), BuildVehicleWindow::OnClick(), CompanyStationsWindow::OnClick(), CreateScenarioWindow::OnClick(), EnginePreviewWindow::OnClick(), GameOptionsWindow::OnClick(), GenerateLandscapeWindow::OnClick(), IndustryCargoesWindow::OnClick(), IndustryDirectoryWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), NetworkClientListWindow::OnClick(), NetworkStartServerWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), PickerWindow::OnClick(), ReplaceVehicleWindow::OnClick(), StoryBookWindow::OnClick(), TextfileWindow::OnClick(), VehicleGroupWindow::OnClick(), VehicleListWindow::OnClick(), PopupMainToolbarMenu(), SetDateWindow::ShowDateDropDown(), ShowDropDownMenu(), and ToolbarOptionsClick().

◆ ShowDropDownListAt()

void ShowDropDownListAt ( Window * w,
DropDownList && list,
int selected,
WidgetID button,
Rect wi_rect,
Colours wi_colour,
DropDownOptions options,
std::string *const persistent_filter_text )

Show a drop down list.

Parameters
wParent window for the list.
listPrepopulated DropDownList.
selectedThe initially selected list item.
buttonThe widget which is passed to Window::OnDropdownSelect and OnDropdownClose. Unless you override those functions, this should be then widget index of the dropdown button.
wi_rectCoord of the parent drop down button, used to position the dropdown menu.
wi_colourColour of the parent widget.
optionsDrop Down options for this menu.
persistent_filter_textOptional pointer to string for retaining filter text.

Definition at line 568 of file dropdown.cpp.

References CloseWindowByClass(), Rect, and WC_DROPDOWN_MENU.

Referenced by GSConfigWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), NetworkClientListWindow::OnClickClientAdmin(), NetworkClientListWindow::OnClickCompanyAdmin(), and ShowDropDownList().