# NWidgetLeaf Class Reference
[Hierarchical widgets]

Leaf widget. More...

`#include <widget_type.h>`

Inheritance diagram for NWidgetLeaf:

## Public Member Functions

| NWidgetLeaf (WidgetType tp, Colours colour, int index, uint16 data, StringID tip)
| Nested leaf widget.
void | SetupSmallestSize (Window *w, bool init_array)
| Compute smallest size needed by the widget.
void | Draw (const Window *w)
| Draw the widgets of the tree.
Scrollbar * | FindScrollbar (Window *w, bool allow_next=true) const
| Find the scrollbar of the widget through the Window::nested_array.
bool | ButtonHit (const Point &pt)
| For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.

## Static Public Member Functions

static void | InvalidateDimensionCache ()
| Reset the cached dimensions.

## Static Private Attributes

static Dimension | shadebox_dimension = {0, 0}
| Cached size of a shadebox widget.
static Dimension | stickybox_dimension = {0, 0}
| Cached size of a stickybox widget.
static Dimension | resizebox_dimension = {0, 0}
| Cached size of a resizebox widget.
static Dimension | closebox_dimension = {0, 0}
| Cached size of a closebox widget.

## Detailed Description

Leaf widget.

Definition at line 470 of file widget_type.h.

## Constructor & Destructor Documentation

NWidgetLeaf::NWidgetLeaf | ( | WidgetType | tp,
|  | Colours | colour,
|  | int | index,
|  | uint16 | data,
|  | StringID | tip |
| ) |  |  |

Nested leaf widget.

Parameters:

  | tp | Type of leaf widget.
  | colour | Colour of the leaf widget.
  | index | Index in the widget array used by the window system.
  | data | Data of the widget.
  | tip | Tooltip of the widget.

Definition at line 1711 of file widget.cpp.

References NWidgetResizeBase::min_x, NWidgetResizeBase::min_y, NWID_BUTTON_ARROW, NWID_BUTTON_DROPDOWN, NWidgetCore::SetDataTip(), NWidgetResizeBase::SetFill(), NWidgetCore::SetIndex(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), WD_CAPTION_HEIGHT, WD_CLOSEBOX_WIDTH, WD_DROPDOWN_HEIGHT, WD_HSCROLLBAR_HEIGHT, WD_RESIZEBOX_WIDTH, WD_SHADEBOX_TOP, WD_STICKYBOX_WIDTH, WD_VSCROLLBAR_WIDTH, WWT_CAPTION, WWT_CLOSEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_HSCROLLBAR, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_RESIZEBOX, WWT_SCROLL2BAR, WWT_SCROLLBAR, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

## Member Function Documentation

bool NWidgetLeaf::ButtonHit | ( | const Point & | pt | ) |

For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.

Parameters:

  | pt | Point in the widget.

Returns:
  The point refers to the button.

Note:
  The magic constants are also used at DrawButtonDropdown.

Definition at line 2108 of file widget.cpp.

References _dynlang, NWidgetBase::current_x, NWidgetBase::pos_x, TD_LTR, and DynamicLanguages::text_dir.

void NWidgetLeaf::Draw | ( | const Window * | w | ) | `[virtual]`

Draw the widgets of the tree.

The function calls Window::DrawWidget for each widget with a non-negative index, after the widget itself is painted.

Parameters:

  | w | Window that owns the tree.

Implements NWidgetBase.

Definition at line 1953 of file widget.cpp.

References _colour_gradient, _dynlang, AWV_DECREASE, AWV_INCREASE, AWV_LEFT, AWV_RIGHT, NWidgetCore::colour, NWidgetBase::current_x, NWidgetBase::current_y, NWidgetCore::disp_flags, DrawButtonDropdown(), DrawCaption(), DrawCloseBox(), DrawDropdown(), DrawFrameRect(), DrawHorizontalScrollbar(), DrawImageButtons(), DrawLabel(), DrawMatrix(), DrawResizeBox(), DrawShadeBox(), DrawStickyBox(), DrawText(), DrawVerticalScrollbar(), Window::DrawWidget(), FILLRECT_CHECKER, Window::flags4, FR_DARKENED, FR_LOWERED, GfxFillRect(), Window::hscroll, NWidgetCore::index, NWidgetCore::IsDisabled(), NWidgetCore::IsLowered(), Window::IsShaded(), ND_DROPDOWN_ACTIVE, NWID_BUTTON_ARROW, NWID_BUTTON_DROPDOWN, Window::owner, NWidgetBase::pos_x, NWidgetBase::pos_y, Window::SetStringParameters(), TD_RTL, DynamicLanguages::text_dir, NWidgetBase::type, Window::vscroll, Window::vscroll2, WF_SCROLL_DOWN, WF_SCROLL_MIDDLE, WF_SCROLL_UP, WF_SIZING, WF_STICKY, NWidgetCore::widget_data, Window::width, WWT_CAPTION, WWT_CLOSEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_HSCROLLBAR, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_RESIZEBOX, WWT_SCROLL2BAR, WWT_SCROLLBAR, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

Scrollbar * NWidgetLeaf::FindScrollbar | ( | Window * | w,
|  | bool | allow_next = `true` |
| ) |  |  | const`[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.

Implements NWidgetCore.

Definition at line 2085 of file widget.cpp.

References NWidgetCore::FindScrollbar(), Window::GetWidget(), NWidgetCore::index, Window::nested_array_size, NWidgetBase::type, Window::vscroll, Window::vscroll2, WWT_SCROLL2BAR, and WWT_SCROLLBAR.

void NWidgetLeaf::InvalidateDimensionCache | ( |  | ) | `[static]`

Reset the cached dimensions.

Definition at line 1690 of file widget.cpp.

References closebox_dimension, resizebox_dimension, shadebox_dimension, and stickybox_dimension.

Referenced by InitWindowSystem(), and ReInitAllWindows().

void NWidgetLeaf::SetupSmallestSize | ( | Window * | w,
|  | bool | init_array |
| ) |  |  | `[virtual]`

Compute smallest size needed by the widget.

The smallest size of a widget is the smallest size that a widget needs to display itself properly. In addition, filling and resizing of the widget are computed. The function calls Window::UpdateWidgetSize for each leaf widget and background widget without child with a non-negative index.

Parameters:

  | w | Window owning the widget.
  | init_array | Initialize the `w->nested_array`.

Note:
  After the computation, the results can be queried by accessing the smallest_x and smallest_y data members of the widget.

Implements NWidgetBase.

Definition at line 1798 of file widget.cpp.

References NWidgetBase::fill_x, NWidgetBase::fill_y, GetSpriteSize(), GetStringBoundingBox(), NWidgetCore::index, max(), maxdim(), NWidgetResizeBase::min_x, NWidgetResizeBase::min_y, Window::nested_array, Window::nested_array_size, NWID_BUTTON_ARROW, NWID_BUTTON_DROPDOWN, NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetStringParameters(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, NWidgetBase::type, Window::UpdateWidgetSize(), WD_CAPTIONTEXT_BOTTOM, WD_CAPTIONTEXT_LEFT, WD_CAPTIONTEXT_RIGHT, WD_CAPTIONTEXT_TOP, WD_CLOSEBOX_BOTTOM, WD_CLOSEBOX_LEFT, WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP, WD_DROPDOWNTEXT_BOTTOM, WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP, WD_IMGBTN_BOTTOM, WD_IMGBTN_LEFT, WD_IMGBTN_RIGHT, WD_IMGBTN_TOP, WD_MATRIX_BOTTOM, WD_MATRIX_LEFT, WD_MATRIX_RIGHT, WD_MATRIX_TOP, WD_RESIZEBOX_BOTTOM, WD_RESIZEBOX_LEFT, WD_RESIZEBOX_RIGHT, WD_RESIZEBOX_TOP, WD_SHADEBOX_BOTTOM, WD_SHADEBOX_LEFT, WD_SHADEBOX_RIGHT, WD_SHADEBOX_TOP, WD_STICKYBOX_BOTTOM, WD_STICKYBOX_LEFT, WD_STICKYBOX_RIGHT, WD_STICKYBOX_TOP, NWidgetCore::widget_data, WWT_CAPTION, WWT_CLOSEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_HSCROLLBAR, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_RESIZEBOX, WWT_SCROLL2BAR, WWT_SCROLLBAR, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

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

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