OpenTTD Source  14.0-beta1
dropdown.cpp File Reference
#include "../stdafx.h"
#include "../window_gui.h"
#include "../string_func.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "../zoom_func.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "dropdown_type.h"
#include "dropdown_widget.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  DropdownWindow
 Drop-down menu window. More...
 

Functions

Dimension GetDropDownListDimension (const DropDownList &list)
 Determine width and height required to fully display a DropDownList. More...
 
void ShowDropDownListAt (Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close)
 Show a drop down list. More...
 
void ShowDropDownList (Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
 Show a drop down list. More...
 
void ShowDropDownMenu (Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
 Show a dropdown menu window near a widget of the parent window. More...
 

Variables

static constexpr NWidgetPart _nested_dropdown_menu_widgets []
 
static WindowDesc _dropdown_desc (__FILE__, __LINE__, WDP_MANUAL, nullptr, 0, 0, WC_DROPDOWN_MENU, WC_NONE, WDF_NO_FOCUS, std::begin(_nested_dropdown_menu_widgets), std::end(_nested_dropdown_menu_widgets))
 

Detailed Description

Implementation of the dropdown widget.

Definition in file dropdown.cpp.

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 310 of file dropdown.cpp.

References WidgetDimensions::dropdowntext, RectPadding::Horizontal(), and WidgetDimensions::scaled.

Referenced by DropdownWindow::UpdateSizeAndPosition().

◆ ShowDropDownList()

void ShowDropDownList ( Window w,
DropDownList &&  list,
int  selected,
WidgetID  button,
uint  width,
bool  instant_close 
)

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.
instant_closeSet to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 349 of file dropdown.cpp.

References NWidgetCore::colour, Window::GetWidget(), and NWidgetBase::type.

Referenced by GenerateLandscapeWindow::OnClick(), PopupMainToolbarMenu(), and ShowDropDownMenu().

◆ ShowDropDownListAt()

void ShowDropDownListAt ( Window w,
DropDownList &&  list,
int  selected,
WidgetID  button,
Rect  wi_rect,
Colours  wi_colour,
bool  instant_close 
)

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.
instant_closeSet to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 332 of file dropdown.cpp.

References CloseWindowByClass(), and WC_DROPDOWN_MENU.

◆ ShowDropDownMenu()

void ShowDropDownMenu ( Window w,
const StringID strings,
int  selected,
WidgetID  button,
uint32_t  disabled_mask,
uint32_t  hidden_mask,
uint  width 
)

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, end with INVALID_STRING_ID
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.

Definition at line 386 of file dropdown.cpp.

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

Variable Documentation

◆ _nested_dropdown_menu_widgets

constexpr NWidgetPart _nested_dropdown_menu_widgets[]
staticconstexpr
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition: dropdown_widget.h:17
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition: dropdown_widget.h:15
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition: dropdown_widget.h:16
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82