# NWidgetCore Class Reference
[Hierarchical widgets]

Base class for a 'real' widget. More...

`#include <widget_type.h>`

Inheritance diagram for NWidgetCore:

## Public Member Functions
| NWidgetCore (WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint16 widget_data, StringID tool_tip)
| Initialization of a 'real' widget.
void | SetIndex (int index)
| Set index of the nested widget in the widget array.
void | SetDataTip (uint16 widget_data, StringID tool_tip)
| Set data and tool tip of the nested widget.
void | SetLowered (bool lowered)
| Lower or raise the widget.
bool | IsLowered () const
| Return whether the widget is lowered.
void | SetDisabled (bool disabled)
| Disable (grey-out) or enable the widget.
bool | IsDisabled () const
| Return whether the widget is disabled.
void | FillNestedArray (NWidgetBase **array, uint length)
NWidgetCore * | GetWidgetFromPos (int x, int y)
| Retrieve a widget by its position.
virtual Scrollbar * | FindScrollbar (Window *w, bool allow_next=true) const =0
| Find the scrollbar of the widget through the Window::nested_array.
## Data Fields
NWidgetDisplay | disp_flags
| Flags that affect display and interaction with the widget.
Colours | colour
| Colour of this widget.
int | index
| Index of the nested widget in the widget array of the window (`-1` means 'not used').
uint16 | widget_data
| Data of the widget.
StringID | tool_tip
| Tooltip of the widget.

## Detailed Description

Base class for a 'real' widget.

Definition at line 242 of file widget_type.h.

## Constructor & Destructor Documentation

NWidgetCore::NWidgetCore | ( | WidgetType | tp,
|  | Colours | colour,
|  | uint | fill_x,
|  | uint | fill_y,
|  | uint16 | widget_data,
|  | StringID | tool_tip |
| ) |  |  |

Initialization of a 'real' widget.

Parameters:

  | tp | Type of the widget.
  | colour | Colour of the widget.
  | fill_x | Default horizontal filling.
  | fill_y | Default vertical filling.
  | widget_data | Data component of the widget.

See also:
  Widget::data

Parameters:

  | tool_tip | Tool tip of the widget.

See also:
  Widget::tootips

Definition at line 822 of file widget.cpp.

References index.

## Member Function Documentation

void NWidgetCore::SetIndex | ( | int | index | ) |

Set index of the nested widget in the widget array.

Parameters:

  | index | Index to use.

Definition at line 834 of file widget.cpp.

Referenced by NWidgetBackground::NWidgetBackground(), and NWidgetLeaf::NWidgetLeaf().

void NWidgetCore::SetDataTip | ( | uint16 | widget_data,
|  | StringID | tool_tip |
| ) |  |  |

Set data and tool tip of the nested widget.

Parameters:

  | widget_data | Data to use.
  | tool_tip | Tool tip string to use.

Definition at line 845 of file widget.cpp.

Referenced by CargoWidgets(), MakeCompanyButtonRows(), MakeNWidgetCompanyLines(), MakePerformanceDetailPanels(), NWidgetLeaf::NWidgetLeaf(), and StationViewWindow::OnClick().

void NWidgetCore::SetLowered | ( | bool | lowered | ) | `[inline]`

Lower or raise the widget.

Parameters:

  | lowered | Widget must be lowered (drawn pressed down).

Definition at line 270 of file widget_type.h.

References CLRBITS, disp_flags, ND_LOWERED, and SETBITS.

Referenced by MakeCargoButtons().

bool NWidgetCore::IsLowered | ( |  | ) | const`[inline]`

Return whether the widget is lowered.

Definition at line 276 of file widget_type.h.

References disp_flags, HasBit(), and NDB_LOWERED.

Referenced by NWidgetLeaf::Draw(), and SelectCompanyManagerFaceWindow::DrawFaceStringLabel().

void NWidgetCore::SetDisabled | ( | bool | disabled | ) | `[inline]`

Disable (grey-out) or enable the widget.

Parameters:

  | disabled | Widget must be disabled.

Definition at line 285 of file widget_type.h.

References CLRBITS, disp_flags, ND_DISABLED, and SETBITS.

Referenced by AIDebugWindow::OnPaint().

bool NWidgetCore::IsDisabled | ( |  | ) | const`[inline]`

Return whether the widget is disabled.

Definition at line 291 of file widget_type.h.

References disp_flags, HasBit(), and NDB_DISABLED.

Referenced by DispatchLeftClickEvent(), NWidgetLeaf::Draw(), NWidgetBackground::Draw(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), and AIDebugWindow::OnPaint().

NWidgetCore * NWidgetCore::GetWidgetFromPos | ( | int | x,
|  | int | y |
| ) |  |  | `[virtual]`

Retrieve a widget by its position.

Parameters:

  | x | Horizontal position relative to the left edge of the window.
  | y | Vertical position relative to the top edge of the window.

Returns:
  Returns the deepest nested widget that covers the given position, or `NULL` if no widget can be found.

Implements NWidgetBase.

Reimplemented in NWidgetBackground.

Definition at line 856 of file widget.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, IsInsideBS(), NWidgetBase::pos_x, and NWidgetBase::pos_y.

Referenced by NWidgetPIPContainer::GetWidgetFromPos(), NWidgetStacked::GetWidgetFromPos(), NWidgetToolbarContainer::GetWidgetFromPos(), and NWidgetSmallmapDisplay::GetWidgetFromPos().

Scrollbar * NWidgetCore::FindScrollbar | ( | Window * | w,
|  | bool | allow_next = `true` |
| ) |  |  | const`[pure virtual]`

Find the scrollbar of the widget through the Window::nested_array.

Parameters:

  | w | Window containing the widgets and the scrollbar,
  | allow_next | Search may be extended to the next widget.

Todo:
  This implementation uses the constraint that a scrollbar must be the next item in the Window::nested_array, and the scrollbar data is stored in the Window structure (Window::vscroll, Window::vscroll2, and Window::hscroll). Alternative light-weight implementations may be considered, eg by sub-classing a canvas-like widget, and/or by having an explicit link between the scrollbar and the widget being scrolled.

Implemented in NWidgetBackground, NWidgetViewport, and NWidgetLeaf.

Referenced by DispatchMouseWheelEvent(), NWidgetLeaf::FindScrollbar(), and NWidgetBackground::FindScrollbar().

## Field Documentation

uint16 NWidgetCore::widget_data

Data of the widget.

See also:
  Widget::data

Definition at line 262 of file widget_type.h.

Referenced by NWidgetLeaf::Draw(), NWidgetBackground::Draw(), MakeNWidget(), VehicleDetailsWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), NWidgetLeaf::SetupSmallestSize(), and NWidgetBackground::SetupSmallestSize().

StringID NWidgetCore::tool_tip

Tooltip of the widget.

See also:
  Widget::tootips

Definition at line 263 of file widget_type.h.

Referenced by DispatchRightClickEvent(), MakeCargoButtons(), and MakeNWidget().

The documentation for this class was generated from the following files:

- src/widget_type.h
- src/widget.cpp