# DropdownWindow Struct Reference

Drop-down menu window. More...

Inheritance diagram for DropdownWindow:

## Public Member Functions
| DropdownWindow (Window *parent, DropDownList *list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
| Create a dropdown menu.
virtual Point | OnInitialPosition (const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
| Compute the initial position of the window.
bool | GetDropDownItem (int &value)
| Find the dropdown item under the cursor.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual void | OnClick (Point pt, int widget, int click_count)
| A click with the left mouse button has been made on the window.
virtual void | OnTick ()
| Called once per (game) tick.
virtual void | OnMouseLoop ()
| Called for every mouse loop run, which is at least once per (game) tick.
## Data Fields
WindowClass | parent_wnd_class
| Parent window class.
WindowNumber | parent_wnd_num
| Parent window number.
byte | parent_button
| Parent widget number where the window is dropped from.
DropDownList * | list
| List with dropdown menu items.
int | selected_index
| Index of the selected item in the list.
byte | click_delay
| Timer to delay selection.
bool | drag_mode
bool | instant_close
| Close the window when the mouse button is raised.
int | scrolling
| If non-zero, auto-scroll the item list (one time).
Point | position
| Position of the topleft corner of the window.
Scrollbar * | vscroll

## Detailed Description

Drop-down menu window.

Definition at line 94 of file dropdown.cpp.

## Constructor & Destructor Documentation

DropdownWindow::DropdownWindow | ( | Window * | parent,
|  | DropDownList * | list,
|  | int | selected,
|  | int | button,
|  | bool | instant_close,
|  | const Point & | position,
|  | const Dimension & | size,
|  | Colours | wi_colour,
|  | bool | scroll |
| ) |  |  | `[inline]`

Create a dropdown menu.

Parameters:

  | parent | Parent window.
  | list | Dropdown item list.
  | selected | Index of the selected item in the list.
  | button | Widget of the parent window doing the dropdown.
  | instant_close | Close the window when the mouse button is raised.
  | position | Topleft position of the dropdown menu window.
  | size | Size of the dropdown menu window.
  | wi_colour | Colour of the parent widget.
  | scroll | Dropdown menu has a scrollbar.
  | widget | Widgets of the dropdown menu window.

Definition at line 120 of file dropdown.cpp.

References click_delay, NWidgetCore::colour, Window::CreateNestedTree(), DDM_ITEMS, DDM_SCROLL, DDM_SHOW_SCROLL, Window::FinishInitNested(), Window::flags4, Window::GetScrollbar(), parent_button, parent_wnd_class, parent_wnd_num, selected_index, Scrollbar::SetCapacity(), Scrollbar::SetCount(), NWidgetResizeBase::SetMinimalSize(), SZSP_NONE, WD_VSCROLLBAR_WIDTH, Window::window_class, and Window::window_number.

## Member Function Documentation

virtual void DropdownWindow::DrawWidget | ( | const Rect & | r,
|  | int | widget |
| ) |  |  | const`[inline, virtual]`

Draw the contents of a nested widget.

Parameters:

  | r | Rectangle occupied by the widget.
  | widget | Number of the widget to draw.

Note:
  This method may not change any state, it may only use drawing functions.

Reimplemented from Window.

Definition at line 222 of file dropdown.cpp.

References _colour_gradient, DDM_ITEMS, FILLRECT_CHECKER, Scrollbar::GetPosition(), GfxFillRect(), list, DropDownListItem::masked, DropDownListItem::result, and selected_index.

bool DropdownWindow::GetDropDownItem | ( | int & | value | ) | `[inline]`

Find the dropdown item under the cursor.

Parameters:

  | value | [out] Selected item, if function returns `true`.

Returns:
  Cursor points to a dropdown item.

Definition at line 192 of file dropdown.cpp.

References NWidgetBase::current_x, DDM_ITEMS, Scrollbar::GetPosition(), GetWidgetFromPos(), list, DropDownListItem::masked, NWidgetBase::pos_y, DropDownListItem::result, and Window::width.

Referenced by OnClick(), and OnMouseLoop().

virtual void DropdownWindow::OnClick | ( | Point | pt,
|  | int | widget,
|  | int | click_count |
| ) |  |  | `[inline, virtual]`

A click with the left mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.
  | click_count | Number of fast consecutive clicks at same position

Reimplemented from Window.

Definition at line 251 of file dropdown.cpp.

References click_delay, DDM_ITEMS, GetDropDownItem(), selected_index, and Window::SetDirty().

virtual Point DropdownWindow::OnInitialPosition | ( | const WindowDesc * | desc,
|  | int16 | sm_width,
|  | int16 | sm_height,
|  | int | window_number |
| ) |  |  | `[inline, virtual]`

Compute the initial position of the window.

Parameters:

  | *desc | The pointer to the WindowDesc of the window to create.
  | sm_width | Smallest width of the window.
  | sm_height | Smallest height of the window.
  | window_number | The window number of the new window.

Returns:
  Initial position of the top-left corner of the window.

Reimplemented from Window.

Definition at line 182 of file dropdown.cpp.

References position.

The documentation for this struct was generated from the following file:

- src/widgets/dropdown.cpp