Public Member Functions | Data Fields

# DropdownWindow Struct Reference

Drop-down menu window. More...

Inheritance diagram for DropdownWindow:

## Public Member Functions
| DropdownWindow (Window *parent, const 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 (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.
int | parent_button
| Parent widget number where the window is dropped from.
const 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 88 of file dropdown.cpp.

## Constructor & Destructor Documentation

DropdownWindow::DropdownWindow | ( | Window * | parent,
|  | const 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 114 of file dropdown.cpp.

References SmallVector< T, S >::Begin(), click_delay, CLRBITS, NWidgetCore::colour, Window::CreateNestedTree(), SmallVector< T, S >::End(), Window::FinishInitNested(), Window::flags, Window::GetScrollbar(), SmallVector< T, S >::Length(), parent_button, parent_wnd_class, parent_wnd_num, selected_index, Scrollbar::SetCapacity(), Scrollbar::SetCount(), NWidgetResizeBase::SetMinimalSize(), SZSP_NONE, WF_WHITE_BORDER, WID_DM_SCROLL, 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 214 of file dropdown.cpp.

References _colour_gradient, SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), FILLRECT_CHECKER, Scrollbar::GetPosition(), GfxFillRect(), list, DropDownListItem::masked, PC_BLACK, DropDownListItem::result, selected_index, and WID_DM_ITEMS.

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

References SmallVector< T, S >::Begin(), NWidgetBase::current_x, SmallVector< T, S >::End(), 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 243 of file dropdown.cpp.

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

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

Compute the initial position of the window.

Parameters:

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

References position.

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

- src/widgets/dropdown.cpp