OpenTTD Source 20250609-master-g3908df5fbe
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/bitmath_func.hpp"
14#include "core/math_func.hpp"
15#include "strings_type.h"
16#include "gfx_type.h"
17#include "window_type.h"
18
26
32
111
113enum SizingType : uint8_t {
116};
117
118enum class AspectFlag : uint8_t {
119 ResizeX,
120 ResizeY,
121};
123
124/* Forward declarations. */
125class NWidgetCore;
126class Scrollbar;
127
129using WidgetLookup = std::map<WidgetID, class NWidgetBase *>;
130
138public:
139 NWidgetBase(WidgetType tp, WidgetID index = -1) : type(tp), index(index) {}
140 virtual ~NWidgetBase() = default;
141
142 void ApplyAspectRatio();
143 virtual void AdjustPaddingForZoom();
144 virtual void SetupSmallestSize(Window *w) = 0;
145 virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
146
147 virtual void FillWidgetLookup(WidgetLookup &widget_lookup);
148
149 virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
151
157 template <class NWID>
159 {
160 for (NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
161 if (NWID *nwid = dynamic_cast<NWID *>(nwid_parent); nwid != nullptr) return nwid;
162 }
163 return nullptr;
164 }
165
171 template <class NWID>
172 const NWID *GetParentWidget() const
173 {
174 for (const NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
175 if (const NWID *nwid = dynamic_cast<const NWID *>(nwid_parent); nwid != nullptr) return nwid;
176 }
177 return nullptr;
178 }
179
180 inline WidgetID GetIndex() const { return this->index; }
181 virtual bool IsHighlighted() const { return false; }
182 virtual TextColour GetHighlightColour() const { return TC_INVALID; }
183 virtual void SetHighlighted([[maybe_unused]] TextColour highlight_colour) {}
184
192 inline void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
193 {
194 this->uz_padding.top = top;
195 this->uz_padding.right = right;
196 this->uz_padding.bottom = bottom;
197 this->uz_padding.left = left;
198 this->AdjustPaddingForZoom();
199 }
200
205 inline void SetPadding(const RectPadding &padding)
206 {
207 this->uz_padding = padding;
208 this->AdjustPaddingForZoom();
209 }
210
211 inline uint GetHorizontalStepSize(SizingType sizing) const;
212 inline uint GetVerticalStepSize(SizingType sizing) const;
213
214 virtual void Draw(const Window *w) = 0;
215 virtual void SetDirty(const Window *w) const;
216
217 Rect GetCurrentRect() const
218 {
219 Rect r;
220 r.left = this->pos_x;
221 r.top = this->pos_y;
222 r.right = this->pos_x + this->current_x - 1;
223 r.bottom = this->pos_y + this->current_y - 1;
224 return r;
225 }
226
228 uint fill_x = 0;
229 uint fill_y = 0;
230 uint resize_x = 0;
231 uint resize_y = 0;
232 /* Size of the widget in the smallest window possible.
233 * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
234 */
235 uint smallest_x = 0;
236 uint smallest_y = 0;
237 /* Current widget size (that is, after resizing). */
238 uint current_x = 0;
239 uint current_y = 0;
240 float aspect_ratio = 0;
241 AspectFlags aspect_flags = AspectFlag::ResizeX;
242
243 int pos_x = 0;
244 int pos_y = 0;
245
248
249 NWidgetBase *parent = nullptr;
250
251protected:
252 const WidgetID index = -1;
253
254 inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
255};
256
262{
263 return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
264}
265
271{
272 return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
273}
274
283inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
284{
285 this->pos_x = x;
286 this->pos_y = y;
287 if (sizing == ST_SMALLEST) {
288 this->smallest_x = given_width;
289 this->smallest_y = given_height;
290 }
291 this->current_x = given_width;
292 this->current_y = given_height;
293}
294
295
301public:
303
304 void AdjustPaddingForZoom() override;
305 void SetMinimalSize(uint min_x, uint min_y);
306 void SetMinimalSizeAbsolute(uint min_x, uint min_y);
307 void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size);
308 void SetFill(uint fill_x, uint fill_y);
309 void SetResize(uint resize_x, uint resize_y);
310 void SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX);
311 void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlag::ResizeX);
312
313 bool UpdateMultilineWidgetSize(const std::string &str, int max_lines);
314 bool UpdateSize(uint min_x, uint min_y);
315 bool UpdateVerticalSize(uint min_y);
316
317 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
318
319 uint min_x = 0;
320 uint min_y = 0;
321
322 bool absolute = false;
323 uint uz_min_x = 0;
324 uint uz_min_y = 0;
325
326 uint8_t uz_text_lines = 0;
327 uint8_t uz_text_spacing = 0;
329};
330
332enum NWidgetDisplayFlag : uint8_t {
333 /* Generic. */
336
337 /* Viewport widget. */
341
342 /* Button dropdown widget. */
344
345 /* Scrollbar widget. */
348
349 /* Generic. */
352};
354
357 StringID string{};
358 SpriteID sprite{};
359 ArrowWidgetValues arrow_widget_type{};
360 ResizeWidgetValues resize_widget_type{};
361 Colours alternate_colour = INVALID_COLOUR;
362 Dimension matrix{};
363};
364
370public:
372
373 void SetString(StringID string);
375 void SetSprite(SpriteID sprite);
377 void SetMatrixDimension(uint32_t columns, uint32_t rows);
380 StringID GetToolTip() const;
383
384 StringID GetString() const;
386
387 inline void SetLowered(bool lowered);
388 inline bool IsLowered() const;
389 inline void SetDisabled(bool disabled);
390 inline bool IsDisabled() const;
391
392 inline TextColour GetTextColour() const { return this->text_colour; }
393 inline FontSize GetFontSize() const { return this->text_size; }
394
395 NWidgetCore *GetWidgetFromPos(int x, int y) override;
396 bool IsHighlighted() const override;
397 TextColour GetHighlightColour() const override;
399
401 Colours colour;
402protected:
410
411 /* This function constructs the widgets, so it should be able to write the variables. */
412 friend void ApplyNWidgetPartAttribute(const struct NWidgetPart &nwid, NWidgetBase *dest);
413};
414
419inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
420{
422 this->highlight_colour = highlight_colour;
423}
424
426inline bool NWidgetCore::IsHighlighted() const
427{
429}
430
433{
434 return this->highlight_colour;
435}
436
441inline void NWidgetCore::SetLowered(bool lowered)
442{
444}
445
447inline bool NWidgetCore::IsLowered() const
448{
450}
451
456inline void NWidgetCore::SetDisabled(bool disabled)
457{
459}
460
462inline bool NWidgetCore::IsDisabled() const
463{
465}
466
467
473public:
475
476 void AdjustPaddingForZoom() override;
477 void Add(std::unique_ptr<NWidgetBase> &&wid);
478 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
479
480 void Draw(const Window *w) override;
481 NWidgetCore *GetWidgetFromPos(int x, int y) override;
482
484 inline bool IsEmpty() { return this->children.empty(); }
485
487 void Clear() { this->children.clear(); }
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
525 int shown_plane = 0;
526private:
528};
529
536
539public:
541
542 void AdjustPaddingForZoom() override;
543 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
544 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post);
545
546protected:
548 uint8_t pip_pre = 0;
549 uint8_t pip_inter = 0;
550 uint8_t pip_post = 0;
551 uint8_t pip_ratio_pre = 0;
552 uint8_t pip_ratio_inter = 0;
553 uint8_t pip_ratio_post = 0;
554
555 uint8_t uz_pip_pre = 0;
556 uint8_t uz_pip_inter = 0;
557 uint8_t uz_pip_post = 0;
558
559 uint8_t gaps = 0;
560};
561
567public:
569
570 void SetupSmallestSize(Window *w) override;
571 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
572};
573
579public:
581
582 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
583};
584
590public:
592
593 void SetupSmallestSize(Window *w) override;
594 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
595};
596
606public:
608
609 void SetClicked(int clicked);
610 void SetCount(int count);
612 int GetCurrentElement() const;
613
614 void SetupSmallestSize(Window *w) override;
615 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
616
617 NWidgetCore *GetWidgetFromPos(int x, int y) override;
618 void Draw(const Window *w) override;
619protected:
620 Colours colour{};
621 int clicked = -1;
622 int count = 0;
624 Scrollbar *sb = nullptr;
625private:
626 int widget_w = 0;
627 int widget_h = 0;
628 int widgets_x = 0;
629 int widgets_y = 0;
630
631 void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
632};
633
634
640public:
641 NWidgetSpacer(int width, int height);
642
643 void SetupSmallestSize(Window *w) override;
644
645 void Draw(const Window *w) override;
646 void SetDirty(const Window *w) const override;
647 NWidgetCore *GetWidgetFromPos(int x, int y) override;
648};
649
655public:
656 NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child = nullptr);
657
658 void Add(std::unique_ptr<NWidgetBase> &&nwid);
659 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
660 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
661
662 void AdjustPaddingForZoom() override;
663 void SetupSmallestSize(Window *w) override;
664 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
665
666 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
667
668 void Draw(const Window *w) override;
669 NWidgetCore *GetWidgetFromPos(int x, int y) override;
671
672private:
673 std::unique_ptr<NWidgetPIPContainer> child{};
674};
675
686public:
688
689 void SetupSmallestSize(Window *w) override;
690 void Draw(const Window *w) override;
691
692 void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
694};
695
700public:
701 using size_type = int32_t;
702 static constexpr size_type max_size_type = std::numeric_limits<size_type>::max();
703 static constexpr size_type npos = max_size_type;
704private:
705 const bool is_vertical = false;
706 size_type count = 0;
707 size_type cap = 0;
708 size_type pos = 0;
709 size_type stepsize = 1;
710
711public:
718
720
725 inline size_type GetCount() const
726 {
727 return this->count;
728 }
729
734 inline size_type GetCapacity() const
735 {
736 return this->cap;
737 }
738
743 inline size_type GetPosition() const
744 {
745 return this->pos;
746 }
747
753 inline bool IsVisible(size_type item) const
754 {
755 return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
756 }
757
762 inline bool IsVertical() const
763 {
764 return this->is_vertical;
765 }
766
771 void SetStepSize(size_t stepsize)
772 {
773 assert(stepsize > 0);
774
775 this->stepsize = ClampTo<size_type>(stepsize);
776 }
777
783 void SetCount(size_t num)
784 {
785 assert(num < Scrollbar::max_size_type);
786
787 this->count = ClampTo<size_type>(num);
788 /* Ensure position is within bounds */
789 this->SetPosition(this->pos);
790 }
791
797 void SetCapacity(size_t capacity)
798 {
799 assert(capacity < Scrollbar::max_size_type);
800
801 this->cap = ClampTo<size_type>(capacity);
802 /* Ensure position is within bounds */
803 this->SetPosition(this->pos);
804 }
805
806 void SetCapacityFromWidget(Window *w, WidgetID widget, int padding = 0);
807
813 bool SetPosition(size_type position)
814 {
815 size_type old_pos = this->pos;
816 this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
817 return this->pos != old_pos;
818 }
819
827 bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
828 {
829 if (difference == 0) return false;
830 switch (unit) {
831 case SS_SMALL: difference *= this->stepsize; break;
832 case SS_BIG: difference *= this->cap; break;
833 default: break;
834 }
835 return this->SetPosition(this->pos + difference);
836 }
837
844 void ScrollTowards(size_type position)
845 {
846 if (position < this->GetPosition()) {
847 /* scroll up to the item */
848 this->SetPosition(position);
849 } else if (position >= this->GetPosition() + this->GetCapacity()) {
850 /* scroll down so that the item is at the bottom */
851 this->SetPosition(position - this->GetCapacity() + 1);
852 }
853 }
854
855 size_type GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
856
862 template <typename Tcontainer>
863 auto GetVisibleRangeIterators(Tcontainer &container) const
864 {
865 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
866 auto first = std::next(std::begin(container), this->GetPosition());
867 auto last = std::next(first, std::min<size_t>(this->GetCapacity(), this->GetCount() - this->GetPosition()));
868 return std::make_pair(first, last);
869 }
870
881 template <typename Tcontainer>
882 auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
883 {
884 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
885 size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
886 if (row == Scrollbar::npos) return std::end(container);
887
888 return std::next(std::begin(container), row);
889 }
890
891 EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
892};
893
899class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
900public:
902
903 void SetupSmallestSize(Window *w) override;
904 void Draw(const Window *w) override;
905
906 static void InvalidateDimensionCache();
907 static Dimension GetVerticalDimension();
908 static Dimension GetHorizontalDimension();
909
910private:
913};
914
919class NWidgetLeaf : public NWidgetCore {
920public:
921 NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const WidgetData &data, StringID tip);
922
923 void SetupSmallestSize(Window *w) override;
924 void Draw(const Window *w) override;
925
926 bool ButtonHit(const Point &pt);
927
928 static void InvalidateDimensionCache();
929
933private:
938};
939
947inline uint ComputeMaxSize(uint base, uint max_space, uint step)
948{
949 if (base >= max_space || step == 0) return base;
950 if (step == 1) return max_space;
951 uint increment = max_space - base;
952 increment -= increment % step;
953 return base + increment;
954}
955
1013
1022
1024 NWidContainerFlags flags;
1025 WidgetID index;
1026};
1027
1034
1040 uint8_t pre, inter, post;
1041};
1042
1052
1061
1069
1071 float ratio;
1072 AspectFlags flags;
1073};
1074
1079using NWidgetFunctionType = std::unique_ptr<NWidgetBase>();
1080
1099
1100 /* Constructors for each NWidgetPartUnion data type. */
1101 constexpr NWidgetPartUnion() : xy() {}
1102 constexpr NWidgetPartUnion(Point xy) : xy(xy) {}
1103 constexpr NWidgetPartUnion(NWidgetPartDataTip data_tip) : data_tip(data_tip) {}
1104 constexpr NWidgetPartUnion(NWidgetPartWidget widget) : widget(widget) {}
1105 constexpr NWidgetPartUnion(NWidgetPartPaddings padding) : padding(padding) {}
1106 constexpr NWidgetPartUnion(NWidgetPartPIP pip) : pip(pip) {}
1107 constexpr NWidgetPartUnion(NWidgetPartTextLines text_lines) : text_lines(text_lines) {}
1108 constexpr NWidgetPartUnion(NWidgetPartTextStyle text_style) : text_style(text_style) {}
1109 constexpr NWidgetPartUnion(NWidgetPartAlignment align) : align(align) {}
1110 constexpr NWidgetPartUnion(NWidgetFunctionType *func_ptr) : func_ptr(func_ptr) {}
1111 constexpr NWidgetPartUnion(NWidgetPartContainer container) : container(container) {}
1112 constexpr NWidgetPartUnion(NWidgetPartAspect aspect) : aspect(aspect) {}
1113 } u;
1114
1115 /* Constructors for each NWidgetPart data type. */
1116 explicit constexpr NWidgetPart(WidgetType type) : type(type), u() {}
1117 constexpr NWidgetPart(WidgetType type, Point xy) : type(type), u(xy) {}
1118 constexpr NWidgetPart(WidgetType type, NWidgetPartDataTip data_tip) : type(type), u(data_tip) {}
1119 constexpr NWidgetPart(WidgetType type, NWidgetPartWidget widget) : type(type), u(widget) {}
1120 constexpr NWidgetPart(WidgetType type, NWidgetPartPaddings padding) : type(type), u(padding) {}
1121 constexpr NWidgetPart(WidgetType type, NWidgetPartPIP pip) : type(type), u(pip) {}
1122 constexpr NWidgetPart(WidgetType type, NWidgetPartTextLines text_lines) : type(type), u(text_lines) {}
1123 constexpr NWidgetPart(WidgetType type, NWidgetPartTextStyle text_style) : type(type), u(text_style) {}
1124 constexpr NWidgetPart(WidgetType type, NWidgetPartAlignment align) : type(type), u(align) {}
1125 constexpr NWidgetPart(WidgetType type, NWidgetFunctionType *func_ptr) : type(type), u(func_ptr) {}
1126 constexpr NWidgetPart(WidgetType type, NWidgetPartContainer container) : type(type), u(container) {}
1127 constexpr NWidgetPart(WidgetType type, NWidgetPartAspect aspect) : type(type), u(aspect) {}
1128};
1129
1136constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
1137{
1138 return NWidgetPart{WPT_RESIZE, Point{dx, dy}};
1139}
1140
1147constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
1148{
1149 return NWidgetPart{WPT_MINSIZE, Point{x, y}};
1150}
1151
1157{
1158 return NWidgetPart{WPT_MINSIZE, Point{4, 0}};
1159}
1160
1167{
1168 return NWidgetPart{WPT_MINSIZE, Point{20 * width + 2, 22}};
1169}
1170
1178constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size = FS_NORMAL)
1179{
1180 return NWidgetPart{WPT_MINTEXTLINES, NWidgetPartTextLines{lines, spacing, size}};
1181}
1182
1190{
1191 return NWidgetPart{WPT_TEXTSTYLE, NWidgetPartTextStyle{colour, size}};
1192}
1193
1203
1210constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
1211{
1212 return NWidgetPart{WPT_FILL, Point{fill_x, fill_y}};
1213}
1214
1221{
1223}
1224
1231constexpr NWidgetPart SetStringTip(StringID string, StringID tip = {})
1232{
1233 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string}, tip}};
1234}
1235
1242constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip = {})
1243{
1244 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.sprite = sprite}, tip}};
1245}
1246
1254constexpr NWidgetPart SetSpriteStringTip(SpriteID sprite, StringID string, StringID tip = {})
1255{
1256 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string, .sprite = sprite}, tip}};
1257}
1258
1266{
1267 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.arrow_widget_type = widget_type}, tip}};
1268}
1269
1277{
1278 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.resize_widget_type = widget_type}, tip}};
1279}
1280
1287constexpr NWidgetPart SetAlternateColourTip(Colours colour, StringID tip)
1288{
1289 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.alternate_colour = colour}, tip}};
1290}
1291
1299constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip = {})
1300{
1301 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.matrix{ cols, rows }}, tip}};
1302}
1303
1310{
1311 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{}, tip}};
1312}
1313
1323constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
1324{
1325 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{left, top, right, bottom}};
1326}
1327
1334constexpr NWidgetPart SetPadding(uint8_t horizontal, uint8_t vertical)
1335{
1336 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{horizontal, vertical, horizontal, vertical}};
1337}
1338
1344constexpr NWidgetPart SetPadding(const RectPadding &padding)
1345{
1347}
1348
1354constexpr NWidgetPart SetPadding(uint8_t padding)
1355{
1356 return SetPadding(padding, padding, padding, padding);
1357}
1358
1366constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
1367{
1368 return NWidgetPart{WPT_PIPSPACE, NWidgetPartPIP{pre, inter, post}};
1369}
1370
1378constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
1379{
1380 return NWidgetPart{WPT_PIPRATIO, NWidgetPartPIP{ratio_pre, ratio_inter, ratio_post}};
1381}
1382
1391{
1392 return NWidgetPart{WPT_SCROLLBAR, NWidgetPartWidget{INVALID_COLOUR, index}};
1393}
1394
1401constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX)
1402{
1403 return NWidgetPart{WPT_ASPECT, NWidgetPartAspect{ratio, flags}};
1404}
1405
1415constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx = -1)
1416{
1417 return NWidgetPart{tp, NWidgetPartWidget{col, idx}};
1418}
1419
1426constexpr NWidgetPart NWidget(WidgetType tp, NWidContainerFlags cont_flags = {}, WidgetID idx = -1)
1427{
1428 return NWidgetPart{tp, NWidgetPartContainer{cont_flags, idx}};
1429}
1430
1437{
1438 return NWidgetPart{WPT_FUNCTION, func_ptr};
1439}
1440
1442std::unique_ptr<NWidgetBase> MakeNWidgets(std::span<const NWidgetPart> nwid_parts, std::unique_ptr<NWidgetBase> &&container);
1443std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(std::span<const NWidgetPart> nwid_parts, NWidgetStacked **shade_select);
1444
1445std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
1446
1448
1449#endif /* WIDGET_TYPE_H */
Functions related to bit mathematics.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
Nested widget with a child.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2346
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:2356
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:2292
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2225
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:2191
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2310
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition widget.cpp:2172
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:2304
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:2210
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:942
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.
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.
const WidgetID index
Index of the nested widget (-1 means 'not used').
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition widget.cpp:962
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).
virtual void FillWidgetLookup(WidgetLookup &widget_lookup)
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:926
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:1303
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1310
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1318
bool IsEmpty()
Return whether the container is empty.
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in container.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1327
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:1281
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:1235
bool IsHighlighted() const override
Return whether the widget is highlighted.
bool IsDisabled() const
Return whether the widget is disabled.
void SetSprite(SpriteID sprite)
Set sprite of the nested widget.
Definition widget.cpp:1185
NWidgetDisplayFlags disp_flags
Flags that affect display and interaction with the widget.
void SetTextStyle(TextColour colour, FontSize size)
Set the text style of the nested widget.
Definition widget.cpp:1225
WidgetID GetScrollbarIndex() const
Get the WidgetID of this nested widget's scrollbar.
Definition widget.cpp:1271
TextColour highlight_colour
Colour of highlight.
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition widget.cpp:1253
void SetResizeWidgetType(ResizeWidgetValues type)
Set the resize widget type of the nested widget.
Definition widget.cpp:1215
void SetSpriteTip(SpriteID sprite, StringID tool_tip)
Set sprite and tool tip of the nested widget.
Definition widget.cpp:1195
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:1262
WidgetID scrollbar_index
Index of an attached scrollbar.
StringID GetToolTip() const
Get the tool tip of the nested widget.
Definition widget.cpp:1244
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1276
void SetString(StringID string)
Set string of the nested widget.
Definition widget.cpp:1165
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:1206
void SetLowered(bool lowered)
Lower or raise the widget.
TextColour GetHighlightColour() const override
Return the colour of the highlight.
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1175
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:1724
Horizontal container.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1546
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:1615
Leaf widget.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2974
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition widget.cpp:2651
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:2787
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:3118
Matrix container with implicitly equal sized (virtual) sub-widgets.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2071
int count
Amount of valid elements.
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition widget.cpp:1940
int GetCurrentElement() const
Get current element.
Definition widget.cpp:1990
Scrollbar * sb
The scrollbar we're associated with.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1995
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:1981
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:2126
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:2017
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2041
int clicked
The currently clicked element.
void SetCount(int count)
Set the number of elements in this matrix.
Definition widget.cpp:1957
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.
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post)
Set additional pre/inter/post space for the container.
Definition widget.cpp:1539
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
Set additional pre/inter/post space for the container.
Definition widget.cpp:1519
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:1034
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1117
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:1073
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition widget.cpp:1060
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:1097
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:1138
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1131
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition widget.cpp:1084
void SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Set desired aspect ratio of this widget.
Definition widget.cpp:1003
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1047
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:2595
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2574
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Spacer widget.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1931
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:1926
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1914
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1907
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:1338
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:1379
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1409
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1433
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1399
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1418
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:1798
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1729
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:2411
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2375
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2368
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2402
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:2434
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:2508
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:2455
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.
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:250
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:251
StringAlignment
How to align the to-be drawn text.
Definition gfx_type.h:382
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:393
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:302
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 SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
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 SetAlternateColourTip(Colours colour, StringID tip)
Widget part function for setting the alternate colour and tooltip.
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:3402
constexpr NWidgetPart SetToolbarSpacerMinimalSize()
Widget part function to setting the minimal size for a toolbar spacer.
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:3383
constexpr NWidgetPart SetSpriteStringTip(SpriteID sprite, StringID string, StringID tip={})
Widget part function for setting the sprite, string and tooltip.
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:273
NWidgetPartContainer container
Part with container flags.
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.
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.
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:36
@ 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:41
@ WPT_FILL
Widget part for specifying fill.
Definition widget_type.h:85
@ WWT_PUSHIMGTEXTBTN
Normal push-button (no toggle button) with image and text caption.
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition widget_type.h:91
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ 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:43
@ NWID_CUSTOM
General Custom widget.
Definition widget_type.h:78
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition widget_type.h:83
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:49
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:75
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:71
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:63
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition widget_type.h:44
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:67
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition widget_type.h:92
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WPT_ASPECT
Widget part for specifying aspect ratio.
Definition widget_type.h:93
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:58
@ WPT_RESIZE
Widget part for specifying resizing.
Definition widget_type.h:82
@ WWT_IMGTEXTBTN
(Toggle) Button with image and text
Definition widget_type.h:48
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:51
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:53
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:77
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition widget_type.h:90
@ WPT_PADDING
Widget part for specifying a padding.
Definition widget_type.h:87
@ WWT_BOOLBTN
Standard boolean toggle button.
Definition widget_type.h:47
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:69
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:61
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition widget_type.h:46
@ WWT_FRAME
Frame.
Definition widget_type.h:52
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition widget_type.h:84
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition widget_type.h:64
@ WPT_ATTRIBUTE_END
End marker for attribute NWidgetPart types.
Definition widget_type.h:94
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition widget_type.h:76
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition widget_type.h:97
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:60
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition widget_type.h:89
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition widget_type.h:86
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:57
@ WPT_ATTRIBUTE_BEGIN
Begin marker for attribute NWidgetPart types.
Definition widget_type.h:81
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition widget_type.h:88
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:70
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:74
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:62
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:50
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:68
@ WPT_FUNCTION
Widget part for calling a user function.
Definition widget_type.h:96
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition widget_type.h:55
@ NWID_LAYER
Layered widgets, all visible together.
Definition widget_type.h:73
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:72
NWidgetDisplayFlag
Nested widget flags that affect display and interaction with 'real' widgets.
@ DropdownClosed
Dropdown menu of the dropdown widget has closed.
@ ScrollbarDown
Down-button is lowered bit.
@ Lowered
Widget is lowered (pressed down) bit.
@ ShadeDimmed
Display dimmed colours in the viewport.
@ ShadeGrey
Shade viewport to grey-scale.
@ ScrollbarUp
Up-button is lowered bit.
@ DropdownActive
Dropdown menu of the button dropdown widget is active.
@ Highlight
Highlight of widget is on.
@ NoTransparency
Viewport is never transparent.
@ Disabled
Widget is disabled (greyed out) bit.
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:3326
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).
NWidContainerFlag
Nested widget container flags,.
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ BigFirst
Allocate space to biggest resize first.
std::unique_ptr< NWidgetBase >() NWidgetFunctionType
Pointer to function returning a nested widget.
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:3444
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition widget.cpp:80
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:20
@ AWV_LEFT
Force the arrow to the left.
Definition widget_type.h:23
@ AWV_RIGHT
Force the arrow to the right.
Definition widget_type.h:24
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:21
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:22
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
ResizeWidgetValues
WidgetData values for a resize box widget.
Definition widget_type.h:28
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition widget_type.h:29
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:30
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