OpenTTD Source: src/widget_type.h File Reference

OpenTTD Source 15.3

Data Structures | Typedefs | Enumerations | Functions
widget_type.h File Reference

Definitions about widgets. More...

`#include "core/math_func.hpp"`
`#include "strings_type.h"`
`#include "gfx_type.h"`
`#include "window_type.h"`

Go to the source code of this file.

## Data Structures
class | NWidgetBase
| Baseclass for nested widgets. More...
class | NWidgetResizeBase
| Base class for a resizable nested widget. More...
struct | WidgetData
| Container with the data associated to a single widget. More...
class | NWidgetCore
| Base class for a 'real' widget. More...
class | NWidgetContainer
| Baseclass for container widgets. More...
class | NWidgetStacked
| Stacked widgets, widgets all occupying the same space in the window. More...
class | NWidgetPIPContainer
| Container with pre/inter/post child space. More...
class | NWidgetHorizontal
| Horizontal container. More...
class | NWidgetHorizontalLTR
| Horizontal container that doesn't change the direction of the widgets for RTL languages. More...
class | NWidgetVertical
| Vertical container. More...
class | NWidgetMatrix
| Matrix container with implicitly equal sized (virtual) sub-widgets. More...
class | NWidgetSpacer
| Spacer widget. More...
class | NWidgetBackground
| Nested widget with a child. More...
class | NWidgetViewport
| Nested widget to display a viewport in a window. More...
class | Scrollbar
| Scrollbar data structure. More...
class | NWidgetScrollbar
| Nested widget to display and control a scrollbar in a window. More...
class | NWidgetLeaf
| Leaf widget. More...
struct | NWidgetPartDataTip
| Widget part for storing data and tooltip information. More...
struct | NWidgetPartWidget
| Widget part for storing basic widget information. More...
struct | NWidgetPartContainer
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 | NWidgetPartTextStyle
| Widget part for storing text colour. More...
struct | NWidgetPartAlignment
| Widget part for setting text/image alignment within a widget. More...
struct | NWidgetPartAspect
struct | NWidgetPart
| Partial widget specification to allow NWidgets to be written nested. More...
union | NWidgetPart::NWidgetPartUnion

## Typedefs
using | AspectFlags = EnumBitSet< AspectFlag, uint8_t >
using | WidgetLookup = std::map< WidgetID, class NWidgetBase * >
| Lookup between widget IDs and NWidget objects.
using | NWidgetDisplayFlags = EnumBitSet< NWidgetDisplayFlag, uint16_t >
using | NWidContainerFlags = EnumBitSet< NWidContainerFlag, uint8_t >
using | NWidgetFunctionType = std::unique_ptr< NWidgetBase >()
| Pointer to function returning a nested widget.

## Enumerations
enum | ArrowWidgetValues : uint8_t { AWV_DECREASE , AWV_INCREASE , AWV_LEFT , AWV_RIGHT }
| Values for an arrow widget. More...
enum | ResizeWidgetValues : uint8_t { RWV_SHOW_BEVEL , RWV_HIDE_BEVEL }
| WidgetData values for a resize box widget. More...
enum | WidgetType : uint8_t { WWT_EMPTY , WWT_PANEL , WWT_INSET , WWT_IMGBTN , WWT_IMGBTN_2 , WWT_ARROWBTN , WWT_TEXTBTN , WWT_TEXTBTN_2 , WWT_BOOLBTN , WWT_IMGTEXTBTN , WWT_LABEL , WWT_TEXT , WWT_MATRIX , WWT_FRAME , WWT_CAPTION , WWT_DEBUGBOX , WWT_SHADEBOX , WWT_DEFSIZEBOX , WWT_STICKYBOX , WWT_RESIZEBOX , WWT_CLOSEBOX , WWT_DROPDOWN , WWT_EDITBOX , WWT_LAST , NWID_HORIZONTAL , NWID_HORIZONTAL_LTR , NWID_VERTICAL , NWID_MATRIX , NWID_SPACER , NWID_SELECTION , NWID_LAYER , NWID_VIEWPORT , NWID_BUTTON_DROPDOWN , NWID_HSCROLLBAR , NWID_VSCROLLBAR , NWID_CUSTOM , WPT_ATTRIBUTE_BEGIN , WPT_RESIZE , WPT_MINSIZE , WPT_MINTEXTLINES , WPT_FILL , WPT_DATATIP , WPT_PADDING , WPT_PIPSPACE , WPT_PIPRATIO , WPT_TEXTSTYLE , WPT_ALIGNMENT , WPT_SCROLLBAR , WPT_ASPECT , WPT_TOOLBARSIZE , WPT_ATTRIBUTE_END , WPT_FUNCTION , WPT_ENDCONTAINER , WWT_MASK = 0x7F , WWB_PUSHBUTTON = 1 << 7 , WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON , WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON , WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON , WWT_PUSHARROWBTN = WWT_ARROWBTN | WWB_PUSHBUTTON , WWT_PUSHIMGTEXTBTN = WWT_IMGTEXTBTN | WWB_PUSHBUTTON , NWID_PUSHBUTTON_DROPDOWN = NWID_BUTTON_DROPDOWN | WWB_PUSHBUTTON }
| Window widget types, nested widget types, and nested widget part types. More...
enum | SizingType : uint8_t { ST_SMALLEST , ST_RESIZE }
| Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition() More...
enum class | AspectFlag : uint8_t { ResizeX , ResizeY }
enum | NWidgetDisplayFlag : uint8_t { Lowered , Disabled , NoTransparency , ShadeGrey , ShadeDimmed , DropdownActive , ScrollbarUp , ScrollbarDown , Highlight , DropdownClosed }
| Nested widget flags that affect display and interaction with 'real' widgets. More...
enum | StackedZeroSizePlanes : int { SZSP_VERTICAL = INT_MAX / 2 , SZSP_HORIZONTAL , SZSP_NONE , SZSP_BEGIN = SZSP_VERTICAL }
| Display planes with zero size for NWidgetStacked. More...
enum | NWidContainerFlag : uint8_t { EqualSize , BigFirst }
| Nested widget container flags,. More...

## Functions
uint | ComputeMaxSize (uint base, uint max_space, uint step)
| Return the biggest possible size of a nested widget.
constexpr NWidgetPart | SetResize (int16_t dx, int16_t dy)
| Widget part function for setting the resize step.
constexpr NWidgetPart | SetMinimalSize (int16_t x, int16_t y)
| Widget part function for setting the minimal size.
constexpr NWidgetPart | SetToolbarSpacerMinimalSize ()
| Widget part function to setting the minimal size for a toolbar spacer.
constexpr NWidgetPart | SetToolbarMinimalSize (int width)
| Widget part function to setting the minimal size for a toolbar button.
constexpr NWidgetPart | SetMinimalTextLines (uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
| Widget part function for setting the minimal text lines.
constexpr NWidgetPart | SetTextStyle (TextColour colour, FontSize size=FS_NORMAL)
| Widget part function for setting the text style.
constexpr NWidgetPart | SetAlignment (StringAlignment align)
| Widget part function for setting the alignment of text/images.
constexpr NWidgetPart | SetFill (uint16_t fill_x, uint16_t fill_y)
| Widget part function for setting filling.
constexpr NWidgetPart | EndContainer ()
| Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
constexpr NWidgetPart | SetStringTip (StringID string, StringID tip={})
| Widget part function for setting the string and tooltip.
constexpr NWidgetPart | SetSpriteTip (SpriteID sprite, StringID tip={})
| Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart | SetSpriteStringTip (SpriteID sprite, StringID string, StringID tip={})
| Widget part function for setting the sprite, string and tooltip.
constexpr NWidgetPart | SetArrowWidgetTypeTip (ArrowWidgetValues widget_type, StringID tip={})
| Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart | SetResizeWidgetTypeTip (ResizeWidgetValues widget_type, StringID tip)
| Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart | SetAlternateColourTip (Colours colour, StringID tip)
| Widget part function for setting the alternate colour and tooltip.
constexpr NWidgetPart | SetMatrixDataTip (uint32_t cols, uint32_t rows, StringID tip={})
| Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart | SetToolTip (StringID tip)
| Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart | SetPadding (uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
| Widget part function for setting additional space around a widget.
constexpr NWidgetPart | SetPadding (uint8_t horizontal, uint8_t vertical)
| Widget part function for setting additional space around a widget.
constexpr NWidgetPart | SetPadding (const RectPadding &padding)
| Widget part function for setting additional space around a widget.
constexpr NWidgetPart | SetPadding (uint8_t padding)
| Widget part function for setting a padding.
constexpr NWidgetPart | SetPIP (uint8_t pre, uint8_t inter, uint8_t post)
| Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart | SetPIPRatio (uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
| Widget part function for setting a pre/inter/post ratio.
constexpr NWidgetPart | SetScrollbar (WidgetID index)
| Attach a scrollbar to a widget.
constexpr NWidgetPart | SetAspect (float ratio, AspectFlags flags=AspectFlag::ResizeX)
| Widget part function for setting the aspect ratio.
constexpr NWidgetPart | NWidget (WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
| Widget part function for starting a new 'real' widget.
constexpr NWidgetPart | NWidget (WidgetType tp, NWidContainerFlags cont_flags={}, WidgetID idx=INVALID_WIDGET)
| Widget part function for starting a new horizontal container, vertical container, or spacer widget.
constexpr NWidgetPart | NWidgetFunction (NWidgetFunctionType *func_ptr)
| Obtain a nested widget (sub)tree from an external source.
bool | IsContainerWidgetType (WidgetType tp)
| Test if WidgetType is a container widget.
std::unique_ptr< NWidgetBase > | MakeNWidgets (std::span< const NWidgetPart > nwid_parts, std::unique_ptr< NWidgetBase > &&container)
| Construct a nested widget tree from an array of parts.
std::unique_ptr< NWidgetBase > | MakeWindowNWidgetTree (std::span< const NWidgetPart > nwid_parts, NWidgetStacked **shade_select)
| Make a nested widget tree for a window from a parts array.
std::unique_ptr< NWidgetBase > | MakeCompanyButtonRows (WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable=true)
| Make a number of rows with button-like graphics, for enabling/disabling each company.
void | SetupWidgetDimensions ()
| Set up pre-scaled versions of Widget Dimensions.

## Detailed Description

Definitions about widgets.

Definition in file widget_type.h.

## Typedef Documentation

## ◆ AspectFlags

using AspectFlags = EnumBitSet<AspectFlag, uint8_t>

Definition at line 122 of file widget_type.h.

## ◆ NWidContainerFlags

using NWidContainerFlags = EnumBitSet<NWidContainerFlag, uint8_t>

Definition at line 547 of file widget_type.h.

## ◆ NWidgetDisplayFlags

using NWidgetDisplayFlags = EnumBitSet<NWidgetDisplayFlag, uint16_t>

Definition at line 355 of file widget_type.h.

## ◆ NWidgetFunctionType

using NWidgetFunctionType = std::unique_ptr<NWidgetBase>()

Pointer to function returning a nested widget.

Returns
  Nested widget (tree).

Definition at line 1091 of file widget_type.h.

## ◆ WidgetLookup

using WidgetLookup = std::map<WidgetID, class NWidgetBase *>

Lookup between widget IDs and NWidget objects.

Definition at line 129 of file widget_type.h.

## Enumeration Type Documentation

## ◆ ArrowWidgetValues

enum ArrowWidgetValues : uint8_t

Values for an arrow widget.

Enumerator
AWV_DECREASE | Arrow to the left or in case of RTL to the right.
AWV_INCREASE | Arrow to the right or in case of RTL to the left.
AWV_LEFT | Force the arrow to the left.
AWV_RIGHT | Force the arrow to the right.

Definition at line 19 of file widget_type.h.

## ◆ AspectFlag

enum class AspectFlag : uint8_t
| strong

Definition at line 118 of file widget_type.h.

## ◆ NWidContainerFlag

enum NWidContainerFlag : uint8_t

Nested widget container flags,.

Enumerator
EqualSize | Containers should keep all their (resizing) children equally large.
BigFirst | Allocate space to biggest resize first.

Definition at line 543 of file widget_type.h.

## ◆ NWidgetDisplayFlag

enum NWidgetDisplayFlag : uint8_t

Nested widget flags that affect display and interaction with 'real' widgets.

Enumerator
Lowered | Widget is lowered (pressed down) bit.
Disabled | Widget is disabled (greyed out) bit.
NoTransparency | Viewport is never transparent.
ShadeGrey | Shade viewport to grey-scale.
ShadeDimmed | Display dimmed colours in the viewport.
DropdownActive | Dropdown menu of the button dropdown widget is active. See also NWID_BUTTON_DROPDOWN
ScrollbarUp | Up-button is lowered bit.
ScrollbarDown | Down-button is lowered bit.
Highlight | Highlight of widget is on.
DropdownClosed | Dropdown menu of the dropdown widget has closed.

Definition at line 334 of file widget_type.h.

## ◆ ResizeWidgetValues

enum ResizeWidgetValues : uint8_t

WidgetData values for a resize box widget.

Enumerator
RWV_SHOW_BEVEL | Bevel of resize box is shown.
RWV_HIDE_BEVEL | Bevel of resize box is hidden.

Definition at line 27 of file widget_type.h.

## ◆ SizingType

enum SizingType : uint8_t

Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()

Enumerator
ST_SMALLEST | Initialize nested widget tree to smallest size. Also updates current_x and current_y.
ST_RESIZE | Resize the nested widget tree.

Definition at line 113 of file widget_type.h.

## ◆ StackedZeroSizePlanes

enum StackedZeroSizePlanes : int

Display planes with zero size for NWidgetStacked.

Enumerator
SZSP_VERTICAL | Display plane with zero size horizontally, and filling and resizing vertically.
SZSP_HORIZONTAL | Display plane with zero size vertically, and filling and resizing horizontally.
SZSP_NONE | Display plane with zero size in both directions (none filling and resizing).
SZSP_BEGIN | First zero-size plane.

Definition at line 506 of file widget_type.h.

## ◆ WidgetType

enum WidgetType : uint8_t

Window widget types, nested widget types, and nested widget part types.

Enumerator
WWT_EMPTY | Empty widget, place holder to reserve space in widget tree.
WWT_PANEL | Simple depressed panel.
WWT_INSET | Pressed (inset) panel, most commonly used as combo box text area.
WWT_IMGBTN | (Toggle) Button with image
WWT_IMGBTN_2 | (Toggle) Button with diff image when clicked
WWT_ARROWBTN | (Toggle) Button with an arrow
WWT_TEXTBTN | (Toggle) Button with text
WWT_TEXTBTN_2 | (Toggle) Button with diff text when clicked
WWT_BOOLBTN | Standard boolean toggle button.
WWT_IMGTEXTBTN | (Toggle) Button with image and text
WWT_LABEL | Centered label.
WWT_TEXT | Pure simple text.
WWT_MATRIX | Grid of rows and columns. See also MatrixWidgetValues
WWT_FRAME | Frame.
WWT_CAPTION | Window caption (window title between closebox and stickybox)
WWT_DEBUGBOX | NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
WWT_SHADEBOX | Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
WWT_DEFSIZEBOX | Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
WWT_STICKYBOX | Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
WWT_RESIZEBOX | Resize box (normally at bottom-right of a window)
WWT_CLOSEBOX | Close box (at top-left of a window)
WWT_DROPDOWN | Drop down list.
WWT_EDITBOX | a textbox for typing
WWT_LAST | Last Item. use WIDGETS_END to fill up padding!!
NWID_HORIZONTAL | Horizontal container.
NWID_HORIZONTAL_LTR | Horizontal container that doesn't change the order of the widgets for RTL languages.
NWID_VERTICAL | Vertical container.
NWID_MATRIX | Matrix container.
NWID_SPACER | Invisible widget that takes some space.
NWID_SELECTION | Stacked widgets, only one visible at a time (eg in a panel with tabs).
NWID_LAYER | Layered widgets, all visible together.
NWID_VIEWPORT | Nested widget containing a viewport.
NWID_BUTTON_DROPDOWN | Button with a drop-down.
NWID_HSCROLLBAR | Horizontal scrollbar.
NWID_VSCROLLBAR | Vertical scrollbar.
NWID_CUSTOM | General Custom widget.
WPT_ATTRIBUTE_BEGIN | Begin marker for attribute NWidgetPart types.
WPT_RESIZE | Widget part for specifying resizing.
WPT_MINSIZE | Widget part for specifying minimal size.
WPT_MINTEXTLINES | Widget part for specifying minimal number of lines of text.
WPT_FILL | Widget part for specifying fill.
WPT_DATATIP | Widget part for specifying data and tooltip.
WPT_PADDING | Widget part for specifying a padding.
WPT_PIPSPACE | Widget part for specifying pre/inter/post space for containers.
WPT_PIPRATIO | Widget part for specifying pre/inter/post ratio for containers.
WPT_TEXTSTYLE | Widget part for specifying text colour.
WPT_ALIGNMENT | Widget part for specifying text/image alignment.
WPT_SCROLLBAR | Widget part for attaching a scrollbar.
WPT_ASPECT | Widget part for specifying aspect ratio.
WPT_TOOLBARSIZE | Widget part for specifying minimal size in terms of toolbar images.
WPT_ATTRIBUTE_END | End marker for attribute NWidgetPart types.
WPT_FUNCTION | Widget part for calling a user function.
WPT_ENDCONTAINER | Widget part to denote end of a container.
WWT_PUSHBTN | Normal push-button (no toggle button) with custom drawing.
WWT_PUSHTXTBTN | Normal push-button (no toggle button) with text caption.
WWT_PUSHIMGBTN | Normal push-button (no toggle button) with image caption.
WWT_PUSHARROWBTN | Normal push-button (no toggle button) with arrow caption.
WWT_PUSHIMGTEXTBTN | Normal push-button (no toggle button) with image and text caption.

Definition at line 35 of file widget_type.h.

## Function Documentation

## ◆ ComputeMaxSize()

uint ComputeMaxSize | ( | uint | base,
|  | uint | max_space,
|  | uint | step
| ) |  |
| inline

Return the biggest possible size of a nested widget.

Parameters

  base | Base size of the widget.
  max_space | Available space for the widget.
  step | Stepsize of the widget.

Returns
  Biggest possible size of the widget, assuming that base may only be incremented by step size steps.

Definition at line 959 of file widget_type.h.

Referenced by NWidgetNewGRFDisplay::AssignSizePosition(), NWidgetLayer::AssignSizePosition(), NWidgetStacked::AssignSizePosition(), NWidgetHorizontal::AssignSizePosition(), NWidgetVertical::AssignSizePosition(), and NWidgetNewGRFDisplay::SetupSmallestSize().

## ◆ IsContainerWidgetType()

bool IsContainerWidgetType | ( | WidgetType | tp | ) |

Test if WidgetType is a container widget.

Parameters

  tp | WidgetType to test.

Returns
  True iff WidgetType is a container widget.

Definition at line 3353 of file widget.cpp.

References NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_LAYER, NWID_MATRIX, NWID_SELECTION, NWID_VERTICAL, WWT_FRAME, WWT_INSET, and WWT_PANEL.

Referenced by IsNWidgetTreeClosed(), MakeNWidget(), and MakeWidgetTree().

## ◆ MakeCompanyButtonRows()

std::unique_ptr< NWidgetBase > MakeCompanyButtonRows | ( | WidgetID | widget_first,
|  | WidgetID | widget_last,
|  | Colours | button_colour,
|  | int | max_length,
|  | StringID | button_tooltip,
|  | bool | resizable
| ) |  |

Make a number of rows with button-like graphics, for enabling/disabling each company.

Parameters

  widget_first | The first widget index to use.
  widget_last | The last widget index to use.
  colour | The colour in which to draw the button.
  max_length | Maximal number of company buttons in one row.
  button_tooltip | The tooltip-string of every button.
  resizable | Whether the rows are resizable.

Returns
  Panel with rows of company buttons.

Definition at line 3471 of file widget.cpp.

References GetSpriteSize(), RectPadding::Horizontal(), WidgetDimensions::matrix, Normal, WidgetDimensions::unscaled, RectPadding::Vertical(), and WWT_PANEL.

Referenced by MakeCompanyButtonRowsGraphGUI(), MakeCompanyButtonRowsLinkGraphGUI(), and MakeCompanyButtonRowsScriptDebug().

## ◆ SetupWidgetDimensions()

void SetupWidgetDimensions | ( |  | ) |

Set up pre-scaled versions of Widget Dimensions.

Definition at line 96 of file widget.cpp.

References _settings_client, _toolbar_image_size, WidgetDimensions::bevel, WidgetDimensions::captiontext, WidgetDimensions::closebox, WidgetDimensions::debugbox, WidgetDimensions::defsizebox, WidgetDimensions::dropdownlist, WidgetDimensions::dropdowntext, WidgetDimensions::framerect, WidgetDimensions::frametext, WidgetDimensions::fullbevel, GetToolbarMaximalImageSize(), ClientSettings::gui, WidgetDimensions::hscrollbar, WidgetDimensions::hsep_indent, WidgetDimensions::hsep_normal, WidgetDimensions::hsep_wide, WidgetDimensions::imgbtn, WidgetDimensions::inset, WidgetDimensions::matrix, WidgetDimensions::modalpopup, WidgetDimensions::resizebox, GUISettings::scale_bevels, WidgetDimensions::scaled, ScaleGUITrad(), WidgetDimensions::shadebox, WidgetDimensions::stickybox, WidgetDimensions::unscaled, WidgetDimensions::vscrollbar, WidgetDimensions::vsep_normal, and WidgetDimensions::vsep_wide.

Referenced by AdjustGUIZoom(), InitWindowSystem(), GameOptionsWindow::OnClick(), and ReInitAllWindows().