OpenTTD Source: src/widget_type.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef WIDGET_TYPE_H
11#define WIDGET_TYPE_H
12
13#include "core/math_func.hpp"
14#include "strings_type.h"
15#include "gfx_type.h"
16#include "window_type.h"
17
19 enum ArrowWidgetValues : uint8_t {
20 AWV_DECREASE,
21 AWV_INCREASE,
22 AWV_LEFT,
23 AWV_RIGHT,
24};
25
27 enum ResizeWidgetValues : uint8_t {
28 RWV_SHOW_BEVEL,
29 RWV_HIDE_BEVEL,
30};
31
35 enum WidgetType : uint8_t {
36 /* Window widget types. */
37 WWT_EMPTY,
38
39 WWT_PANEL,
40 WWT_INSET,
41 WWT_IMGBTN,
42 WWT_IMGBTN_2,
43 WWT_ARROWBTN,
44 WWT_TEXTBTN,
45 WWT_TEXTBTN_2,
46 WWT_BOOLBTN,
47 WWT_IMGTEXTBTN,
48 WWT_LABEL,
49 WWT_TEXT,
50 WWT_MATRIX,
51 WWT_FRAME,
52 WWT_CAPTION,
53
54 WWT_DEBUGBOX,
55 WWT_SHADEBOX,
56 WWT_DEFSIZEBOX,
57 WWT_STICKYBOX,
58
59 WWT_RESIZEBOX,
60 WWT_CLOSEBOX,
61 WWT_DROPDOWN,
62 WWT_EDITBOX,
63 WWT_LAST,
64
65 /* Nested widget types. */
66 NWID_HORIZONTAL,
67 NWID_HORIZONTAL_LTR,
68 NWID_VERTICAL,
69 NWID_MATRIX,
70 NWID_SPACER,
71 NWID_SELECTION,
72 NWID_LAYER,
73 NWID_VIEWPORT,
74 NWID_BUTTON_DROPDOWN,
75 NWID_HSCROLLBAR,
76 NWID_VSCROLLBAR,
77 NWID_CUSTOM,
78
79 /* Nested widget part types. */
80 WPT_ATTRIBUTE_BEGIN,
81 WPT_RESIZE,
82 WPT_MINSIZE,
83 WPT_MINTEXTLINES,
84 WPT_FILL,
85 WPT_DATATIP,
86 WPT_PADDING,
87 WPT_PIPSPACE,
88 WPT_PIPRATIO,
89 WPT_TEXTSTYLE,
90 WPT_ALIGNMENT,
91 WPT_SCROLLBAR,
92 WPT_ASPECT,
93 WPT_TOOLBARSIZE,
94 WPT_ATTRIBUTE_END,
95
96 WPT_FUNCTION,
97 WPT_ENDCONTAINER,
98
99 /* Pushable window widget types. */
100 WWT_MASK = 0x7F,
101
102 WWB_PUSHBUTTON = 1 << 7,
103
104 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON,
105 WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON,
106 WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON,
107 WWT_PUSHARROWBTN = WWT_ARROWBTN | WWB_PUSHBUTTON,
108 WWT_PUSHIMGTEXTBTN = WWT_IMGTEXTBTN | WWB_PUSHBUTTON,
109 NWID_PUSHBUTTON_DROPDOWN = NWID_BUTTON_DROPDOWN | WWB_PUSHBUTTON,
110};
111
113 enum SizingType : uint8_t {
114 ST_SMALLEST,
115 ST_RESIZE,
116};
117
118enum class AspectFlag : uint8_t {
119 ResizeX,
120 ResizeY,
121};
122using AspectFlags = EnumBitSet<AspectFlag, uint8_t>;
123
124/* Forward declarations. */
125class NWidgetCore;
126class Scrollbar;
127
129 using WidgetLookup = std::map<WidgetID, class NWidgetBase *>;
130
137 class NWidgetBase {
138public:
139 NWidgetBase(WidgetType tp, WidgetID index = INVALID_WIDGET) : 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;
150 virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
151
157 template <class NWID>
158 NWID *GetParentWidget()
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
227 WidgetType type{};
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
246 RectPadding padding{};
247 RectPadding uz_padding{};
248
249 NWidgetBase *parent = nullptr;
250
251protected:
252 const WidgetID index = INVALID_WIDGET;
253
254 inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
255};
256
261 inline uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
262{
263 return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
264}
265
270 inline uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
271{
272 return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
273}
274
283 inline 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
300 class NWidgetResizeBase : public NWidgetBase {
301public:
302 NWidgetResizeBase(WidgetType tp, WidgetID index, uint fill_x, uint fill_y);
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 SetToolbarMinimalSize(uint8_t toolbar_size);
309 void SetFill(uint fill_x, uint fill_y);
310 void SetResize(uint resize_x, uint resize_y);
311 void SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX);
312 void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlag::ResizeX);
313
314 bool UpdateMultilineWidgetSize(const std::string &str, int max_lines);
315 bool UpdateSize(uint min_x, uint min_y);
316 bool UpdateVerticalSize(uint min_y);
317
318 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
319
320 uint min_x = 0;
321 uint min_y = 0;
322
323 bool absolute = false;
324 uint uz_min_x = 0;
325 uint uz_min_y = 0;
326
327 uint8_t uz_text_lines = 0;
328 uint8_t uz_text_spacing = 0;
329 FontSize uz_text_size{};
330 uint8_t toolbar_size = 0;
331};
332
334 enum NWidgetDisplayFlag : uint8_t {
335 /* Generic. */
336 Lowered,
337 Disabled,
338
339 /* Viewport widget. */
340 NoTransparency,
341 ShadeGrey,
342 ShadeDimmed,
343
344 /* Button dropdown widget. */
345 DropdownActive,
346
347 /* Scrollbar widget. */
348 ScrollbarUp,
349 ScrollbarDown,
350
351 /* Generic. */
352 Highlight,
353 DropdownClosed,
354};
355using NWidgetDisplayFlags = EnumBitSet<NWidgetDisplayFlag, uint16_t>;
356
358 struct WidgetData {
359 StringID string{};
360 SpriteID sprite{};
361 ArrowWidgetValues arrow_widget_type{};
362 ResizeWidgetValues resize_widget_type{};
363 Colours alternate_colour = INVALID_COLOUR;
364 Dimension matrix{};
365};
366
371 class NWidgetCore : public NWidgetResizeBase {
372public:
373 NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, const WidgetData &widget_data, StringID tool_tip);
374
375 void SetString(StringID string);
376 void SetStringTip(StringID string, StringID tool_tip);
377 void SetSprite(SpriteID sprite);
378 void SetSpriteTip(SpriteID sprite, StringID tool_tip);
379 void SetMatrixDimension(uint32_t columns, uint32_t rows);
380 void SetResizeWidgetType(ResizeWidgetValues type);
381 void SetToolTip(StringID tool_tip);
382 StringID GetToolTip() const;
383 void SetTextStyle(TextColour colour, FontSize size);
384 void SetAlignment(StringAlignment align);
385
386 StringID GetString() const;
387 WidgetID GetScrollbarIndex() 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 inline TextColour GetTextColour() const { return this->text_colour; }
395 inline FontSize GetFontSize() const { return this->text_size; }
396
397 NWidgetCore *GetWidgetFromPos(int x, int y) override;
398 bool IsHighlighted() const override;
399 TextColour GetHighlightColour() const override;
400 void SetHighlighted(TextColour highlight_colour) override;
401
402 NWidgetDisplayFlags disp_flags;
403 Colours colour;
404protected:
405 WidgetData widget_data{};
406 StringID tool_tip{};
407 WidgetID scrollbar_index = INVALID_WIDGET;
408 TextColour highlight_colour{};
409 TextColour text_colour{};
410 FontSize text_size = FS_NORMAL;
411 StringAlignment align = SA_CENTER;
412
413 /* This function constructs the widgets, so it should be able to write the variables. */
414 friend void ApplyNWidgetPartAttribute(const struct NWidgetPart &nwid, NWidgetBase *dest);
415};
416
421 inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
422{
423 highlight_colour != TC_INVALID ? this->disp_flags.Set(NWidgetDisplayFlag::Highlight) : this->disp_flags.Reset(NWidgetDisplayFlag::Highlight);
424 this->highlight_colour = highlight_colour;
425}
426
428 inline bool NWidgetCore::IsHighlighted() const
429{
430 return this->disp_flags.Test(NWidgetDisplayFlag::Highlight);
431}
432
434 inline TextColour NWidgetCore::GetHighlightColour() const
435{
436 return this->highlight_colour;
437}
438
443 inline void NWidgetCore::SetLowered(bool lowered)
444{
445 lowered ? this->disp_flags.Set(NWidgetDisplayFlag::Lowered) : this->disp_flags.Reset(NWidgetDisplayFlag::Lowered);
446}
447
449 inline bool NWidgetCore::IsLowered() const
450{
451 return this->disp_flags.Test(NWidgetDisplayFlag::Lowered);
452}
453
458 inline void NWidgetCore::SetDisabled(bool disabled)
459{
460 this->disp_flags = disabled ? this->disp_flags.Set(NWidgetDisplayFlag::Disabled) : this->disp_flags.Reset(NWidgetDisplayFlag::Disabled);
461}
462
464 inline bool NWidgetCore::IsDisabled() const
465{
466 return this->disp_flags.Test(NWidgetDisplayFlag::Disabled);
467}
468
469
474 class NWidgetContainer : public NWidgetBase {
475public:
476 NWidgetContainer(WidgetType tp, WidgetID index = INVALID_WIDGET) : NWidgetBase(tp, index) {}
477
478 void AdjustPaddingForZoom() override;
479 void Add(std::unique_ptr<NWidgetBase> &&wid);
480 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
481
482 void Draw(const Window *w) override;
483 NWidgetCore *GetWidgetFromPos(int x, int y) override;
484
486 inline bool IsEmpty() { return this->children.empty(); }
487
488 NWidgetBase *GetWidgetOfType(WidgetType tp) override;
489 void UnfocusWidgets(Window *parent_window);
490
495 inline void Clear(Window *parent_window)
496 {
497 this->UnfocusWidgets(parent_window);
498 this->children.clear();
499 }
500
501protected:
502 std::vector<std::unique_ptr<NWidgetBase>> children{};
503};
504
506 enum StackedZeroSizePlanes : int {
507 SZSP_VERTICAL = INT_MAX / 2,
508 SZSP_HORIZONTAL,
509 SZSP_NONE,
510
511 SZSP_BEGIN = SZSP_VERTICAL,
512};
513
524 class NWidgetStacked : public NWidgetContainer {
525public:
526 NWidgetStacked(WidgetID index) : NWidgetContainer(NWID_SELECTION, index) {}
527
528 void SetupSmallestSize(Window *w) override;
529 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
530 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
531
532 void Draw(const Window *w) override;
533 NWidgetCore *GetWidgetFromPos(int x, int y) override;
534
535 bool SetDisplayedPlane(int plane);
536
537 int shown_plane = 0;
538private:
539 WidgetLookup *widget_lookup = nullptr;
540};
541
543 enum NWidContainerFlag : uint8_t {
544 EqualSize,
545 BigFirst,
546};
547using NWidContainerFlags = EnumBitSet<NWidContainerFlag, uint8_t>;
548
550 class NWidgetPIPContainer : public NWidgetContainer {
551public:
552 NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags = {}, WidgetID index = INVALID_WIDGET) : NWidgetContainer(tp, index), flags(flags) {}
553
554 void AdjustPaddingForZoom() override;
555 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
556 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
557
558protected:
559 NWidContainerFlags flags{};
560 uint8_t pip_pre = 0;
561 uint8_t pip_inter = 0;
562 uint8_t pip_post = 0;
563 uint8_t pip_ratio_pre = 0;
564 uint8_t pip_ratio_inter = 0;
565 uint8_t pip_ratio_post = 0;
566
567 uint8_t uz_pip_pre = 0;
568 uint8_t uz_pip_inter = 0;
569 uint8_t uz_pip_post = 0;
570
571 uint8_t gaps = 0;
572};
573
578 class NWidgetHorizontal : public NWidgetPIPContainer {
579public:
580 NWidgetHorizontal(NWidContainerFlags flags = {}, WidgetID index = INVALID_WIDGET, WidgetType type = NWID_HORIZONTAL) : NWidgetPIPContainer(type, flags, index) {}
581
582 void SetupSmallestSize(Window *w) override;
583 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
584};
585
590 class NWidgetHorizontalLTR : public NWidgetHorizontal {
591public:
592 NWidgetHorizontalLTR(NWidContainerFlags flags = {}, WidgetID index = INVALID_WIDGET) : NWidgetHorizontal(flags, index, NWID_HORIZONTAL_LTR) {}
593
594 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
595};
596
601 class NWidgetVertical : public NWidgetPIPContainer {
602public:
603 NWidgetVertical(NWidContainerFlags flags = {}, WidgetID index = INVALID_WIDGET) : NWidgetPIPContainer(NWID_VERTICAL, flags, index) {}
604
605 void SetupSmallestSize(Window *w) override;
606 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
607};
608
617 class NWidgetMatrix : public NWidgetPIPContainer {
618public:
619 NWidgetMatrix(Colours colour, WidgetID index) : NWidgetPIPContainer(NWID_MATRIX, NWidContainerFlag::EqualSize, index), colour(colour) {}
620
621 void SetClicked(int clicked);
622 void SetCount(int count);
623 void SetScrollbar(Scrollbar *sb);
624 int GetCurrentElement() const;
625
626 void SetupSmallestSize(Window *w) override;
627 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
628
629 NWidgetCore *GetWidgetFromPos(int x, int y) override;
630 void Draw(const Window *w) override;
631protected:
632 Colours colour{};
633 int clicked = -1;
634 int count = 0;
635 int current_element = 0;
636 Scrollbar *sb = nullptr;
637private:
638 int widget_w = 0;
639 int widget_h = 0;
640 int widgets_x = 0;
641 int widgets_y = 0;
642
643 void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
644};
645
646
651 class NWidgetSpacer : public NWidgetResizeBase {
652public:
653 NWidgetSpacer(int width, int height);
654
655 void SetupSmallestSize(Window *w) override;
656
657 void Draw(const Window *w) override;
658 void SetDirty(const Window *w) const override;
659 NWidgetCore *GetWidgetFromPos(int x, int y) override;
660};
661
666 class NWidgetBackground : public NWidgetCore {
667public:
668 NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child = nullptr);
669
670 void Add(std::unique_ptr<NWidgetBase> &&nwid);
671 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
672 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
673
674 void AdjustPaddingForZoom() override;
675 void SetupSmallestSize(Window *w) override;
676 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
677
678 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
679
680 void Draw(const Window *w) override;
681 NWidgetCore *GetWidgetFromPos(int x, int y) override;
682 NWidgetBase *GetWidgetOfType(WidgetType tp) override;
683
684private:
685 std::unique_ptr<NWidgetPIPContainer> child{};
686};
687
697 class NWidgetViewport : public NWidgetCore {
698public:
699 NWidgetViewport(WidgetID index);
700
701 void SetupSmallestSize(Window *w) override;
702 void Draw(const Window *w) override;
703
704 void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
705 void UpdateViewportCoordinates(Window *w);
706};
707
711 class Scrollbar {
712public:
713 using size_type = int32_t;
714 static constexpr size_type max_size_type = std::numeric_limits<size_type>::max();
715 static constexpr size_type npos = max_size_type;
716private:
717 const bool is_vertical = false;
718 size_type count = 0;
719 size_type cap = 0;
720 size_type pos = 0;
721 size_type stepsize = 1;
722
723public:
725 enum ScrollbarStepping : uint8_t {
726 SS_RAW,
727 SS_SMALL,
728 SS_BIG,
729 };
730
731 Scrollbar(bool is_vertical) : is_vertical(is_vertical) {}
732
737 inline size_type GetCount() const
738 {
739 return this->count;
740 }
741
746 inline size_type GetCapacity() const
747 {
748 return this->cap;
749 }
750
755 inline size_type GetPosition() const
756 {
757 return this->pos;
758 }
759
765 inline bool IsVisible(size_type item) const
766 {
767 return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
768 }
769
774 inline bool IsVertical() const
775 {
776 return this->is_vertical;
777 }
778
783 void SetStepSize(size_t stepsize)
784 {
785 assert(stepsize > 0);
786
787 this->stepsize = ClampTo<size_type>(stepsize);
788 }
789
795 void SetCount(size_t num)
796 {
797 assert(num < Scrollbar::max_size_type);
798
799 this->count = ClampTo<size_type>(num);
800 /* Ensure position is within bounds */
801 this->SetPosition(this->pos);
802 }
803
809 void SetCapacity(size_t capacity)
810 {
811 assert(capacity < Scrollbar::max_size_type);
812
813 this->cap = ClampTo<size_type>(capacity);
814 /* Ensure position is within bounds */
815 this->SetPosition(this->pos);
816 }
817
818 void SetCapacityFromWidget(Window *w, WidgetID widget, int padding = 0);
819
825 bool SetPosition(size_type position)
826 {
827 size_type old_pos = this->pos;
828 this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
829 return this->pos != old_pos;
830 }
831
839 bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
840 {
841 if (difference == 0) return false;
842 switch (unit) {
843 case SS_SMALL: difference *= this->stepsize; break;
844 case SS_BIG: difference *= this->cap; break;
845 default: break;
846 }
847 return this->SetPosition(this->pos + difference);
848 }
849
856 void ScrollTowards(size_type position)
857 {
858 if (position < this->GetPosition()) {
859 /* scroll up to the item */
860 this->SetPosition(position);
861 } else if (position >= this->GetPosition() + this->GetCapacity()) {
862 /* scroll down so that the item is at the bottom */
863 this->SetPosition(position - this->GetCapacity() + 1);
864 }
865 }
866
867 size_type GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
868
874 template <typename Tcontainer>
875 auto GetVisibleRangeIterators(Tcontainer &container) const
876 {
877 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
878 auto first = std::next(std::begin(container), this->GetPosition());
879 auto last = std::next(first, std::min<size_t>(this->GetCapacity(), this->GetCount() - this->GetPosition()));
880 return std::make_pair(first, last);
881 }
882
893 template <typename Tcontainer>
894 auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
895 {
896 assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
897 size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
898 if (row == Scrollbar::npos) return std::end(container);
899
900 return std::next(std::begin(container), row);
901 }
902
903 EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
904};
905
911 class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
912public:
913 NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index);
914
915 void SetupSmallestSize(Window *w) override;
916 void Draw(const Window *w) override;
917
918 static void InvalidateDimensionCache();
919 static Dimension GetVerticalDimension();
920 static Dimension GetHorizontalDimension();
921
922private:
923 static Dimension vertical_dimension;
924 static Dimension horizontal_dimension;
925};
926
931 class NWidgetLeaf : public NWidgetCore {
932public:
933 NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, const WidgetData &data, StringID tip);
934
935 void SetupSmallestSize(Window *w) override;
936 void Draw(const Window *w) override;
937
938 bool ButtonHit(const Point &pt);
939
940 static void InvalidateDimensionCache();
941
942 static Dimension dropdown_dimension;
943 static Dimension resizebox_dimension;
944 static Dimension closebox_dimension;
945private:
946 static Dimension shadebox_dimension;
947 static Dimension debugbox_dimension;
948 static Dimension defsizebox_dimension;
949 static Dimension stickybox_dimension;
950};
951
959 inline uint ComputeMaxSize(uint base, uint max_space, uint step)
960{
961 if (base >= max_space || step == 0) return base;
962 if (step == 1) return max_space;
963 uint increment = max_space - base;
964 increment -= increment % step;
965 return base + increment;
966}
967
1021 struct NWidgetPartDataTip {
1022 WidgetData data;
1023 StringID tooltip;
1024};
1025
1030 struct NWidgetPartWidget {
1031 Colours colour;
1032 WidgetID index;
1033};
1034
1035 struct NWidgetPartContainer {
1036 NWidContainerFlags flags;
1037 WidgetID index;
1038};
1039
1044 struct NWidgetPartPaddings : RectPadding {
1045};
1046
1051 struct NWidgetPartPIP {
1052 uint8_t pre, inter, post;
1053};
1054
1059 struct NWidgetPartTextLines {
1060 uint8_t lines;
1061 uint8_t spacing;
1062 FontSize size;
1063};
1064
1069 struct NWidgetPartTextStyle {
1070 TextColour colour;
1071 FontSize size;
1072};
1073
1078 struct NWidgetPartAlignment {
1079 StringAlignment align;
1080};
1081
1082 struct NWidgetPartAspect {
1083 float ratio;
1084 AspectFlags flags;
1085};
1086
1091 using NWidgetFunctionType = std::unique_ptr<NWidgetBase>();
1092
1097 struct NWidgetPart {
1098 WidgetType type;
1099 union NWidgetPartUnion {
1100 Point xy;
1101 NWidgetPartDataTip data_tip;
1102 NWidgetPartWidget widget;
1103 NWidgetPartPaddings padding;
1104 NWidgetPartPIP pip;
1105 NWidgetPartTextLines text_lines;
1106 NWidgetPartTextStyle text_style;
1107 NWidgetPartAlignment align;
1108 NWidgetFunctionType *func_ptr;
1109 NWidgetPartContainer container;
1110 NWidgetPartAspect aspect;
1111
1112 /* Constructors for each NWidgetPartUnion data type. */
1113 constexpr NWidgetPartUnion() : xy() {}
1114 constexpr NWidgetPartUnion(Point xy) : xy(xy) {}
1115 constexpr NWidgetPartUnion(NWidgetPartDataTip data_tip) : data_tip(data_tip) {}
1116 constexpr NWidgetPartUnion(NWidgetPartWidget widget) : widget(widget) {}
1117 constexpr NWidgetPartUnion(NWidgetPartPaddings padding) : padding(padding) {}
1118 constexpr NWidgetPartUnion(NWidgetPartPIP pip) : pip(pip) {}
1119 constexpr NWidgetPartUnion(NWidgetPartTextLines text_lines) : text_lines(text_lines) {}
1120 constexpr NWidgetPartUnion(NWidgetPartTextStyle text_style) : text_style(text_style) {}
1121 constexpr NWidgetPartUnion(NWidgetPartAlignment align) : align(align) {}
1122 constexpr NWidgetPartUnion(NWidgetFunctionType *func_ptr) : func_ptr(func_ptr) {}
1123 constexpr NWidgetPartUnion(NWidgetPartContainer container) : container(container) {}
1124 constexpr NWidgetPartUnion(NWidgetPartAspect aspect) : aspect(aspect) {}
1125 } u;
1126
1127 /* Constructors for each NWidgetPart data type. */
1128 explicit constexpr NWidgetPart(WidgetType type) : type(type), u() {}
1129 constexpr NWidgetPart(WidgetType type, Point xy) : type(type), u(xy) {}
1130 constexpr NWidgetPart(WidgetType type, NWidgetPartDataTip data_tip) : type(type), u(data_tip) {}
1131 constexpr NWidgetPart(WidgetType type, NWidgetPartWidget widget) : type(type), u(widget) {}
1132 constexpr NWidgetPart(WidgetType type, NWidgetPartPaddings padding) : type(type), u(padding) {}
1133 constexpr NWidgetPart(WidgetType type, NWidgetPartPIP pip) : type(type), u(pip) {}
1134 constexpr NWidgetPart(WidgetType type, NWidgetPartTextLines text_lines) : type(type), u(text_lines) {}
1135 constexpr NWidgetPart(WidgetType type, NWidgetPartTextStyle text_style) : type(type), u(text_style) {}
1136 constexpr NWidgetPart(WidgetType type, NWidgetPartAlignment align) : type(type), u(align) {}
1137 constexpr NWidgetPart(WidgetType type, NWidgetFunctionType *func_ptr) : type(type), u(func_ptr) {}
1138 constexpr NWidgetPart(WidgetType type, NWidgetPartContainer container) : type(type), u(container) {}
1139 constexpr NWidgetPart(WidgetType type, NWidgetPartAspect aspect) : type(type), u(aspect) {}
1140};
1141
1148 constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
1149{
1150 return NWidgetPart{WPT_RESIZE, Point{dx, dy}};
1151}
1152
1159 constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
1160{
1161 return NWidgetPart{WPT_MINSIZE, Point{x, y}};
1162}
1163
1168 constexpr NWidgetPart SetToolbarSpacerMinimalSize()
1169{
1170 return NWidgetPart{WPT_MINSIZE, Point{4, 0}};
1171}
1172
1178 constexpr NWidgetPart SetToolbarMinimalSize(int width)
1179{
1180 return NWidgetPart{WPT_TOOLBARSIZE, Point{width, 1}};
1181}
1182
1190 constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size = FS_NORMAL)
1191{
1192 return NWidgetPart{WPT_MINTEXTLINES, NWidgetPartTextLines{lines, spacing, size}};
1193}
1194
1201 constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size = FS_NORMAL)
1202{
1203 return NWidgetPart{WPT_TEXTSTYLE, NWidgetPartTextStyle{colour, size}};
1204}
1205
1211 constexpr NWidgetPart SetAlignment(StringAlignment align)
1212{
1213 return NWidgetPart{WPT_ALIGNMENT, NWidgetPartAlignment{align}};
1214}
1215
1222 constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
1223{
1224 return NWidgetPart{WPT_FILL, Point{fill_x, fill_y}};
1225}
1226
1232 constexpr NWidgetPart EndContainer()
1233{
1234 return NWidgetPart{WPT_ENDCONTAINER};
1235}
1236
1243 constexpr NWidgetPart SetStringTip(StringID string, StringID tip = {})
1244{
1245 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string}, tip}};
1246}
1247
1254 constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip = {})
1255{
1256 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.sprite = sprite}, tip}};
1257}
1258
1266 constexpr NWidgetPart SetSpriteStringTip(SpriteID sprite, StringID string, StringID tip = {})
1267{
1268 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.string = string, .sprite = sprite}, tip}};
1269}
1270
1277 constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip = {})
1278{
1279 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.arrow_widget_type = widget_type}, tip}};
1280}
1281
1288 constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
1289{
1290 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.resize_widget_type = widget_type}, tip}};
1291}
1292
1299 constexpr NWidgetPart SetAlternateColourTip(Colours colour, StringID tip)
1300{
1301 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.alternate_colour = colour}, tip}};
1302}
1303
1311 constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip = {})
1312{
1313 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{.matrix{ cols, rows }}, tip}};
1314}
1315
1321 constexpr NWidgetPart SetToolTip(StringID tip)
1322{
1323 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{{}, tip}};
1324}
1325
1335 constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
1336{
1337 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{left, top, right, bottom}};
1338}
1339
1346 constexpr NWidgetPart SetPadding(uint8_t horizontal, uint8_t vertical)
1347{
1348 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{horizontal, vertical, horizontal, vertical}};
1349}
1350
1356 constexpr NWidgetPart SetPadding(const RectPadding &padding)
1357{
1358 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{padding}};
1359}
1360
1366 constexpr NWidgetPart SetPadding(uint8_t padding)
1367{
1368 return SetPadding(padding, padding, padding, padding);
1369}
1370
1378 constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
1379{
1380 return NWidgetPart{WPT_PIPSPACE, NWidgetPartPIP{pre, inter, post}};
1381}
1382
1390 constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
1391{
1392 return NWidgetPart{WPT_PIPRATIO, NWidgetPartPIP{ratio_pre, ratio_inter, ratio_post}};
1393}
1394
1402 constexpr NWidgetPart SetScrollbar(WidgetID index)
1403{
1404 return NWidgetPart{WPT_SCROLLBAR, NWidgetPartWidget{INVALID_COLOUR, index}};
1405}
1406
1413 constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlag::ResizeX)
1414{
1415 return NWidgetPart{WPT_ASPECT, NWidgetPartAspect{ratio, flags}};
1416}
1417
1427 constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx = INVALID_WIDGET)
1428{
1429 return NWidgetPart{tp, NWidgetPartWidget{col, idx}};
1430}
1431
1438 constexpr NWidgetPart NWidget(WidgetType tp, NWidContainerFlags cont_flags = {}, WidgetID idx = INVALID_WIDGET)
1439{
1440 return NWidgetPart{tp, NWidgetPartContainer{cont_flags, idx}};
1441}
1442
1448 constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
1449{
1450 return NWidgetPart{WPT_FUNCTION, func_ptr};
1451}
1452
1453bool IsContainerWidgetType(WidgetType tp);
1454std::unique_ptr<NWidgetBase> MakeNWidgets(std::span<const NWidgetPart> nwid_parts, std::unique_ptr<NWidgetBase> &&container);
1455std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(std::span<const NWidgetPart> nwid_parts, NWidgetStacked **shade_select);
1456
1457std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
1458
1459void SetupWidgetDimensions();
1460
1461#endif /* WIDGET_TYPE_H */
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
EnumBitSet< AspectFlag, uint8_t >
NWidgetBackground
Nested widget with a child.
Definition widget_type.h:666
NWidgetBackground::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2365
NWidgetBackground::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:2375
NWidgetBackground::AssignSizePosition
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:2311
NWidgetBackground::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2242
NWidgetBackground::SetPIP
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:2208
NWidgetBackground::child
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
Definition widget_type.h:685
NWidgetBackground::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2329
NWidgetBackground::Add
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition widget.cpp:2189
NWidgetBackground::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:2323
NWidgetBackground::SetPIPRatio
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:2227
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:137
NWidgetBase::StoreSizePosition
void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
Store size and position.
Definition widget_type.h:283
NWidgetBase::aspect_ratio
float aspect_ratio
Desired aspect ratio of widget.
Definition widget_type.h:240
NWidgetBase::GetHorizontalStepSize
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
Definition widget_type.h:261
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w)=0
Compute smallest size needed by the widget.
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:949
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition widget_type.h:227
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition widget_type.h:230
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition widget_type.h:228
NWidgetBase::GetParentWidget
NWID * GetParentWidget()
Get parent widget of type NWID.
Definition widget_type.h:158
NWidgetBase::parent
NWidgetBase * parent
Parent widget of this widget, automatically filled in when added to container.
Definition widget_type.h:249
NWidgetBase::uz_padding
RectPadding uz_padding
Unscaled padding, for resize calculation.
Definition widget_type.h:247
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition widget_type.h:235
NWidgetBase::aspect_flags
AspectFlags aspect_flags
Which dimensions can be resized.
Definition widget_type.h:241
NWidgetBase::Draw
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition widget_type.h:238
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition widget_type.h:244
NWidgetBase::GetWidgetFromPos
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
Retrieve a widget by its position.
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition widget_type.h:243
NWidgetBase::SetPadding
void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Set additional space (padding) around the widget.
Definition widget_type.h:192
NWidgetBase::SetPadding
void SetPadding(const RectPadding &padding)
Set additional space (padding) around the widget.
Definition widget_type.h:205
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition widget_type.h:236
NWidgetBase::AssignSizePosition
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.
NWidgetBase::index
const WidgetID index
Index of the nested widget (INVALID_WIDGET means 'not used').
Definition widget_type.h:252
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition widget.cpp:969
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition widget_type.h:229
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition widget_type.h:231
NWidgetBase::padding
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition widget_type.h:246
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition widget_type.h:239
NWidgetBase::FillWidgetLookup
virtual void FillWidgetLookup(WidgetLookup &widget_lookup)
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:933
NWidgetBase::GetVerticalStepSize
uint GetVerticalStepSize(SizingType sizing) const
Get the vertical sizing step.
Definition widget_type.h:270
NWidgetBase::GetParentWidget
const NWID * GetParentWidget() const
Get parent widget of type NWID.
Definition widget_type.h:172
NWidgetContainer
Baseclass for container widgets.
Definition widget_type.h:474
NWidgetContainer::Add
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition widget.cpp:1320
NWidgetContainer::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1327
NWidgetContainer::UnfocusWidgets
void UnfocusWidgets(Window *parent_window)
Unfocuses the focused widget of the window, if the focused widget is contained inside the container.
Definition widget.cpp:3521
NWidgetContainer::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1335
NWidgetContainer::IsEmpty
bool IsEmpty()
Return whether the container is empty.
Definition widget_type.h:486
NWidgetContainer::children
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in container.
Definition widget_type.h:502
NWidgetContainer::Clear
void Clear(Window *parent_window)
Clears the container, deleting all widgets that were contained.
Definition widget_type.h:495
NWidgetContainer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1344
NWidgetContainer::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition widget.cpp:1298
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetCore::widget_data
WidgetData widget_data
Data of the widget.
Definition widget_type.h:405
NWidgetCore::SetToolTip
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition widget.cpp:1252
NWidgetCore::IsHighlighted
bool IsHighlighted() const override
Return whether the widget is highlighted.
Definition widget_type.h:428
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition widget_type.h:464
NWidgetCore::SetSprite
void SetSprite(SpriteID sprite)
Set sprite of the nested widget.
Definition widget.cpp:1202
NWidgetCore::disp_flags
NWidgetDisplayFlags disp_flags
Flags that affect display and interaction with the widget.
Definition widget_type.h:402
NWidgetCore::SetTextStyle
void SetTextStyle(TextColour colour, FontSize size)
Set the text style of the nested widget.
Definition widget.cpp:1242
NWidgetCore::GetScrollbarIndex
WidgetID GetScrollbarIndex() const
Get the WidgetID of this nested widget's scrollbar.
Definition widget.cpp:1288
NWidgetCore::highlight_colour
TextColour highlight_colour
Colour of highlight.
Definition widget_type.h:408
NWidgetCore::SetAlignment
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition widget.cpp:1270
NWidgetCore::SetResizeWidgetType
void SetResizeWidgetType(ResizeWidgetValues type)
Set the resize widget type of the nested widget.
Definition widget.cpp:1232
NWidgetCore::SetSpriteTip
void SetSpriteTip(SpriteID sprite, StringID tool_tip)
Set sprite and tool tip of the nested widget.
Definition widget.cpp:1212
NWidgetCore::align
StringAlignment align
Alignment of text/image within widget.
Definition widget_type.h:411
NWidgetCore::text_size
FontSize text_size
Size of text within widget.
Definition widget_type.h:410
NWidgetCore::SetHighlighted
void SetHighlighted(TextColour highlight_colour) override
Highlight the widget or not.
Definition widget_type.h:421
NWidgetCore::GetString
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1279
NWidgetCore::scrollbar_index
WidgetID scrollbar_index
Index of an attached scrollbar.
Definition widget_type.h:407
NWidgetCore::GetToolTip
StringID GetToolTip() const
Get the tool tip of the nested widget.
Definition widget.cpp:1261
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1293
NWidgetCore::SetString
void SetString(StringID string)
Set string of the nested widget.
Definition widget.cpp:1182
NWidgetCore::text_colour
TextColour text_colour
Colour of text within widget.
Definition widget_type.h:409
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition widget_type.h:403
NWidgetCore::SetMatrixDimension
void SetMatrixDimension(uint32_t columns, uint32_t rows)
Set the matrix dimension.
Definition widget.cpp:1223
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition widget_type.h:443
NWidgetCore::GetHighlightColour
TextColour GetHighlightColour() const override
Return the colour of the highlight.
Definition widget_type.h:434
NWidgetCore::SetStringTip
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1192
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition widget_type.h:406
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition widget_type.h:458
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition widget_type.h:449
NWidgetHorizontalLTR
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition widget_type.h:590
NWidgetHorizontalLTR::AssignSizePosition
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:1741
NWidgetHorizontal
Horizontal container.
Definition widget_type.h:578
NWidgetHorizontal::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1563
NWidgetHorizontal::AssignSizePosition
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:1632
NWidgetLeaf
Leaf widget.
Definition widget_type.h:931
NWidgetLeaf::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2993
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition widget.cpp:2670
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition widget_type.h:2685
NWidgetLeaf::shadebox_dimension
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition widget_type.h:2681
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition widget_type.h:2686
NWidgetLeaf::stickybox_dimension
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition widget_type.h:2684
NWidgetLeaf::defsizebox_dimension
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition widget_type.h:2683
NWidgetLeaf::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2806
NWidgetLeaf::dropdown_dimension
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition widget_type.h:2687
NWidgetLeaf::debugbox_dimension
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition widget_type.h:2682
NWidgetLeaf::ButtonHit
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:3137
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition widget_type.h:617
NWidgetMatrix::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2088
NWidgetMatrix::count
int count
Amount of valid elements.
Definition widget_type.h:634
NWidgetMatrix::SetClicked
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition widget.cpp:1957
NWidgetMatrix::GetCurrentElement
int GetCurrentElement() const
Get current element.
Definition widget.cpp:2007
NWidgetMatrix::sb
Scrollbar * sb
The scrollbar we're associated with.
Definition widget_type.h:636
NWidgetMatrix::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2012
NWidgetMatrix::widget_w
int widget_w
The width of the child widget including inter spacing.
Definition widget_type.h:638
NWidgetMatrix::SetScrollbar
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition widget.cpp:1998
NWidgetMatrix::GetScrollOffsets
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:2143
NWidgetMatrix::current_element
int current_element
The element currently being processed.
Definition widget_type.h:635
NWidgetMatrix::widgets_x
int widgets_x
The number of visible widgets in horizontal direction.
Definition widget_type.h:640
NWidgetMatrix::widget_h
int widget_h
The height of the child widget including inter spacing.
Definition widget_type.h:639
NWidgetMatrix::AssignSizePosition
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:2034
NWidgetMatrix::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:2058
NWidgetMatrix::clicked
int clicked
The currently clicked element.
Definition widget_type.h:633
NWidgetMatrix::SetCount
void SetCount(int count)
Set the number of elements in this matrix.
Definition widget.cpp:1974
NWidgetMatrix::widgets_y
int widgets_y
The number of visible widgets in vertical direction.
Definition widget_type.h:641
NWidgetMatrix::colour
Colours colour
Colour of this widget.
Definition widget_type.h:632
NWidgetPIPContainer
Container with pre/inter/post child space.
Definition widget_type.h:550
NWidgetPIPContainer::gaps
uint8_t gaps
Number of gaps between widgets.
Definition widget_type.h:571
NWidgetPIPContainer::flags
NWidContainerFlags flags
Flags of the container.
Definition widget_type.h:559
NWidgetPIPContainer::pip_pre
uint8_t pip_pre
Amount of space before first widget.
Definition widget_type.h:560
NWidgetPIPContainer::uz_pip_pre
uint8_t uz_pip_pre
Unscaled space before first widget.
Definition widget_type.h:567
NWidgetPIPContainer::SetPIPRatio
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post)
Set additional pre/inter/post space for the container.
Definition widget.cpp:1556
NWidgetPIPContainer::uz_pip_inter
uint8_t uz_pip_inter
Unscaled space between widgets.
Definition widget_type.h:568
NWidgetPIPContainer::pip_ratio_pre
uint8_t pip_ratio_pre
Ratio of remaining space before first widget.
Definition widget_type.h:563
NWidgetPIPContainer::SetPIP
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:1536
NWidgetPIPContainer::pip_post
uint8_t pip_post
Amount of space after last widget.
Definition widget_type.h:562
NWidgetPIPContainer::pip_ratio_inter
uint8_t pip_ratio_inter
Ratio of remaining space between widgets.
Definition widget_type.h:564
NWidgetPIPContainer::pip_ratio_post
uint8_t pip_ratio_post
Ratio of remaining space after last widget.
Definition widget_type.h:565
NWidgetPIPContainer::uz_pip_post
uint8_t uz_pip_post
Unscaled space after last widget.
Definition widget_type.h:569
NWidgetPIPContainer::pip_inter
uint8_t pip_inter
Amount of space between widgets.
Definition widget_type.h:561
NWidgetResizeBase
Base class for a resizable nested widget.
Definition widget_type.h:300
NWidgetResizeBase::uz_text_spacing
uint8_t uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition widget_type.h:328
NWidgetResizeBase::absolute
bool absolute
Set if minimum size is fixed and should not be resized.
Definition widget_type.h:323
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition widget.cpp:1045
NWidgetResizeBase::UpdateSize
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1134
NWidgetResizeBase::min_x
uint min_x
Minimal horizontal size of only this widget.
Definition widget_type.h:320
NWidgetResizeBase::uz_text_size
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
Definition widget_type.h:329
NWidgetResizeBase::uz_min_x
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition widget_type.h:324
NWidgetResizeBase::uz_text_lines
uint8_t uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition widget_type.h:327
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition widget.cpp:1090
NWidgetResizeBase::SetToolbarMinimalSize
void SetToolbarMinimalSize(uint8_t toolbar_size)
Set minimal size of the widget in toolbar-icon-relative width.
Definition widget.cpp:1055
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition widget.cpp:1078
NWidgetResizeBase::min_y
uint min_y
Minimal vertical size of only this widget.
Definition widget_type.h:321
NWidgetResizeBase::uz_min_y
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition widget_type.h:325
NWidgetResizeBase::UpdateMultilineWidgetSize
bool UpdateMultilineWidgetSize(const std::string &str, int max_lines)
Try to set optimum widget size for a multiline text widget.
Definition widget.cpp:1114
NWidgetResizeBase::AssignSizePosition
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:1155
NWidgetResizeBase::UpdateVerticalSize
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1148
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition widget.cpp:1101
NWidgetResizeBase::toolbar_size
uint8_t toolbar_size
Minimal size in terms of toolbar images.
Definition widget_type.h:330
NWidgetResizeBase::SetAspect
void SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Set desired aspect ratio of this widget.
Definition widget.cpp:1010
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1065
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition widget_type.h:911
NWidgetScrollbar::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2614
NWidgetScrollbar::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2593
NWidgetScrollbar::horizontal_dimension
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition widget_type.h:2667
NWidgetScrollbar::vertical_dimension
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition widget_type.h:2666
NWidgetSpacer
Spacer widget.
Definition widget_type.h:651
NWidgetSpacer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1948
NWidgetSpacer::SetDirty
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:1943
NWidgetSpacer::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1931
NWidgetSpacer::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1924
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition widget_type.h:524
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition widget_type.h:537
NWidgetStacked::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1355
NWidgetStacked::widget_lookup
WidgetLookup * widget_lookup
Window's widget lookup, updated in SetDisplayedPlane().
Definition widget_type.h:539
NWidgetStacked::AssignSizePosition
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:1396
NWidgetStacked::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1426
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1450
NWidgetStacked::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition widget.cpp:1416
NWidgetStacked::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition widget.cpp:1435
NWidgetVertical
Vertical container.
Definition widget_type.h:601
NWidgetVertical::AssignSizePosition
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:1815
NWidgetVertical::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1746
NWidgetViewport
Nested widget to display a viewport in a window.
Definition widget_type.h:697
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2430
NWidgetViewport::Draw
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:2394
NWidgetViewport::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:2387
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2421
Scrollbar
Scrollbar data structure.
Definition widget_type.h:711
Scrollbar::IsVisible
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
Definition widget_type.h:765
Scrollbar::is_vertical
const bool is_vertical
Scrollbar has vertical orientation.
Definition widget_type.h:717
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition widget_type.h:746
Scrollbar::stepsize
size_type stepsize
Distance to scroll, when pressing the buttons or using the wheel.
Definition widget_type.h:721
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:795
Scrollbar::IsVertical
bool IsVertical() const
Is the scrollbar vertical or not?
Definition widget_type.h:774
Scrollbar::GetScrolledItemFromWidget
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.
Definition widget_type.h:894
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition widget_type.h:839
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition widget_type.h:809
Scrollbar::cap
size_type cap
Number of visible elements of the scroll bar.
Definition widget_type.h:719
Scrollbar::GetScrolledRowFromWidget
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:2453
Scrollbar::count
size_type count
Number of elements in the list.
Definition widget_type.h:718
Scrollbar::SetPosition
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition widget_type.h:825
Scrollbar::SetCapacityFromWidget
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:2527
Scrollbar::GetCount
size_type GetCount() const
Gets the number of elements in the list.
Definition widget_type.h:737
Scrollbar::UpdateListPositionOnKeyPress
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:2474
Scrollbar::ScrollTowards
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition widget_type.h:856
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:875
Scrollbar::SetStepSize
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition widget_type.h:783
Scrollbar::pos
size_type pos
Index of first visible item of the list.
Definition widget_type.h:720
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:755
Scrollbar::ScrollbarStepping
ScrollbarStepping
Stepping sizes when scrolling.
Definition widget_type.h:725
Scrollbar::SS_BIG
@ SS_BIG
Step in cap units.
Definition widget_type.h:728
Scrollbar::SS_RAW
@ SS_RAW
Step in single units.
Definition widget_type.h:726
Scrollbar::SS_SMALL
@ SS_SMALL
Step in stepsize units.
Definition widget_type.h:727
gfx_type.h
Types related to the graphics and/or input devices.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
FontSize
FontSize
Available font sizes.
Definition gfx_type.h:248
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition gfx_type.h:387
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1311
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1448
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1222
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1254
SetToolbarMinimalSize
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
Definition widget_type.h:1178
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1378
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1402
SetPadding
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.
Definition widget_type.h:1335
SetAlternateColourTip
constexpr NWidgetPart SetAlternateColourTip(Colours colour, StringID tip)
Widget part function for setting the alternate colour and tooltip.
Definition widget_type.h:1299
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1243
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1413
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1201
MakeWindowNWidgetTree
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:3429
SetToolbarSpacerMinimalSize
constexpr NWidgetPart SetToolbarSpacerMinimalSize()
Widget part function to setting the minimal size for a toolbar spacer.
Definition widget_type.h:1168
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1159
SetResizeWidgetTypeTip
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
Definition widget_type.h:1288
MakeNWidgets
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:3410
SetSpriteStringTip
constexpr NWidgetPart SetSpriteStringTip(SpriteID sprite, StringID string, StringID tip={})
Widget part function for setting the sprite, string and tooltip.
Definition widget_type.h:1266
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1321
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1232
SetArrowWidgetTypeTip
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
Definition widget_type.h:1277
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1427
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1190
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1211
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1148
SetPIPRatio
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.
Definition widget_type.h:1390
math_func.hpp
Integer math functions.
IsInsideBS
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.
Definition math_func.hpp:252
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
strings_type.h
Types related to strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
NWidgetPartAlignment
Widget part for setting text/image alignment within a widget.
Definition widget_type.h:1078
NWidgetPartAlignment::align
StringAlignment align
Alignment of text/image.
Definition widget_type.h:1079
NWidgetPartAspect
Definition widget_type.h:1082
NWidgetPartContainer
Definition widget_type.h:1035
NWidgetPartDataTip
Widget part for storing data and tooltip information.
Definition widget_type.h:1021
NWidgetPartDataTip::data
WidgetData data
Data value of the widget.
Definition widget_type.h:1022
NWidgetPartDataTip::tooltip
StringID tooltip
Tooltip of the widget.
Definition widget_type.h:1023
NWidgetPartPIP
Widget part for storing pre/inter/post spaces.
Definition widget_type.h:1051
NWidgetPartPIP::post
uint8_t post
Amount of space before/between/after child widgets.
Definition widget_type.h:1052
NWidgetPartPaddings
Widget part for storing padding.
Definition widget_type.h:1044
NWidgetPartTextLines
Widget part for storing minimal text line data.
Definition widget_type.h:1059
NWidgetPartTextLines::lines
uint8_t lines
Number of text lines.
Definition widget_type.h:1060
NWidgetPartTextLines::spacing
uint8_t spacing
Extra spacing around lines.
Definition widget_type.h:1061
NWidgetPartTextLines::size
FontSize size
Font size of text lines.
Definition widget_type.h:1062
NWidgetPartTextStyle
Widget part for storing text colour.
Definition widget_type.h:1069
NWidgetPartTextStyle::colour
TextColour colour
TextColour for DrawString.
Definition widget_type.h:1070
NWidgetPartTextStyle::size
FontSize size
Font size of text.
Definition widget_type.h:1071
NWidgetPartWidget
Widget part for storing basic widget information.
Definition widget_type.h:1030
NWidgetPartWidget::colour
Colours colour
Widget colour.
Definition widget_type.h:1031
NWidgetPartWidget::index
WidgetID index
Index of the widget.
Definition widget_type.h:1032
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1097
NWidgetPart::type
WidgetType type
Type of the part.
Definition widget_type.h:1098
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition geometry_type.hpp:77
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
WidgetData
Container with the data associated to a single widget.
Definition widget_type.h:358
Window
Data structure for an opened window.
Definition window_gui.h:274
NWidgetPart::NWidgetPartUnion
Definition widget_type.h:1099
NWidgetPart::NWidgetPartUnion::container
NWidgetPartContainer container
Part with container flags.
Definition widget_type.h:1109
NWidgetPart::NWidgetPartUnion::text_lines
NWidgetPartTextLines text_lines
Part with text line data.
Definition widget_type.h:1105
NWidgetPart::NWidgetPartUnion::pip
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition widget_type.h:1104
NWidgetPart::NWidgetPartUnion::padding
NWidgetPartPaddings padding
Part with paddings.
Definition widget_type.h:1103
NWidgetPart::NWidgetPartUnion::func_ptr
NWidgetFunctionType * func_ptr
Part with a function call.
Definition widget_type.h:1108
NWidgetPart::NWidgetPartUnion::data_tip
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition widget_type.h:1101
NWidgetPart::NWidgetPartUnion::align
NWidgetPartAlignment align
Part with internal alignment.
Definition widget_type.h:1107
NWidgetPart::NWidgetPartUnion::aspect
NWidgetPartAspect aspect
Part to set aspect ratio.
Definition widget_type.h:1110
NWidgetPart::NWidgetPartUnion::text_style
NWidgetPartTextStyle text_style
Part with text style data.
Definition widget_type.h:1106
NWidgetPart::NWidgetPartUnion::xy
Point xy
Part with an x/y size.
Definition widget_type.h:1100
NWidgetPart::NWidgetPartUnion::widget
NWidgetPartWidget widget
Part with a start of a widget.
Definition widget_type.h:1102
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:35
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:105
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:40
WPT_FILL
@ WPT_FILL
Widget part for specifying fill.
Definition widget_type.h:84
WWT_PUSHIMGTEXTBTN
@ WWT_PUSHIMGTEXTBTN
Normal push-button (no toggle button) with image and text caption.
Definition widget_type.h:108
WPT_ALIGNMENT
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition widget_type.h:90
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition widget_type.h:104
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:42
NWID_CUSTOM
@ NWID_CUSTOM
General Custom widget.
Definition widget_type.h:77
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:106
WPT_MINSIZE
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition widget_type.h:82
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition widget_type.h:107
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:74
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
WWT_ARROWBTN
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition widget_type.h:43
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WPT_SCROLLBAR
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition widget_type.h:91
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WPT_ASPECT
@ WPT_ASPECT
Widget part for specifying aspect ratio.
Definition widget_type.h:92
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WPT_RESIZE
@ WPT_RESIZE
Widget part for specifying resizing.
Definition widget_type.h:81
WWT_IMGTEXTBTN
@ WWT_IMGTEXTBTN
(Toggle) Button with image and text
Definition widget_type.h:47
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WPT_TOOLBARSIZE
@ WPT_TOOLBARSIZE
Widget part for specifying minimal size in terms of toolbar images.
Definition widget_type.h:93
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
WPT_TEXTSTYLE
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition widget_type.h:89
WPT_PADDING
@ WPT_PADDING
Widget part for specifying a padding.
Definition widget_type.h:86
WWT_BOOLBTN
@ WWT_BOOLBTN
Standard boolean toggle button.
Definition widget_type.h:46
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition widget_type.h:45
WWT_FRAME
@ WWT_FRAME
Frame.
Definition widget_type.h:51
WPT_MINTEXTLINES
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition widget_type.h:83
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition widget_type.h:63
WPT_ATTRIBUTE_END
@ WPT_ATTRIBUTE_END
End marker for attribute NWidgetPart types.
Definition widget_type.h:94
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition widget_type.h:75
WPT_ENDCONTAINER
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition widget_type.h:97
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WPT_PIPRATIO
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition widget_type.h:88
WPT_DATATIP
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition widget_type.h:85
WWT_DEFSIZEBOX
@ 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
@ WPT_ATTRIBUTE_BEGIN
Begin marker for attribute NWidgetPart types.
Definition widget_type.h:80
WPT_PIPSPACE
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition widget_type.h:87
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition widget_type.h:69
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:73
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
NWID_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
WPT_FUNCTION
@ WPT_FUNCTION
Widget part for calling a user function.
Definition widget_type.h:96
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition widget_type.h:54
NWID_LAYER
@ NWID_LAYER
Layered widgets, all visible together.
Definition widget_type.h:72
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
NWidgetDisplayFlag
NWidgetDisplayFlag
Nested widget flags that affect display and interaction with 'real' widgets.
Definition widget_type.h:334
DropdownClosed
@ DropdownClosed
Dropdown menu of the dropdown widget has closed.
Definition widget_type.h:353
ScrollbarDown
@ ScrollbarDown
Down-button is lowered bit.
Definition widget_type.h:349
Lowered
@ Lowered
Widget is lowered (pressed down) bit.
Definition widget_type.h:336
ShadeDimmed
@ ShadeDimmed
Display dimmed colours in the viewport.
Definition widget_type.h:342
ShadeGrey
@ ShadeGrey
Shade viewport to grey-scale.
Definition widget_type.h:341
ScrollbarUp
@ ScrollbarUp
Up-button is lowered bit.
Definition widget_type.h:348
DropdownActive
@ DropdownActive
Dropdown menu of the button dropdown widget is active.
Definition widget_type.h:345
Highlight
@ Highlight
Highlight of widget is on.
Definition widget_type.h:352
NoTransparency
@ NoTransparency
Viewport is never transparent.
Definition widget_type.h:340
Disabled
@ Disabled
Widget is disabled (greyed out) bit.
Definition widget_type.h:337
ComputeMaxSize
uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition widget_type.h:959
IsContainerWidgetType
bool IsContainerWidgetType(WidgetType tp)
Test if WidgetType is a container widget.
Definition widget.cpp:3353
StackedZeroSizePlanes
StackedZeroSizePlanes
Display planes with zero size for NWidgetStacked.
Definition widget_type.h:506
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:508
SZSP_BEGIN
@ SZSP_BEGIN
First zero-size plane.
Definition widget_type.h:511
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition widget_type.h:507
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition widget_type.h:509
NWidContainerFlag
NWidContainerFlag
Nested widget container flags,.
Definition widget_type.h:543
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:544
BigFirst
@ BigFirst
Allocate space to biggest resize first.
Definition widget_type.h:545
NWidgetFunctionType
std::unique_ptr< NWidgetBase >() NWidgetFunctionType
Pointer to function returning a nested widget.
Definition widget_type.h:1091
MakeCompanyButtonRows
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:3471
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition widget.cpp:96
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition widget_type.h:113
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition widget_type.h:115
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition widget_type.h:114
ArrowWidgetValues
ArrowWidgetValues
Values for an arrow widget.
Definition widget_type.h:19
AWV_LEFT
@ AWV_LEFT
Force the arrow to the left.
Definition widget_type.h:22
AWV_RIGHT
@ AWV_RIGHT
Force the arrow to the right.
Definition widget_type.h:23
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
WidgetLookup
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition widget_type.h:129
ResizeWidgetValues
ResizeWidgetValues
WidgetData values for a resize box widget.
Definition widget_type.h:27
RWV_SHOW_BEVEL
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition widget_type.h:28
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:29
window_type.h
Types related to windows.
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
INVALID_WIDGET
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:23
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20