OpenTTD Source 20250205-master-gfd85ab1e2c
widget_type.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef WIDGET_TYPE_H
11#define WIDGET_TYPE_H
12
13#include "core/alloc_type.hpp"
14#include "core/bitmath_func.hpp"
15#include "core/math_func.hpp"
16#include "strings_type.h"
17#include "gfx_type.h"
18#include "window_type.h"
19
27
33
109
111enum SizingType : uint8_t {
114};
115
116enum class AspectFlag : uint8_t {
117 ResizeX,
118 ResizeY,
119};
121
122/* Forward declarations. */
123class NWidgetCore;
124class Scrollbar;
125
127using WidgetLookup = std::map<WidgetID, class NWidgetBase *>;
128
136public:
138
139 void ApplyAspectRatio();
140 virtual void AdjustPaddingForZoom();
141 virtual void SetupSmallestSize(Window *w) = 0;
142 virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
143
144 virtual void FillWidgetLookup(WidgetLookup &widget_lookup) = 0;
145
146 virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
148
154 template <class NWID>
156 {
157 for (NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
158 if (NWID *nwid = dynamic_cast<NWID *>(nwid_parent); nwid != nullptr) return nwid;
159 }
160 return nullptr;
161 }
162
168 template <class NWID>
169 const NWID *GetParentWidget() const
170 {
171 for (const NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
172 if (const NWID *nwid = dynamic_cast<const NWID *>(nwid_parent); nwid != nullptr) return nwid;
173 }
174 return nullptr;
175 }
176
177 virtual bool IsHighlighted() const { return false; }
178 virtual TextColour GetHighlightColour() const { return TC_INVALID; }
179 virtual void SetHighlighted([[maybe_unused]] TextColour highlight_colour) {}
180
188 inline void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
189 {
190 this->uz_padding.top = top;
191 this->uz_padding.right = right;
192 this->uz_padding.bottom = bottom;
193 this->uz_padding.left = left;
194 this->AdjustPaddingForZoom();
195 }
196
201 inline void SetPadding(const RectPadding &padding)
202 {
203 this->uz_padding = padding;
204 this->AdjustPaddingForZoom();
205 }
206
207 inline uint GetHorizontalStepSize(SizingType sizing) const;
208 inline uint GetVerticalStepSize(SizingType sizing) const;
209
210 virtual void Draw(const Window *w) = 0;
211 virtual void SetDirty(const Window *w) const;
212
213 Rect GetCurrentRect() const
214 {
215 Rect r;
216 r.left = this->pos_x;
217 r.top = this->pos_y;
218 r.right = this->pos_x + this->current_x - 1;
219 r.bottom = this->pos_y + this->current_y - 1;
220 return r;
221 }
222
224 uint fill_x;
225 uint fill_y;
226 uint resize_x;
227 uint resize_y;
228 /* Size of the widget in the smallest window possible.
229 * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
230 */
233 /* Current widget size (that is, after resizing). */
236 float aspect_ratio = 0;
237 AspectFlags aspect_flags = AspectFlag::ResizeX;
238
239 int pos_x;
240 int pos_y;
241
244
246
247protected:
248 inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
249};
250
256{
257 return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
258}
259
265{
266 return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
267}
268
277inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
278{
279 this->pos_x = x;
280 this->pos_y = y;
281 if (sizing == ST_SMALLEST) {
282 this->smallest_x = given_width;
283 this->smallest_y = given_height;
284 }
285 this->current_x = given_width;
286 this->current_y = given_height;
287}
288
289
295public:
297
298 void AdjustPaddingForZoom() override;
299 void SetMinimalSize(uint min_x, uint min_y);
300 void SetMinimalSizeAbsolute(uint min_x, uint min_y);
301 void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size);
302 void SetFill(uint fill_x, uint fill_y);
303 void SetResize(uint resize_x, uint resize_y);
304 void SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX);
305 void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlag::ResizeX);
306
307 bool UpdateMultilineWidgetSize(const std::string &str, int max_lines);
308 bool UpdateSize(uint min_x, uint min_y);
309 bool UpdateVerticalSize(uint min_y);
310
311 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
312
313 uint min_x;
314 uint min_y;
315
316 bool absolute;
317 uint uz_min_x;
318 uint uz_min_y;
319
323};
324
356
357
359 StringID string{};
360 SpriteID sprite{};
361 ArrowWidgetValues arrow_widget_type{};
362 ResizeWidgetValues resize_widget_type{};
363 Dimension matrix{};
364};
365
371public:
373
374 void SetString(StringID string);
376 void SetSprite(SpriteID sprite);
378 void SetMatrixDimension(uint32_t columns, uint32_t rows);
381 StringID GetToolTip() const;
384
385 StringID GetString() const;
386 WidgetID GetIndex() const;
388
389 inline void SetLowered(bool lowered);
390 inline bool IsLowered() const;
391 inline void SetDisabled(bool disabled);
392 inline bool IsDisabled() const;
393
394 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
395 NWidgetCore *GetWidgetFromPos(int x, int y) override;
396 bool IsHighlighted() const override;
397 TextColour GetHighlightColour() const override;
399
401 Colours colour;
402protected:
411
412 /* This function constructs the widgets, so it should be able to write the variables. */
413 friend void ApplyNWidgetPartAttribute(const struct NWidgetPart &nwid, NWidgetBase *dest);
414};
415
420inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
421{
422 this->disp_flags = highlight_colour != TC_INVALID ? SETBITS(this->disp_flags, ND_HIGHLIGHT) : CLRBITS(this->disp_flags, ND_HIGHLIGHT);
423 this->highlight_colour = highlight_colour;
424}
425
427inline bool NWidgetCore::IsHighlighted() const
428{
429 return HasBit(this->disp_flags, NDB_HIGHLIGHT);
430}
431
434{
435 return this->highlight_colour;
436}
437
442inline void NWidgetCore::SetLowered(bool lowered)
443{
444 this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
445}
446
448inline bool NWidgetCore::IsLowered() const
449{
450 return HasBit(this->disp_flags, NDB_LOWERED);
451}
452
457inline void NWidgetCore::SetDisabled(bool disabled)
458{
459 this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
460}
461
463inline bool NWidgetCore::IsDisabled() const
464{
465 return HasBit(this->disp_flags, NDB_DISABLED);
466}
467
468
474public:
476
477 void AdjustPaddingForZoom() override;
478 void Add(std::unique_ptr<NWidgetBase> &&wid);
479 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
480
481 void Draw(const Window *w) override;
482 NWidgetCore *GetWidgetFromPos(int x, int y) override;
483
485 inline bool IsEmpty() { return this->children.empty(); }
486
488
489protected:
490 std::vector<std::unique_ptr<NWidgetBase>> children;
491};
492
501
513public:
515
516 void SetupSmallestSize(Window *w) override;
517 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
519
520 void Draw(const Window *w) override;
521 NWidgetCore *GetWidgetFromPos(int x, int y) override;
522
523 bool SetDisplayedPlane(int plane);
524
527private:
529};
530
541
542
544public:
546
547 void AdjustPaddingForZoom() override;
548 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
549 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post);
550
551protected:
553 uint8_t pip_pre;
554 uint8_t pip_inter;
555 uint8_t pip_post;
559
560 uint8_t uz_pip_pre;
561 uint8_t uz_pip_inter;
562 uint8_t uz_pip_post;
563
564 uint8_t gaps;
565};
566
572public:
574
575 void SetupSmallestSize(Window *w) override;
576 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
577};
578
584public:
586
587 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
588};
589
595public:
597
598 void SetupSmallestSize(Window *w) override;
599 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
600};
601
611public:
613
614 void SetClicked(int clicked);
615 void SetCount(int count);
617 int GetCurrentElement() const;
618
619 void SetupSmallestSize(Window *w) override;
620 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
621 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
622
623 NWidgetCore *GetWidgetFromPos(int x, int y) override;
624 void Draw(const Window *w) override;
625protected:
627 Colours colour;
629 int count;
632private:
637
638 void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
639};
640
641
647public:
648 NWidgetSpacer(int width, int height);
649
650 void SetupSmallestSize(Window *w) override;
651 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
652
653 void Draw(const Window *w) override;
654 void SetDirty(const Window *w) const override;
655 NWidgetCore *GetWidgetFromPos(int x, int y) override;
656};
657
663public:
664 NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child = nullptr);
665
666 void Add(std::unique_ptr<NWidgetBase> &&nwid);
667 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
668 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
669
670 void AdjustPaddingForZoom() override;
671 void SetupSmallestSize(Window *w) override;
672 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
673
674 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
675
676 void Draw(const Window *w) override;
677 NWidgetCore *GetWidgetFromPos(int x, int y) override;
679
680private:
681 std::unique_ptr<NWidgetPIPContainer> child;
682};
683
694public:
696
697 void SetupSmallestSize(Window *w) override;
698 void Draw(const Window *w) override;
699
700 void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
702};
703
708public:
709 using size_type = int32_t;
710 static constexpr size_type max_size_type = std::numeric_limits<size_type>::max();
711 static constexpr size_type npos = max_size_type;
712private:
713 const bool is_vertical;
714 size_type count;
715 size_type cap;
716 size_type pos;
717 size_type stepsize;
718
719public:
726
728 {
729 }
730
735 inline size_type GetCount() const
736 {
737 return this->count;
738 }
739
744 inline size_type GetCapacity() const
745 {
746 return this->cap;
747 }
748
753 inline size_type GetPosition() const
754 {
755 return this->pos;
756 }
757
763 inline bool IsVisible(size_type item) const
764 {
765 return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
766 }
767
772 inline bool IsVertical() const
773 {
774 return this->is_vertical;
775 }
776
781 void SetStepSize(size_t stepsize)
782 {
783 assert(stepsize > 0);
784
785 this->stepsize = ClampTo<size_type>(stepsize);
786 }
787
793 void SetCount(size_t num)
794 {
795 assert(num < Scrollbar::max_size_type);
796
797 this->count = ClampTo<size_type>(num);
798 /* Ensure position is within bounds */
799 this->SetPosition(this->pos);
800 }
801
807 void SetCapacity(size_t capacity)
808 {
809 assert(capacity < Scrollbar::max_size_type);
810
811 this->cap = ClampTo<size_type>(capacity);
812 /* Ensure position is within bounds */
813 this->SetPosition(this->pos);
814 }
815
816 void SetCapacityFromWidget(Window *w, WidgetID widget, int padding = 0);
817
823 bool SetPosition(size_type position)
824 {
825 size_type old_pos = this->pos;
826 this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
827 return this->pos != old_pos;
828 }
829
837 bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
838 {
839 if (difference == 0) return false;
840 switch (unit) {
841 case SS_SMALL: difference *= this->stepsize; break;
842 case SS_BIG: difference *= this->cap; break;
843 default: break;
844 }
845 return this->SetPosition(this->pos + difference);
846 }
847
854 void ScrollTowards(size_type position)
855 {
856 if (position < this->GetPosition()) {
857 /* scroll up to the item */
858 this->SetPosition(position);
859 } else if (position >= this->GetPosition() + this->GetCapacity()) {
860 /* scroll down so that the item is at the bottom */
861 this->SetPosition(position - this->GetCapacity() + 1);
862 }
863 }
864
865 size_type GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
866
872 template <typename Tcontainer>
873 auto GetVisibleRangeIterators(Tcontainer &container) const
874 {
875 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
876 auto first = std::next(std::begin(container), this->GetPosition());
877 auto last = std::next(first, std::min<size_t>(this->GetCapacity(), this->GetCount() - this->GetPosition()));
878 return std::make_pair(first, last);
879 }
880
891 template <typename Tcontainer>
892 auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
893 {
894 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
895 size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
896 if (row == Scrollbar::npos) return std::end(container);
897
898 return std::next(std::begin(container), row);
899 }
900
901 EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
902};
903
909class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
910public:
912
913 void SetupSmallestSize(Window *w) override;
914 void Draw(const Window *w) override;
915
916 static void InvalidateDimensionCache();
917 static Dimension GetVerticalDimension();
918 static Dimension GetHorizontalDimension();
919
920private:
923};
924
929class NWidgetLeaf : public NWidgetCore {
930public:
931 NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const WidgetData &data, StringID tip);
932
933 void SetupSmallestSize(Window *w) override;
934 void Draw(const Window *w) override;
935
936 bool ButtonHit(const Point &pt);
937
938 static void InvalidateDimensionCache();
939
943private:
948};
949
957inline uint ComputeMaxSize(uint base, uint max_space, uint step)
958{
959 if (base >= max_space || step == 0) return base;
960 if (step == 1) return max_space;
961 uint increment = max_space - base;
962 increment -= increment % step;
963 return base + increment;
964}
965
1021
1030
1037
1043 uint8_t pre, inter, post;
1044};
1045
1055
1064
1072
1074 float ratio;
1075 AspectFlags flags;
1076};
1077
1082typedef std::unique_ptr<NWidgetBase> NWidgetFunctionType();
1083
1102
1103 /* Constructors for each NWidgetPartUnion data type. */
1104 constexpr NWidgetPartUnion() : xy() {}
1105 constexpr NWidgetPartUnion(Point xy) : xy(xy) {}
1106 constexpr NWidgetPartUnion(NWidgetPartDataTip data_tip) : data_tip(data_tip) {}
1107 constexpr NWidgetPartUnion(NWidgetPartWidget widget) : widget(widget) {}
1108 constexpr NWidgetPartUnion(NWidgetPartPaddings padding) : padding(padding) {}
1109 constexpr NWidgetPartUnion(NWidgetPartPIP pip) : pip(pip) {}
1110 constexpr NWidgetPartUnion(NWidgetPartTextLines text_lines) : text_lines(text_lines) {}
1111 constexpr NWidgetPartUnion(NWidgetPartTextStyle text_style) : text_style(text_style) {}
1112 constexpr NWidgetPartUnion(NWidgetPartAlignment align) : align(align) {}
1113 constexpr NWidgetPartUnion(NWidgetFunctionType *func_ptr) : func_ptr(func_ptr) {}
1114 constexpr NWidgetPartUnion(NWidContainerFlags cont_flags) : cont_flags(cont_flags) {}
1115 constexpr NWidgetPartUnion(NWidgetPartAspect aspect) : aspect(aspect) {}
1116 } u;
1117
1118 /* Constructors for each NWidgetPart data type. */
1119 explicit constexpr NWidgetPart(WidgetType type) : type(type), u() {}
1120 constexpr NWidgetPart(WidgetType type, Point xy) : type(type), u(xy) {}
1121 constexpr NWidgetPart(WidgetType type, NWidgetPartDataTip data_tip) : type(type), u(data_tip) {}
1122 constexpr NWidgetPart(WidgetType type, NWidgetPartWidget widget) : type(type), u(widget) {}
1123 constexpr NWidgetPart(WidgetType type, NWidgetPartPaddings padding) : type(type), u(padding) {}
1124 constexpr NWidgetPart(WidgetType type, NWidgetPartPIP pip) : type(type), u(pip) {}
1125 constexpr NWidgetPart(WidgetType type, NWidgetPartTextLines text_lines) : type(type), u(text_lines) {}
1126 constexpr NWidgetPart(WidgetType type, NWidgetPartTextStyle text_style) : type(type), u(text_style) {}
1127 constexpr NWidgetPart(WidgetType type, NWidgetPartAlignment align) : type(type), u(align) {}
1128 constexpr NWidgetPart(WidgetType type, NWidgetFunctionType *func_ptr) : type(type), u(func_ptr) {}
1129 constexpr NWidgetPart(WidgetType type, NWidContainerFlags cont_flags) : type(type), u(cont_flags) {}
1130 constexpr NWidgetPart(WidgetType type, NWidgetPartAspect aspect) : type(type), u(aspect) {}
1131};
1132
1139constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
1140{
1141 return NWidgetPart{WPT_RESIZE, Point{dx, dy}};
1142}
1143
1150constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
1151{
1152 return NWidgetPart{WPT_MINSIZE, Point{x, y}};
1153}
1154
1162constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size = FS_NORMAL)
1163{
1164 return NWidgetPart{WPT_MINTEXTLINES, NWidgetPartTextLines{lines, spacing, size}};
1165}
1166
1174{
1175 return NWidgetPart{WPT_TEXTSTYLE, NWidgetPartTextStyle{colour, size}};
1176}
1177
1187
1194constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
1195{
1196 return NWidgetPart{WPT_FILL, Point{fill_x, fill_y}};
1197}
1198
1205{
1207}
1208
1215constexpr NWidgetPart SetStringTip(StringID string, StringID tip = {})
1216{
1217 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string}, tip}};
1218}
1219
1226constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip = {})
1227{
1228 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.sprite = sprite}, tip}};
1229}
1230
1238{
1239 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.arrow_widget_type = widget_type}, tip}};
1240}
1241
1249{
1250 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.resize_widget_type = widget_type}, tip}};
1251}
1252
1260constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip = {})
1261{
1262 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.matrix{ cols, rows }}, tip}};
1263}
1264
1271{
1272 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{}, tip}};
1273}
1274
1284constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
1285{
1286 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{left, top, right, bottom}};
1287}
1288
1295constexpr NWidgetPart SetPadding(uint8_t horizontal, uint8_t vertical)
1296{
1297 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{horizontal, vertical, horizontal, vertical}};
1298}
1299
1305constexpr NWidgetPart SetPadding(const RectPadding &padding)
1306{
1308}
1309
1315constexpr NWidgetPart SetPadding(uint8_t padding)
1316{
1317 return SetPadding(padding, padding, padding, padding);
1318}
1319
1327constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
1328{
1329 return NWidgetPart{WPT_PIPSPACE, NWidgetPartPIP{pre, inter, post}};
1330}
1331
1339constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
1340{
1341 return NWidgetPart{WPT_PIPRATIO, NWidgetPartPIP{ratio_pre, ratio_inter, ratio_post}};
1342}
1343
1352{
1353 return NWidgetPart{WPT_SCROLLBAR, NWidgetPartWidget{INVALID_COLOUR, index}};
1354}
1355
1362constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX)
1363{
1364 return NWidgetPart{WPT_ASPECT, NWidgetPartAspect{ratio, flags}};
1365}
1366
1376constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx = -1)
1377{
1378 return NWidgetPart{tp, NWidgetPartWidget{col, idx}};
1379}
1380
1388{
1389 return NWidgetPart{tp, NWidContainerFlags{cont_flags}};
1390}
1391
1398{
1399 return NWidgetPart{WPT_FUNCTION, func_ptr};
1400}
1401
1403std::unique_ptr<NWidgetBase> MakeNWidgets(std::span<const NWidgetPart> nwid_parts, std::unique_ptr<NWidgetBase> &&container);
1404std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(std::span<const NWidgetPart> nwid_parts, NWidgetStacked **shade_select);
1405
1406std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
1407
1409
1410#endif /* WIDGET_TYPE_H */
Helper types related to the allocation of memory.
Functions related to bit mathematics.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
#define CLRBITS(x, y)
Clears several bits in a variable.
#define SETBITS(x, y)
Sets several bits in a variable.
Nested widget with a child.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2371
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:2381
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:2315
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2250
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
Set additional pre/inter/post space for the background widget.
Definition widget.cpp:2216
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2333
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition widget.cpp:2197
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:2327
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post)
Set additional pre/inter/post space ratios for the background widget.
Definition widget.cpp:2235
Baseclass for nested widgets.
void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
Store size and position.
float aspect_ratio
Desired aspect ratio of widget.
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
virtual void SetupSmallestSize(Window *w)=0
Compute smallest size needed by the widget.
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:903
WidgetType type
Type of the widget / nested widget.
uint resize_x
Horizontal resize step (0 means not resizable).
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
NWID * GetParentWidget()
Get parent widget of type NWID.
NWidgetBase * parent
Parent widget of this widget, automatically filled in when added to container.
virtual void FillWidgetLookup(WidgetLookup &widget_lookup)=0
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
RectPadding uz_padding
Unscaled padding, for resize calculation.
uint smallest_x
Smallest horizontal size of the widget in a filled window.
AspectFlags aspect_flags
Which dimensions can be resized.
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
uint current_x
Current horizontal size (after resizing).
int pos_y
Vertical position of top-left corner of the widget in the window.
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
Retrieve a widget by its position.
int pos_x
Horizontal position of top-left corner of the widget in the window.
void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Set additional space (padding) around the widget.
void SetPadding(const RectPadding &padding)
Set additional space (padding) around the widget.
uint smallest_y
Smallest vertical size of the widget in a filled window.
virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)=0
Assign size and position to the widget.
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition widget.cpp:923
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
uint resize_y
Vertical resize step (0 means not resizable).
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
uint current_y
Current vertical size (after resizing).
uint GetVerticalStepSize(SizingType sizing) const
Get the vertical sizing step.
const NWID * GetParentWidget() const
Get parent widget of type NWID.
Baseclass for container widgets.
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition widget.cpp:1281
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1288
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1295
bool IsEmpty()
Return whether the container is empty.
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in contaier.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1304
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:1259
Base class for a 'real' widget.
WidgetData widget_data
Data of the widget.
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition widget.cpp:1199
bool IsHighlighted() const override
Return whether the widget is highlighted.
bool IsDisabled() const
Return whether the widget is disabled.
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
void SetSprite(SpriteID sprite)
Set sprite of the nested widget.
Definition widget.cpp:1149
WidgetID GetIndex() const
Get the WidgetID of this nested widget.
Definition widget.cpp:1235
void SetTextStyle(TextColour colour, FontSize size)
Set the text style of the nested widget.
Definition widget.cpp:1189
WidgetID GetScrollbarIndex() const
Get the WidgetID of this nested widget's scrollbar.
Definition widget.cpp:1244
TextColour highlight_colour
Colour of highlight.
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition widget.cpp:1217
void SetResizeWidgetType(ResizeWidgetValues type)
Set the resize widget type of the nested widget.
Definition widget.cpp:1179
void SetSpriteTip(SpriteID sprite, StringID tool_tip)
Set sprite and tool tip of the nested widget.
Definition widget.cpp:1159
const WidgetID index
Index of the nested widget (-1 means 'not used').
StringAlignment align
Alignment of text/image within widget.
FontSize text_size
Size of text within widget.
void SetHighlighted(TextColour highlight_colour) override
Highlight the widget or not.
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1226
WidgetID scrollbar_index
Index of an attached scrollbar.
StringID GetToolTip() const
Get the tool tip of the nested widget.
Definition widget.cpp:1208
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1254
void SetString(StringID string)
Set string of the nested widget.
Definition widget.cpp:1129
TextColour text_colour
Colour of text within widget.
Colours colour
Colour of this widget.
void SetMatrixDimension(uint32_t columns, uint32_t rows)
Set the matrix dimension.
Definition widget.cpp:1170
void SetLowered(bool lowered)
Lower or raise the widget.
TextColour GetHighlightColour() const override
Return the colour of the highlight.
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1249
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1139
StringID tool_tip
Tooltip of the widget.
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
bool IsLowered() const
Return whether the widget is lowered.
Horizontal container that doesn't change the direction of the widgets for RTL languages.
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:1729
Horizontal container.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1545
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:1614
Leaf widget.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2980
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition widget.cpp:2676
static Dimension resizebox_dimension
Cached size of a resizebox widget.
static Dimension shadebox_dimension
Cached size of a shadebox widget.
static Dimension closebox_dimension
Cached size of a closebox widget.
static Dimension stickybox_dimension
Cached size of a stickybox widget.
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2809
static Dimension dropdown_dimension
Cached size of a dropdown widget.
static Dimension debugbox_dimension
Cached size of a debugbox widget.
bool ButtonHit(const Point &pt)
For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.
Definition widget.cpp:3116
Matrix container with implicitly equal sized (virtual) sub-widgets.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2096
int count
Amount of valid elements.
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition widget.cpp:1959
int GetCurrentElement() const
Get current element.
Definition widget.cpp:2009
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Scrollbar * sb
The scrollbar we're associated with.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2014
int widget_w
The width of the child widget including inter spacing.
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition widget.cpp:2000
void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
Get the different offsets that are influenced by scrolling.
Definition widget.cpp:2151
int current_element
The element currently being processed.
int widgets_x
The number of visible widgets in horizontal direction.
int widget_h
The height of the child widget including inter spacing.
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:2036
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:2060
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2066
int clicked
The currently clicked element.
void SetCount(int count)
Set the number of elements in this matrix.
Definition widget.cpp:1976
int widgets_y
The number of visible widgets in vertical direction.
Colours colour
Colour of this widget.
Container with pre/inter/post child space.
uint8_t gaps
Number of gaps between widgets.
NWidContainerFlags flags
Flags of the container.
uint8_t pip_pre
Amount of space before first widget.
uint8_t uz_pip_pre
Unscaled space before first widget.
uint8_t uz_pip_inter
Unscaled space between widgets.
uint8_t pip_ratio_pre
Ratio of remaining space before first widget.
uint8_t pip_post
Amount of space after last widget.
uint8_t pip_ratio_inter
Ratio of remaining space between widgets.
uint8_t pip_ratio_post
Ratio of remaining space after last widget.
uint8_t uz_pip_post
Unscaled space after last widget.
uint8_t pip_inter
Amount of space between widgets.
Base class for a resizable nested widget.
uint8_t uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
bool absolute
Set if minimum size is fixed and should not be resized.
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition widget.cpp:995
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1078
uint min_x
Minimal horizontal size of only this widget.
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
uint8_t uz_text_lines
'Unscaled' text lines, stored for resize calculation.
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition widget.cpp:1034
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition widget.cpp:1021
uint min_y
Minimal vertical size of only this widget.
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
bool UpdateMultilineWidgetSize(const std::string &str, int max_lines)
Try to set optimum widget size for a multiline text widget.
Definition widget.cpp:1058
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:1099
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1092
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition widget.cpp:1045
void SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Set desired aspect ratio of this widget.
Definition widget.cpp:964
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1008
Nested widget to display and control a scrollbar in a window.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2620
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2599
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Spacer widget.
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1924
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1945
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:1940
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1928
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1917
Stacked widgets, widgets all occupying the same space in the window.
int shown_plane
Plane being displayed (for NWID_SELECTION only).
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1322
const WidgetID index
If non-negative, index in the Window::widget_lookup.
WidgetLookup * widget_lookup
Window's widget lookup, updated in SetDisplayedPlane().
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:1363
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1394
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1418
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1383
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1403
Vertical container.
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition widget.cpp:1808
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1739
Nested widget to display a viewport in a window.
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2436
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2400
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2393
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2427
Scrollbar data structure.
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
const bool is_vertical
Scrollbar has vertical orientation.
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
size_type stepsize
Distance to scroll, when pressing the buttons or using the wheel.
void SetCount(size_t num)
Sets the number of elements in the list.
bool IsVertical() const
Is the scrollbar vertical or not?
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
size_type cap
Number of visible elements of the scroll bar.
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2459
size_type count
Number of elements in the list.
bool SetPosition(size_type position)
Sets the position of the first visible element.
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2533
size_type GetCount() const
Gets the number of elements in the list.
EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition widget.cpp:2480
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
size_type pos
Index of first visible item of the list.
size_type GetPosition() const
Gets the position of the first visible element in the list.
ScrollbarStepping
Stepping sizes when scrolling.
@ SS_BIG
Step in cap units.
@ SS_RAW
Step in single units.
@ SS_SMALL
Step in stepsize units.
Base class that provides memory initialization on dynamically created objects.
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:68
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
FontSize
Available font sizes.
Definition gfx_type.h:242
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
StringAlignment
How to align the to-be drawn text.
Definition gfx_type.h:374
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:294
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 NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
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 SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
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.
Definition widget.cpp:3400
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
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.
Definition widget.cpp:3381
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
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.
Integer math functions.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Widget part for setting text/image alignment within a widget.
StringAlignment align
Alignment of text/image.
Widget part for storing data and tooltip information.
WidgetData data
Data value of the widget.
StringID tooltip
Tooltip of the widget.
Widget part for storing pre/inter/post spaces.
uint8_t post
Amount of space before/between/after child widgets.
Widget part for storing padding.
Widget part for storing minimal text line data.
uint8_t lines
Number of text lines.
uint8_t spacing
Extra spacing around lines.
FontSize size
Font size of text lines.
Widget part for storing text colour.
TextColour colour
TextColour for DrawString.
FontSize size
Font size of text.
Widget part for storing basic widget information.
Colours colour
Widget colour.
WidgetID index
Index of the widget.
Partial widget specification to allow NWidgets to be written nested.
WidgetType type
Type of the part.
Coordinates of a point in 2D.
Padding dimensions to apply to each side of a Rect.
Specification of a rectangle with absolute coordinates of all edges.
Container with the data associated to a single widget.
Data structure for an opened window.
Definition window_gui.h:272
NWidgetPartTextLines text_lines
Part with text line data.
NWidgetPartPIP pip
Part with pre/inter/post spaces.
NWidgetPartPaddings padding
Part with paddings.
NWidgetFunctionType * func_ptr
Part with a function call.
NWidContainerFlags cont_flags
Part with container flags.
NWidgetPartDataTip data_tip
Part with a data/tooltip.
NWidgetPartAlignment align
Part with internal alignment.
NWidgetPartAspect aspect
Part to set aspect ratio.
NWidgetPartTextStyle text_style
Part with text style data.
Point xy
Part with an x/y size.
NWidgetPartWidget widget
Part with a start of a widget.
NWidgetDisplay
Nested widget flags that affect display and interaction with 'real' widgets.
@ NDB_DISABLED
Widget is disabled (greyed out) bit.
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
@ ND_DISABLED
Bit value of the disabled flag.
@ NDB_DROPDOWN_ACTIVE
Dropdown menu of the button dropdown widget is active.
@ NDB_SHADE_DIMMED
Display dimmed colours in the viewport.
@ NDB_HIGHLIGHT
Highlight of widget is on.
@ NDB_SHADE_GREY
Shade viewport to grey-scale.
@ ND_SCROLLBAR_UP
Bit value of the 'scrollbar up' flag.
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
@ NDB_LOWERED
Widget is lowered (pressed down) bit.
@ ND_LOWERED
Bit value of the lowered flag.
@ ND_HIGHLIGHT
Bit value of the highlight flag.
@ NDB_NO_TRANSPARENCY
Viewport is never transparent.
@ ND_SCROLLBAR_DOWN
Bit value of the 'scrollbar down' flag.
@ ND_DROPDOWN_CLOSED
Bit value of the 'dropdown closed' flag.
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:37
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:42
@ WPT_FILL
Widget part for specifying fill.
Definition widget_type.h:84
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition widget_type.h:90
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:43
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:44
@ NWID_CUSTOM
General Custom widget.
Definition widget_type.h:77
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition widget_type.h:82
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:74
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition widget_type.h:45
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:46
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition widget_type.h:91
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:41
@ WPT_ASPECT
Widget part for sepcifying aspect ratio.
Definition widget_type.h:92
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
@ WPT_RESIZE
Widget part for specifying resizing.
Definition widget_type.h:81
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition widget_type.h:89
@ WPT_PADDING
Widget part for specifying a padding.
Definition widget_type.h:86
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition widget_type.h:47
@ WWT_FRAME
Frame.
Definition widget_type.h:51
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition widget_type.h:83
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:39
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition widget_type.h:63
@ WPT_ATTRIBUTE_END
End marker for attribute NWidgetPart types.
Definition widget_type.h:93
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition widget_type.h:75
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition widget_type.h:96
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition widget_type.h:88
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition widget_type.h:85
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
@ WPT_ATTRIBUTE_BEGIN
Begin marker for attribute NWidgetPart types.
Definition widget_type.h:80
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition widget_type.h:87
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:69
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:73
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
@ WPT_FUNCTION
Widget part for calling a user function.
Definition widget_type.h:95
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition widget_type.h:54
@ NWID_LAYER
Layered widgets, all visible together.
Definition widget_type.h:72
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
bool IsContainerWidgetType(WidgetType tp)
Test if WidgetType is a container widget.
Definition widget.cpp:3324
StackedZeroSizePlanes
Display planes with zero size for NWidgetStacked.
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
@ SZSP_BEGIN
First zero-size plane.
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
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.
Definition widget.cpp:3442
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition widget.cpp:66
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
@ ST_RESIZE
Resize the nested widget tree.
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
ArrowWidgetValues
Values for an arrow widget.
Definition widget_type.h:21
@ AWV_LEFT
Force the arrow to the left.
Definition widget_type.h:24
@ AWV_RIGHT
Force the arrow to the right.
Definition widget_type.h:25
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:22
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:23
NWidContainerFlags
Nested widget container flags,.
@ NCB_BIGFIRST
Allocate space to biggest resize first.
@ NC_NONE
All flags cleared.
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
@ NCB_EQUALSIZE
Containers should keep all their (resizing) children equally large.
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
std::unique_ptr< NWidgetBase > NWidgetFunctionType()
Pointer to function returning a nested widget.
ResizeWidgetValues
WidgetData values for a resize box widget.
Definition widget_type.h:29
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition widget_type.h:30
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:31
Types related to windows.
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:16