# 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 | OnPaint ()
| The window must be repainted.
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.

## Detailed Description

Drop-down menu window.

Definition at line 91 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 115 of file dropdown.cpp.

References NWidgetCore::colour, DDM_ITEMS, DDM_SCROLL, DropDownListItem::Height(), Dimension::height, NWidgetResizeBase::min_x, NWidgetResizeBase::SetMinimalSize(), WD_VSCROLLBAR_WIDTH, Dimension::width, Window::window_class, and Window::window_number.

## Member Function Documentation

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

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

References NWidgetBase::current_x, DDM_ITEMS, GetWidgetFromPos(), DropDownListItem::Height(), DropDownListItem::masked, CursorVars::pos, NWidgetBase::pos_y, DropDownListItem::result, DropDownListItem::Selectable(), Point::x, and Point::y.

virtual void DropdownWindow::OnPaint | ( |  | ) | `[inline, virtual]`

The window must be repainted.

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

Reimplemented from Window.

Definition at line 216 of file dropdown.cpp.

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

References _colour_gradient, Rect::bottom, DDM_ITEMS, DropDownListItem::Draw(), FILLRECT_CHECKER, GfxFillRect(), DropDownListItem::Height(), Rect::left, DropDownListItem::masked, DropDownListItem::result, Rect::right, and Rect::top.

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

References DDM_ITEMS.

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

- src/widgets/dropdown.cpp