OpenTTD
Data Structures | Functions
Hierarchical widget parts

To make nested widgets easier to enter, nested widget parts have been created. More...

Data Structures

struct  NWidgetPartDataTip
 Widget part for storing data and tooltip information. More...
struct  NWidgetPartWidget
 Widget part for storing basic widget information. More...
struct  NWidgetPartPaddings
 Widget part for storing padding. More...
struct  NWidgetPartPIP
 Widget part for storing pre/inter/post spaces. More...
struct  NWidgetPartTextLines
 Widget part for storing minimal text line data. More...
struct  NWidgetPart
 Partial widget specification to allow NWidgets to be written nested. More...

Functions

NWidgetContainerMakeNWidgets (const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
 Construct a nested widget tree from an array of parts.
NWidgetContainerMakeWindowNWidgetTree (const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
 Make a nested widget tree for a window from a parts array.
static NWidgetPart SetResize (int16 dx, int16 dy)
 Widget part function for setting the resize step.
static NWidgetPart SetMinimalSize (int16 x, int16 y)
 Widget part function for setting the minimal size.
static NWidgetPart SetMinimalTextLines (uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
 Widget part function for setting the minimal text lines.
static NWidgetPart SetFill (uint fill_x, uint fill_y)
 Widget part function for setting filling.
static NWidgetPart EndContainer ()
 Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
static NWidgetPart SetDataTip (uint32 data, StringID tip)
 Widget part function for setting the data and tooltip.
static NWidgetPart SetMatrixDataTip (uint8 cols, uint8 rows, StringID tip)
 Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
static NWidgetPart SetPadding (uint8 top, uint8 right, uint8 bottom, uint8 left)
 Widget part function for setting additional space around a widget.
static NWidgetPart SetPadding (uint8 padding)
 Widget part function for setting a padding.
static NWidgetPart SetPIP (uint8 pre, uint8 inter, uint8 post)
 Widget part function for setting a pre/inter/post spaces.
static NWidgetPart SetScrollbar (int index)
 Attach a scrollbar to a widget.
static NWidgetPart NWidget (WidgetType tp, Colours col, int16 idx=-1)
 Widget part function for starting a new 'real' widget.
static NWidgetPart NWidget (WidgetType tp, NWidContainerFlags cont_flags=NC_NONE)
 Widget part function for starting a new horizontal container, vertical container, or spacer widget.
static NWidgetPart NWidgetFunction (NWidgetFunctionType *func_ptr)
 Obtain a nested widget (sub)tree from an external source.

Detailed Description

To make nested widgets easier to enter, nested widget parts have been created.

They allow the tree to be defined in a flat array of parts.

See Also
Hierarchical widgets

Function Documentation

NWidgetContainer* MakeNWidgets ( const NWidgetPart parts,
int  count,
int *  biggest_index,
NWidgetContainer container 
)

Construct a nested widget tree from an array of parts.

Parameters
partsArray with parts of the widgets.
countLength of the parts array.
biggest_indexPointer to biggest nested widget index collected in the tree.
containerContainer to add the nested widgets to. In case it is NULL a vertical container is used.
Returns
Root of the nested widget tree, a vertical container containing the entire GUI.
Precondition
biggest_index != NULL
Postcondition
*biggest_index contains the largest widget index of the tree and -1 if no index is used.

Definition at line 2792 of file widget.cpp.

References MakeWidgetTree().

Referenced by MakeWindowNWidgetTree(), and NewGRFDisplay().

NWidgetContainer* MakeWindowNWidgetTree ( const NWidgetPart parts,
int  count,
int *  biggest_index,
NWidgetStacked **  shade_select 
)

Make a nested widget tree for a window from a parts array.

Besides loading, it inserts a shading selection widget between the title bar and the window body if the first widget in the parts array looks like a title bar (it is a horizontal container with a caption widget) and has a shade box widget.

Parameters
partsArray with parts of the widgets.
countLength of the parts array.
biggest_indexPointer to biggest nested widget index collected in the tree.
[out]shade_selectPointer to the inserted shade selection widget (NULL if not unserted).
Returns
Root of the nested widget tree, a vertical container containing the entire GUI.
Precondition
biggest_index != NULL
Postcondition
*biggest_index contains the largest widget index of the tree and -1 if no index is used.

Definition at line 2814 of file widget.cpp.

References NWidgetContainer::Add(), NWidgetContainer::GetWidgetOfType(), MakeNWidgets(), MakeWidgetTree(), max(), WWT_CAPTION, and WWT_SHADEBOX.

Referenced by Window::CreateNestedTree().

static NWidgetPart NWidget ( WidgetType  tp,
Colours  col,
int16  idx = -1 
)
inlinestatic

Widget part function for starting a new 'real' widget.

Parameters
tpType of the new nested widget.
colColour of the new widget.
idxIndex of the widget in the widget array.
Note
with WWT_PANEL, WWT_FRAME, WWT_INSET, a new container is started. Child widgets must have a index bigger than the parent index.

Definition at line 1114 of file widget_type.h.

References NWidgetPartWidget::colour, NWidgetPartWidget::index, NWidgetPart::type, and NWidgetPart::widget.

static NWidgetPart NWidget ( WidgetType  tp,
NWidContainerFlags  cont_flags = NC_NONE 
)
inlinestatic

Widget part function for starting a new horizontal container, vertical container, or spacer widget.

Parameters
tpType of the new nested widget, #NWID_HORIZONTAL(_LTR), NWID_VERTICAL, NWID_SPACER, NWID_SELECTION, and NWID_MATRIX.
cont_flagsFlags for the containers (#NWID_HORIZONTAL(_LTR) and NWID_VERTICAL).

Definition at line 1131 of file widget_type.h.

References NWidgetPart::cont_flags, and NWidgetPart::type.

static NWidgetPart NWidgetFunction ( NWidgetFunctionType func_ptr)
inlinestatic

Obtain a nested widget (sub)tree from an external source.

Parameters
func_ptrPointer to function that returns the tree.

Definition at line 1146 of file widget_type.h.

References NWidgetPart::func_ptr, NWidgetPart::type, and WPT_FUNCTION.

static NWidgetPart SetDataTip ( uint32  data,
StringID  tip 
)
inlinestatic

Widget part function for setting the data and tooltip.

Parameters
dataData of the widget.
tipTooltip of the widget.

Definition at line 1014 of file widget_type.h.

References NWidgetPartDataTip::data, NWidgetPart::data_tip, NWidgetPartDataTip::tooltip, NWidgetPart::type, and WPT_DATATIP.

Referenced by GameOptionsWindow::OnInvalidateData(), SetMatrixDataTip(), SmallMapWindow::SetupWidgetData(), DepotWindow::SetupWidgetData(), and WaypointWindow::WaypointWindow().

static NWidgetPart SetFill ( uint  fill_x,
uint  fill_y 
)
inlinestatic

Widget part function for setting filling.

Parameters
fill_xHorizontal filling step from minimal size.
fill_yVertical filling step from minimal size.

Definition at line 983 of file widget_type.h.

References NWidgetPart::type, WPT_FILL, and NWidgetPart::xy.

static NWidgetPart SetMatrixDataTip ( uint8  cols,
uint8  rows,
StringID  tip 
)
inlinestatic

Widget part function for setting the data and tooltip of WWT_MATRIX widgets.

Parameters
colsNumber of columns. 0 means to use draw columns with width according to the resize step size.
rowsNumber of rows. 0 means to use draw rows with height according to the resize step size.
tipTooltip of the widget.

Definition at line 1032 of file widget_type.h.

References MAT_COL_START, MAT_ROW_START, and SetDataTip().

static NWidgetPart SetMinimalSize ( int16  x,
int16  y 
)
inlinestatic

Widget part function for setting the minimal size.

Parameters
xHorizontal minimal size.
yVertical minimal size.

Definition at line 947 of file widget_type.h.

References NWidgetPart::type, WPT_MINSIZE, and NWidgetPart::xy.

static NWidgetPart SetMinimalTextLines ( uint8  lines,
uint8  spacing,
FontSize  size = FS_NORMAL 
)
inlinestatic

Widget part function for setting the minimal text lines.

Parameters
linesNumber of text lines.
spacingExtra spacing required.
sizeFont size of text.

Definition at line 965 of file widget_type.h.

References NWidgetPartTextLines::lines, NWidgetPartTextLines::size, NWidgetPartTextLines::spacing, NWidgetPart::text_lines, NWidgetPart::type, and WPT_MINTEXTLINES.

static NWidgetPart SetPadding ( uint8  top,
uint8  right,
uint8  bottom,
uint8  left 
)
inlinestatic

Widget part function for setting additional space around a widget.

Parameters start above the widget, and are specified in clock-wise direction.

Parameters
topThe padding above the widget.
rightThe padding right of the widget.
bottomThe padding below the widget.
leftThe padding left of the widget.

Definition at line 1046 of file widget_type.h.

References NWidgetPartPaddings::left, NWidgetPart::padding, NWidgetPart::type, and WPT_PADDING.

Referenced by SetPadding().

static NWidgetPart SetPadding ( uint8  padding)
inlinestatic

Widget part function for setting a padding.

Parameters
paddingThe padding to use for all directions.

Definition at line 1064 of file widget_type.h.

References SetPadding().

static NWidgetPart SetPIP ( uint8  pre,
uint8  inter,
uint8  post 
)
inlinestatic

Widget part function for setting a pre/inter/post spaces.

Parameters
preThe amount of space before the first widget.
interThe amount of space between widgets.
postThe amount of space after the last widget.

Definition at line 1076 of file widget_type.h.

References NWidgetPart::pip, NWidgetPartPIP::post, NWidgetPart::type, and WPT_PIPSPACE.

static NWidgetPart SetResize ( int16  dx,
int16  dy 
)
inlinestatic

Widget part function for setting the resize step.

Parameters
dxHorizontal resize step. 0 means no horizontal resizing.
dyVertical resize step. 0 means no vertical resizing.

Definition at line 930 of file widget_type.h.

References NWidgetPart::type, WPT_RESIZE, and NWidgetPart::xy.

static NWidgetPart SetScrollbar ( int  index)
inlinestatic

Attach a scrollbar to a widget.

The scrollbar is controlled when using the mousewheel on the widget. Multiple widgets can refer to the same scrollbar to make the mousewheel work in all of them.

Parameters
indexWidget index of the scrollbar.

Definition at line 1095 of file widget_type.h.

References NWidgetPartWidget::index, NWidgetPart::type, NWidgetPart::widget, and WPT_SCROLLBAR.