OpenTTD Source: src/widgets/dropdown.cpp File Reference

OpenTTD Source 13.1

Data Structures | Functions | Variables
dropdown.cpp File Reference
`#include "../stdafx.h"`
`#include "../window_gui.h"`
`#include "../string_func.h"`
`#include "../strings_func.h"`
`#include "../window_func.h"`
`#include "../guitimer_func.h"`
`#include "../zoom_func.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
void | ShowDropDownListAt (Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
| Show a drop down list. More...
void | ShowDropDownList (Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
| Show a drop down list. More...
void | ShowDropDownMenu (Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
| Show a dropdown menu window near a widget of the parent window. More...
int | HideDropDownMenu (Window *pw)
| Delete the drop-down menu from window pw. More...

## Variables
static const NWidgetPart | _nested_dropdown_menu_widgets []
static WindowDesc | _dropdown_desc (WDP_MANUAL, nullptr, 0, 0, WC_DROPDOWN_MENU, WC_NONE, WDF_NO_FOCUS, _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets))

## Detailed Description

Implementation of the dropdown widget.

Definition in file dropdown.cpp.

## Function Documentation

## ◆ HideDropDownMenu()

int HideDropDownMenu | ( | Window * | pw | ) |

Delete the drop-down menu from window pw.

Parameters

  pw | Parent window of the drop-down menu window

Returns
  Parent widget number if the drop-down was found and closed, `-1` if the window was not found.

Definition at line 505 of file dropdown.cpp.

References DropdownWindow::Close(), DropdownWindow::parent_button, DropdownWindow::parent_wnd_class, DropdownWindow::parent_wnd_num, WC_DROPDOWN_MENU, Window::window_class, and Window::window_number.

Referenced by NewGRFParametersWindow::OnClick(), AISettingsWindow::OnClick(), AISettingsWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), VehicleGroupWindow::OnPaint(), and VehicleListWindow::OnPaint().

## ◆ ShowDropDownList()

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

Show a drop down list.

Parameters

  w | Parent window for the list.
  list | Prepopulated DropDownList.
  selected | The initially selected list item.
  button | The widget within the parent window that is used to determine the list's location.
  width | Override the width determined by the selected widget.
  auto_width | Maximum width is determined by the widest item in the list.
  instant_close | Set to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 450 of file dropdown.cpp.

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

Referenced by BuildAirportWindow::OnClick(), ReplaceVehicleWindow::OnClick(), GenerateLandscapeWindow::OnClick(), StoryBookWindow::OnClick(), CreateScenarioWindow::OnClick(), NetworkClientListWindow::OnClick(), GameSettingsWindow::OnClick(), PopupMainToolbMenu(), and ShowDropDownMenu().

## ◆ ShowDropDownListAt()

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

Show a drop down list.

Parameters

  w | Parent window for the list.
  list | Prepopulated DropDownList.
  selected | The initially selected list item.
  button | The 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_rect | Coord of the parent drop down button, used to position the dropdown menu.
  auto_width | The width is determined by the widest item in the list, in this case only one of left or right is used (depending on text direction).
  instant_close | Set to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 361 of file dropdown.cpp.

References CloseWindowById(), WidgetDimensions::fullbevel, GetMainViewBottom(), GetMainViewTop(), RectPadding::Horizontal(), WidgetDimensions::scaled, Window::top, WC_DROPDOWN_MENU, and Rect::Width().

## ◆ ShowDropDownMenu()

void ShowDropDownMenu | ( | Window * | w,
|  | const StringID * | strings,
|  | int | selected,
|  | int | button,
|  | uint32 | disabled_mask,
|  | uint32 | 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

  w | Parent window that wants the dropdown menu.
  strings | Menu list, end with INVALID_STRING_ID
  selected | Index of initial selected item.
  button | Button widget number of the parent window w that wants the dropdown menu.
  disabled_mask | Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
  hidden_mask | Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
  width | Width of the dropdown menu. If `0`, use the width of parent widget button.

Definition at line 487 of file dropdown.cpp.

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

Referenced by BuildBridgeWindow::OnClick(), CompanyStationsWindow::OnClick(), VehicleGroupWindow::OnClick(), TownDirectoryWindow::OnClick(), BuildVehicleWindow::OnClick(), IndustryDirectoryWindow::OnClick(), and VehicleDetailsWindow::OnClick().

## Variable Documentation

## ◆ _nested_dropdown_menu_widgets

const NWidgetPart _nested_dropdown_menu_widgets[]
| static

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
EndContainer(),
EndContainer(),
}

Definition at line 104 of file dropdown.cpp.

SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1208
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition: dropdown_widget.h:16
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition: dropdown_widget.h:15
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition: dropdown_widget.h:17