OpenTTD Source: src/widget_type.h Source File

OpenTTD Source 14.0-RC3

widget_type.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef WIDGET_TYPE_H
11 #define WIDGET_TYPE_H
12
13 #include "core/alloc_type.hpp"
14 #include "core/bitmath_func.hpp"
15 #include "core/math_func.hpp"
16 #include "strings_type.h"
17 #include "gfx_type.h"
18 #include "window_type.h"
19
21 enum MatrixWidgetValues {
22 /* Number of column bits of the WWT_MATRIX widget data. */
23 MAT_COL_START = 0,
24 MAT_COL_BITS = 8,
25
26 /* Number of row bits of the WWT_MATRIX widget data. */
27 MAT_ROW_START = 8,
28 MAT_ROW_BITS = 8,
29 };
30
32 enum ArrowWidgetValues {
33 AWV_DECREASE,
34 AWV_INCREASE,
35 AWV_LEFT,
36 AWV_RIGHT,
37 };
38
40 enum ResizeWidgetValues {
41 RWV_SHOW_BEVEL,
42 RWV_HIDE_BEVEL,
43 };
44
48 enum WidgetType {
49 /* Window widget types. */
50 WWT_EMPTY,
51
52 WWT_PANEL,
53 WWT_INSET,
54 WWT_IMGBTN,
55 WWT_IMGBTN_2,
56 WWT_ARROWBTN,
57 WWT_TEXTBTN,
58 WWT_TEXTBTN_2,
59 WWT_LABEL,
60 WWT_TEXT,
61 WWT_MATRIX,
62 WWT_FRAME,
63 WWT_CAPTION,
64
65 WWT_DEBUGBOX,
66 WWT_SHADEBOX,
67 WWT_DEFSIZEBOX,
68 WWT_STICKYBOX,
69
70 WWT_RESIZEBOX,
71 WWT_CLOSEBOX,
72 WWT_DROPDOWN,
73 WWT_EDITBOX,
74 WWT_LAST,
75
76 /* Nested widget types. */
77 NWID_HORIZONTAL,
78 NWID_HORIZONTAL_LTR,
79 NWID_VERTICAL,
80 NWID_MATRIX,
81 NWID_SPACER,
82 NWID_SELECTION,
83 NWID_VIEWPORT,
84 NWID_BUTTON_DROPDOWN,
85 NWID_HSCROLLBAR,
86 NWID_VSCROLLBAR,
87 NWID_CUSTOM,
88
89 /* Nested widget part types. */
90 WPT_RESIZE,
91 WPT_MINSIZE,
92 WPT_MINTEXTLINES,
93 WPT_FILL,
94 WPT_DATATIP,
95 WPT_PADDING,
96 WPT_PIPSPACE,
97 WPT_PIPRATIO,
98 WPT_TEXTSTYLE,
99 WPT_ALIGNMENT,
100 WPT_ENDCONTAINER,
101 WPT_FUNCTION,
102 WPT_SCROLLBAR,
103
104 /* Pushable window widget types. */
105 WWT_MASK = 0x7F,
106
107 WWB_PUSHBUTTON = 1 << 7,
108
109 WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON,
110 WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON,
111 WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON,
112 WWT_PUSHARROWBTN = WWT_ARROWBTN | WWB_PUSHBUTTON,
113 NWID_PUSHBUTTON_DROPDOWN = NWID_BUTTON_DROPDOWN | WWB_PUSHBUTTON,
114 };
115
117 enum SizingType {
118 ST_SMALLEST,
119 ST_RESIZE,
120 };
121
122 /* Forward declarations. */
123 class NWidgetCore;
124 class Scrollbar;
125
127 using WidgetLookup = std::map<WidgetID, class NWidgetBase *>;
128
135 class NWidgetBase : public ZeroedMemoryAllocator {
136 public:
137 NWidgetBase(WidgetType tp);
138
139 virtual void AdjustPaddingForZoom();
140 virtual void SetupSmallestSize(Window *w) = 0;
141 virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
142
143 virtual void FillWidgetLookup(WidgetLookup &widget_lookup) = 0;
144
145 virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
146 virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
147
153 template <class NWID>
154 NWID *GetParentWidget()
155 {
156 for (NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
157 if (NWID *nwid = dynamic_cast<NWID *>(nwid_parent); nwid != nullptr) return nwid;
158 }
159 return nullptr;
160 }
161
167 template <class NWID>
168 const NWID *GetParentWidget() const
169 {
170 for (const NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
171 if (const NWID *nwid = dynamic_cast<const NWID *>(nwid_parent); nwid != nullptr) return nwid;
172 }
173 return nullptr;
174 }
175
176 virtual bool IsHighlighted() const { return false; }
177 virtual TextColour GetHighlightColour() const { return TC_INVALID; }
178 virtual void SetHighlighted([[maybe_unused]] TextColour highlight_colour) {}
179
187 inline void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
188 {
189 this->uz_padding.top = top;
190 this->uz_padding.right = right;
191 this->uz_padding.bottom = bottom;
192 this->uz_padding.left = left;
193 this->AdjustPaddingForZoom();
194 }
195
200 inline void SetPadding(const RectPadding &padding)
201 {
202 this->uz_padding = padding;
203 this->AdjustPaddingForZoom();
204 }
205
206 inline uint GetHorizontalStepSize(SizingType sizing) const;
207 inline uint GetVerticalStepSize(SizingType sizing) const;
208
209 virtual void Draw(const Window *w) = 0;
210 virtual void SetDirty(const Window *w) const;
211
212 Rect GetCurrentRect() const
213 {
214 Rect r;
215 r.left = this->pos_x;
216 r.top = this->pos_y;
217 r.right = this->pos_x + this->current_x - 1;
218 r.bottom = this->pos_y + this->current_y - 1;
219 return r;
220 }
221
222 WidgetType type;
223 uint fill_x;
224 uint fill_y;
225 uint resize_x;
226 uint resize_y;
227 /* Size of the widget in the smallest window possible.
228 * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
229 */
230 uint smallest_x;
231 uint smallest_y;
232 /* Current widget size (that is, after resizing). */
233 uint current_x;
234 uint current_y;
235
236 int pos_x;
237 int pos_y;
238
239 RectPadding padding;
240 RectPadding uz_padding;
241
242 NWidgetBase *parent;
243
244 protected:
245 inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
246 };
247
252 inline uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
253 {
254 return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
255 }
256
261 inline uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
262 {
263 return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
264 }
265
274 inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
275 {
276 this->pos_x = x;
277 this->pos_y = y;
278 if (sizing == ST_SMALLEST) {
279 this->smallest_x = given_width;
280 this->smallest_y = given_height;
281 }
282 this->current_x = given_width;
283 this->current_y = given_height;
284 }
285
286
291 class NWidgetResizeBase : public NWidgetBase {
292 public:
293 NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
294
295 void AdjustPaddingForZoom() override;
296 void SetMinimalSize(uint min_x, uint min_y);
297 void SetMinimalSizeAbsolute(uint min_x, uint min_y);
298 void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size);
299 void SetFill(uint fill_x, uint fill_y);
300 void SetResize(uint resize_x, uint resize_y);
301
302 bool UpdateMultilineWidgetSize(const std::string &str, int max_lines);
303 bool UpdateSize(uint min_x, uint min_y);
304 bool UpdateVerticalSize(uint min_y);
305
306 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
307
308 uint min_x;
309 uint min_y;
310
311 bool absolute;
312 uint uz_min_x;
313 uint uz_min_y;
314
315 uint8_t uz_text_lines;
316 uint8_t uz_text_spacing;
317 FontSize uz_text_size;
318 };
319
321 enum NWidgetDisplay {
322 /* Generic. */
323 NDB_LOWERED = 0,
324 NDB_DISABLED = 1,
325 /* Viewport widget. */
326 NDB_NO_TRANSPARENCY = 2,
327 NDB_SHADE_GREY = 3,
328 NDB_SHADE_DIMMED = 4,
329 /* Button dropdown widget. */
330 NDB_DROPDOWN_ACTIVE = 5,
331 /* Scrollbar widget. */
332 NDB_SCROLLBAR_UP = 6,
333 NDB_SCROLLBAR_DOWN = 7,
334 /* Generic. */
335 NDB_HIGHLIGHT = 8,
336 NDB_DROPDOWN_CLOSED = 9,
337
338 ND_LOWERED = 1 << NDB_LOWERED,
339 ND_DISABLED = 1 << NDB_DISABLED,
340 ND_HIGHLIGHT = 1 << NDB_HIGHLIGHT,
341 ND_NO_TRANSPARENCY = 1 << NDB_NO_TRANSPARENCY,
342 ND_SHADE_GREY = 1 << NDB_SHADE_GREY,
343 ND_SHADE_DIMMED = 1 << NDB_SHADE_DIMMED,
344 ND_DROPDOWN_ACTIVE = 1 << NDB_DROPDOWN_ACTIVE,
345 ND_SCROLLBAR_UP = 1 << NDB_SCROLLBAR_UP,
346 ND_SCROLLBAR_DOWN = 1 << NDB_SCROLLBAR_DOWN,
347 ND_SCROLLBAR_BTN = ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN,
348 ND_DROPDOWN_CLOSED = 1 << NDB_DROPDOWN_CLOSED,
349 };
350 DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
351
352
356 class NWidgetCore : public NWidgetResizeBase {
357 public:
358 NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip);
359
360 void SetDataTip(uint32_t widget_data, StringID tool_tip);
361 void SetToolTip(StringID tool_tip);
362 void SetTextStyle(TextColour colour, FontSize size);
363 void SetAlignment(StringAlignment align);
364
365 inline void SetLowered(bool lowered);
366 inline bool IsLowered() const;
367 inline void SetDisabled(bool disabled);
368 inline bool IsDisabled() const;
369
370 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
371 NWidgetCore *GetWidgetFromPos(int x, int y) override;
372 bool IsHighlighted() const override;
373 TextColour GetHighlightColour() const override;
374 void SetHighlighted(TextColour highlight_colour) override;
375
376 NWidgetDisplay disp_flags;
377 Colours colour;
378 const WidgetID index;
379 uint32_t widget_data;
380 StringID tool_tip;
381 WidgetID scrollbar_index;
382 TextColour highlight_colour;
383 TextColour text_colour;
384 FontSize text_size;
385 StringAlignment align;
386 };
387
392 inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
393 {
394 this->disp_flags = highlight_colour != TC_INVALID ? SETBITS(this->disp_flags, ND_HIGHLIGHT) : CLRBITS(this->disp_flags, ND_HIGHLIGHT);
395 this->highlight_colour = highlight_colour;
396 }
397
399 inline bool NWidgetCore::IsHighlighted() const
400 {
401 return HasBit(this->disp_flags, NDB_HIGHLIGHT);
402 }
403
405 inline TextColour NWidgetCore::GetHighlightColour() const
406 {
407 return this->highlight_colour;
408 }
409
414 inline void NWidgetCore::SetLowered(bool lowered)
415 {
416 this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
417 }
418
420 inline bool NWidgetCore::IsLowered() const
421 {
422 return HasBit(this->disp_flags, NDB_LOWERED);
423 }
424
429 inline void NWidgetCore::SetDisabled(bool disabled)
430 {
431 this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
432 }
433
435 inline bool NWidgetCore::IsDisabled() const
436 {
437 return HasBit(this->disp_flags, NDB_DISABLED);
438 }
439
440
445 class NWidgetContainer : public NWidgetBase {
446 public:
447 NWidgetContainer(WidgetType tp) : NWidgetBase(tp) { }
448
449 void AdjustPaddingForZoom() override;
450 void Add(std::unique_ptr<NWidgetBase> &&wid);
451 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
452
453 void Draw(const Window *w) override;
454 NWidgetCore *GetWidgetFromPos(int x, int y) override;
455
457 inline bool IsEmpty() { return this->children.empty(); }
458
459 NWidgetBase *GetWidgetOfType(WidgetType tp) override;
460
461 protected:
462 std::vector<std::unique_ptr<NWidgetBase>> children;
463 };
464
466 enum StackedZeroSizePlanes {
467 SZSP_VERTICAL = INT_MAX / 2,
468 SZSP_HORIZONTAL,
469 SZSP_NONE,
470
471 SZSP_BEGIN = SZSP_VERTICAL,
472 };
473
484 class NWidgetStacked : public NWidgetContainer {
485 public:
486 NWidgetStacked(WidgetID index);
487
488 void AdjustPaddingForZoom() override;
489 void SetupSmallestSize(Window *w) override;
490 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
491 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
492
493 void Draw(const Window *w) override;
494 NWidgetCore *GetWidgetFromPos(int x, int y) override;
495
496 bool SetDisplayedPlane(int plane);
497
498 int shown_plane;
499 const WidgetID index;
500 private:
501 WidgetLookup *widget_lookup;
502 };
503
505 enum NWidContainerFlags {
506 NCB_EQUALSIZE = 0,
507 NCB_BIGFIRST = 1,
508
509 NC_NONE = 0,
510 NC_EQUALSIZE = 1 << NCB_EQUALSIZE,
511 NC_BIGFIRST = 1 << NCB_BIGFIRST,
512 };
513 DECLARE_ENUM_AS_BIT_SET(NWidContainerFlags)
514
515
516 class NWidgetPIPContainer : public NWidgetContainer {
517 public:
518 NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags = NC_NONE);
519
520 void AdjustPaddingForZoom() override;
521 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
522 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post);
523
524 protected:
525 NWidContainerFlags flags;
526 uint8_t pip_pre;
527 uint8_t pip_inter;
528 uint8_t pip_post;
529 uint8_t pip_ratio_pre;
530 uint8_t pip_ratio_inter;
531 uint8_t pip_ratio_post;
532
533 uint8_t uz_pip_pre;
534 uint8_t uz_pip_inter;
535 uint8_t uz_pip_post;
536
537 uint8_t gaps;
538 };
539
544 class NWidgetHorizontal : public NWidgetPIPContainer {
545 public:
546 NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
547
548 void SetupSmallestSize(Window *w) override;
549 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
550 };
551
556 class NWidgetHorizontalLTR : public NWidgetHorizontal {
557 public:
558 NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE);
559
560 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
561 };
562
567 class NWidgetVertical : public NWidgetPIPContainer {
568 public:
569 NWidgetVertical(NWidContainerFlags flags = NC_NONE);
570
571 void SetupSmallestSize(Window *w) override;
572 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
573 };
574
583 class NWidgetMatrix : public NWidgetPIPContainer {
584 public:
585 NWidgetMatrix(Colours colour, WidgetID index);
586
587 void SetClicked(int clicked);
588 void SetCount(int count);
589 void SetScrollbar(Scrollbar *sb);
590 int GetCurrentElement() const;
591
592 void SetupSmallestSize(Window *w) override;
593 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
594 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
595
596 NWidgetCore *GetWidgetFromPos(int x, int y) override;
597 void Draw(const Window *w) override;
598 protected:
599 const WidgetID index;
600 Colours colour;
601 int clicked;
602 int count;
603 int current_element;
604 Scrollbar *sb;
605 private:
606 int widget_w;
607 int widget_h;
608 int widgets_x;
609 int widgets_y;
610
611 void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
612 };
613
614
619 class NWidgetSpacer : public NWidgetResizeBase {
620 public:
621 NWidgetSpacer(int width, int height);
622
623 void SetupSmallestSize(Window *w) override;
624 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
625
626 void Draw(const Window *w) override;
627 void SetDirty(const Window *w) const override;
628 NWidgetCore *GetWidgetFromPos(int x, int y) override;
629 };
630
635 class NWidgetBackground : public NWidgetCore {
636 public:
637 NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child = nullptr);
638
639 void Add(std::unique_ptr<NWidgetBase> &&nwid);
640 void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
641 void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
642
643 void AdjustPaddingForZoom() override;
644 void SetupSmallestSize(Window *w) override;
645 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
646
647 void FillWidgetLookup(WidgetLookup &widget_lookup) override;
648
649 void Draw(const Window *w) override;
650 NWidgetCore *GetWidgetFromPos(int x, int y) override;
651 NWidgetBase *GetWidgetOfType(WidgetType tp) override;
652
653 private:
654 std::unique_ptr<NWidgetPIPContainer> child;
655 };
656
666 class NWidgetViewport : public NWidgetCore {
667 public:
668 NWidgetViewport(WidgetID index);
669
670 void SetupSmallestSize(Window *w) override;
671 void Draw(const Window *w) override;
672
673 void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
674 void UpdateViewportCoordinates(Window *w);
675 };
676
680 class Scrollbar {
681 private:
682 const bool is_vertical;
683 uint16_t count;
684 uint16_t cap;
685 uint16_t pos;
686 uint16_t stepsize;
687
688 public:
690 enum ScrollbarStepping {
691 SS_RAW,
692 SS_SMALL,
693 SS_BIG,
694 };
695
696 Scrollbar(bool is_vertical) : is_vertical(is_vertical), stepsize(1)
697 {
698 }
699
704 inline uint16_t GetCount() const
705 {
706 return this->count;
707 }
708
713 inline uint16_t GetCapacity() const
714 {
715 return this->cap;
716 }
717
722 inline uint16_t GetPosition() const
723 {
724 return this->pos;
725 }
726
732 inline bool IsVisible(uint16_t item) const
733 {
734 return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
735 }
736
741 inline bool IsVertical() const
742 {
743 return this->is_vertical;
744 }
745
750 void SetStepSize(size_t stepsize)
751 {
752 assert(stepsize > 0);
753
754 this->stepsize = ClampTo<uint16_t>(stepsize);
755 }
756
762 void SetCount(size_t num)
763 {
764 assert(num <= MAX_UVALUE(uint16_t));
765
766 this->count = ClampTo<uint16_t>(num);
767 /* Ensure position is within bounds */
768 this->SetPosition(this->pos);
769 }
770
776 void SetCapacity(size_t capacity)
777 {
778 assert(capacity <= MAX_UVALUE(uint16_t));
779
780 this->cap = ClampTo<uint16_t>(capacity);
781 /* Ensure position is within bounds */
782 this->SetPosition(this->pos);
783 }
784
785 void SetCapacityFromWidget(Window *w, WidgetID widget, int padding = 0);
786
792 bool SetPosition(int position)
793 {
794 uint16_t old_pos = this->pos;
795 this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
796 return this->pos != old_pos;
797 }
798
806 bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
807 {
808 if (difference == 0) return false;
809 switch (unit) {
810 case SS_SMALL: difference *= this->stepsize; break;
811 case SS_BIG: difference *= this->cap; break;
812 default: break;
813 }
814 return this->SetPosition(this->pos + difference);
815 }
816
823 void ScrollTowards(int position)
824 {
825 if (position < this->GetPosition()) {
826 /* scroll up to the item */
827 this->SetPosition(position);
828 } else if (position >= this->GetPosition() + this->GetCapacity()) {
829 /* scroll down so that the item is at the bottom */
830 this->SetPosition(position - this->GetCapacity() + 1);
831 }
832 }
833
834 int GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
835
846 template <typename Tcontainer>
847 typename Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
848 {
849 assert(this->GetCount() == container.size()); // Scrollbar and container size must match.
850 int row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
851 if (row == INT_MAX) return std::end(container);
852
853 typename Tcontainer::iterator it = std::begin(container);
854 std::advance(it, row);
855 return it;
856 }
857
858 EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
859 };
860
866 class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
867 public:
868 NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index);
869
870 void SetupSmallestSize(Window *w) override;
871 void Draw(const Window *w) override;
872
873 static void InvalidateDimensionCache();
874 static Dimension GetVerticalDimension();
875 static Dimension GetHorizontalDimension();
876
877 private:
878 static Dimension vertical_dimension;
879 static Dimension horizontal_dimension;
880 };
881
886 class NWidgetLeaf : public NWidgetCore {
887 public:
888 NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip);
889
890 void SetupSmallestSize(Window *w) override;
891 void Draw(const Window *w) override;
892
893 bool ButtonHit(const Point &pt);
894
895 static void InvalidateDimensionCache();
896
897 static Dimension dropdown_dimension;
898 static Dimension resizebox_dimension;
899 static Dimension closebox_dimension;
900 private:
901 static Dimension shadebox_dimension;
902 static Dimension debugbox_dimension;
903 static Dimension defsizebox_dimension;
904 static Dimension stickybox_dimension;
905 };
906
914 inline uint ComputeMaxSize(uint base, uint max_space, uint step)
915 {
916 if (base >= max_space || step == 0) return base;
917 if (step == 1) return max_space;
918 uint increment = max_space - base;
919 increment -= increment % step;
920 return base + increment;
921 }
922
974 struct NWidgetPartDataTip {
975 uint32_t data;
976 StringID tooltip;
977 };
978
983 struct NWidgetPartWidget {
984 Colours colour;
985 WidgetID index;
986 };
987
992 struct NWidgetPartPaddings : RectPadding {
993 };
994
999 struct NWidgetPartPIP {
1000 uint8_t pre, inter, post;
1001 };
1002
1007 struct NWidgetPartTextLines {
1008 uint8_t lines;
1009 uint8_t spacing;
1010 FontSize size;
1011 };
1012
1017 struct NWidgetPartTextStyle {
1018 TextColour colour;
1019 FontSize size;
1020 };
1021
1026 struct NWidgetPartAlignment {
1027 StringAlignment align;
1028 };
1029
1034 typedef std::unique_ptr<NWidgetBase> NWidgetFunctionType();
1035
1040 struct NWidgetPart {
1041 WidgetType type;
1042 union NWidgetPartUnion {
1043 Point xy;
1044 NWidgetPartDataTip data_tip;
1045 NWidgetPartWidget widget;
1046 NWidgetPartPaddings padding;
1047 NWidgetPartPIP pip;
1048 NWidgetPartTextLines text_lines;
1049 NWidgetPartTextStyle text_style;
1050 NWidgetPartAlignment align;
1051 NWidgetFunctionType *func_ptr;
1052 NWidContainerFlags cont_flags;
1053
1054 /* Constructors for each NWidgetPartUnion data type. */
1055 constexpr NWidgetPartUnion() : xy() {}
1056 constexpr NWidgetPartUnion(Point xy) : xy(xy) {}
1057 constexpr NWidgetPartUnion(NWidgetPartDataTip data_tip) : data_tip(data_tip) {}
1058 constexpr NWidgetPartUnion(NWidgetPartWidget widget) : widget(widget) {}
1059 constexpr NWidgetPartUnion(NWidgetPartPaddings padding) : padding(padding) {}
1060 constexpr NWidgetPartUnion(NWidgetPartPIP pip) : pip(pip) {}
1061 constexpr NWidgetPartUnion(NWidgetPartTextLines text_lines) : text_lines(text_lines) {}
1062 constexpr NWidgetPartUnion(NWidgetPartTextStyle text_style) : text_style(text_style) {}
1063 constexpr NWidgetPartUnion(NWidgetPartAlignment align) : align(align) {}
1064 constexpr NWidgetPartUnion(NWidgetFunctionType *func_ptr) : func_ptr(func_ptr) {}
1065 constexpr NWidgetPartUnion(NWidContainerFlags cont_flags) : cont_flags(cont_flags) {}
1066 } u;
1067
1068 /* Constructors for each NWidgetPart data type. */
1069 explicit constexpr NWidgetPart(WidgetType type) : type(type), u() {}
1070 constexpr NWidgetPart(WidgetType type, Point xy) : type(type), u(xy) {}
1071 constexpr NWidgetPart(WidgetType type, NWidgetPartDataTip data_tip) : type(type), u(data_tip) {}
1072 constexpr NWidgetPart(WidgetType type, NWidgetPartWidget widget) : type(type), u(widget) {}
1073 constexpr NWidgetPart(WidgetType type, NWidgetPartPaddings padding) : type(type), u(padding) {}
1074 constexpr NWidgetPart(WidgetType type, NWidgetPartPIP pip) : type(type), u(pip) {}
1075 constexpr NWidgetPart(WidgetType type, NWidgetPartTextLines text_lines) : type(type), u(text_lines) {}
1076 constexpr NWidgetPart(WidgetType type, NWidgetPartTextStyle text_style) : type(type), u(text_style) {}
1077 constexpr NWidgetPart(WidgetType type, NWidgetPartAlignment align) : type(type), u(align) {}
1078 constexpr NWidgetPart(WidgetType type, NWidgetFunctionType *func_ptr) : type(type), u(func_ptr) {}
1079 constexpr NWidgetPart(WidgetType type, NWidContainerFlags cont_flags) : type(type), u(cont_flags) {}
1080 };
1081
1088 constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
1089 {
1090 return NWidgetPart{WPT_RESIZE, Point{dx, dy}};
1091 }
1092
1099 constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
1100 {
1101 return NWidgetPart{WPT_MINSIZE, Point{x, y}};
1102 }
1103
1111 constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size = FS_NORMAL)
1112 {
1113 return NWidgetPart{WPT_MINTEXTLINES, NWidgetPartTextLines{lines, spacing, size}};
1114 }
1115
1122 constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size = FS_NORMAL)
1123 {
1124 return NWidgetPart{WPT_TEXTSTYLE, NWidgetPartTextStyle{colour, size}};
1125 }
1126
1132 constexpr NWidgetPart SetAlignment(StringAlignment align)
1133 {
1134 return NWidgetPart{WPT_ALIGNMENT, NWidgetPartAlignment{align}};
1135 }
1136
1143 constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
1144 {
1145 return NWidgetPart{WPT_FILL, Point{fill_x, fill_y}};
1146 }
1147
1153 constexpr NWidgetPart EndContainer()
1154 {
1155 return NWidgetPart{WPT_ENDCONTAINER};
1156 }
1157
1164 constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
1165 {
1166 return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{data, tip}};
1167 }
1168
1176 constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
1177 {
1178 return SetDataTip((rows << MAT_ROW_START) | (cols << MAT_COL_START), tip);
1179 }
1180
1190 constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
1191 {
1192 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{left, top, right, bottom}};
1193 }
1194
1200 constexpr NWidgetPart SetPadding(const RectPadding &padding)
1201 {
1202 return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{padding}};
1203 }
1204
1210 constexpr NWidgetPart SetPadding(uint8_t padding)
1211 {
1212 return SetPadding(padding, padding, padding, padding);
1213 }
1214
1222 constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
1223 {
1224 return NWidgetPart{WPT_PIPSPACE, NWidgetPartPIP{pre, inter, post}};
1225 }
1226
1234 constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
1235 {
1236 return NWidgetPart{WPT_PIPRATIO, NWidgetPartPIP{ratio_pre, ratio_inter, ratio_post}};
1237 }
1238
1246 constexpr NWidgetPart SetScrollbar(WidgetID index)
1247 {
1248 return NWidgetPart{WPT_SCROLLBAR, NWidgetPartWidget{INVALID_COLOUR, index}};
1249 }
1250
1260 constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx = -1)
1261 {
1262 return NWidgetPart{tp, NWidgetPartWidget{col, idx}};
1263 }
1264
1271 constexpr NWidgetPart NWidget(WidgetType tp, NWidContainerFlags cont_flags = NC_NONE)
1272 {
1273 return NWidgetPart{tp, NWidContainerFlags{cont_flags}};
1274 }
1275
1281 constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
1282 {
1283 return NWidgetPart{WPT_FUNCTION, func_ptr};
1284 }
1285
1286 bool IsContainerWidgetType(WidgetType tp);
1287 std::unique_ptr<NWidgetBase> MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr<NWidgetBase> &&container);
1288 std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select);
1289
1290 std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
1291
1292 void SetupWidgetDimensions();
1293
1294 #endif /* WIDGET_TYPE_H */
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:469
NWidgetSpacer::NWidgetSpacer
NWidgetSpacer(int width, int height)
Generic spacer widget.
Definition: widget.cpp:1723
NWidgetResizeBase
Base class for a resizable nested widget.
Definition: widget_type.h:291
NWidgetMatrix::clicked
int clicked
The currently clicked element.
Definition: widget_type.h:601
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
NWidgetContainer::children
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in contaier.
Definition: widget_type.h:462
NWidgetScrollbar::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2378
NWidgetMatrix::widgets_y
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:609
NDB_LOWERED
@ NDB_LOWERED
Widget is lowered (pressed down) bit.
Definition: widget_type.h:323
NWidgetBackground::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2060
NWidgetResizeBase::uz_min_x
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition: widget_type.h:312
Scrollbar::stepsize
uint16_t stepsize
Distance to scroll, when pressing the buttons or using the wheel.
Definition: widget_type.h:686
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:435
NWidgetPIPContainer::uz_pip_pre
uint8_t uz_pip_pre
Unscaled space before first widget.
Definition: widget_type.h:533
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:55
WPT_DATATIP
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition: widget_type.h:94
WPT_PIPRATIO
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition: widget_type.h:97
NWidgetCore::GetHighlightColour
TextColour GetHighlightColour() const override
Return the colour of the highlight.
Definition: widget_type.h:405
NWidgetCore::IsHighlighted
bool IsHighlighted() const override
Return whether the widget is highlighted.
Definition: widget_type.h:399
NWidgetSpacer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1756
Scrollbar::SS_SMALL
@ SS_SMALL
Step in stepsize units.
Definition: widget_type.h:692
NWidgetPartTextStyle
Widget part for storing text colour.
Definition: widget_type.h:1017
NWidgetBase::GetParentWidget
NWID * GetParentWidget()
Get parent widget of type NWID.
Definition: widget_type.h:154
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)=0
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:898
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
Scrollbar::is_vertical
const bool is_vertical
Scrollbar has vertical orientation.
Definition: widget_type.h:682
NWidgetCore::SetHighlighted
void SetHighlighted(TextColour highlight_colour) override
Highlight the widget or not.
Definition: widget_type.h:392
SZSP_BEGIN
@ SZSP_BEGIN
First zero-size plane.
Definition: widget_type.h:471
NWidgetPart::NWidgetPartUnion::text_lines
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:1048
NWidgetBase::GetVerticalStepSize
uint GetVerticalStepSize(SizingType sizing) const
Get the vertical sizing step.
Definition: widget_type.h:261
NWidgetPartTextStyle::size
FontSize size
Font size of text.
Definition: widget_type.h:1019
ND_SCROLLBAR_DOWN
@ ND_SCROLLBAR_DOWN
Bit value of the 'scrollbar down' flag.
Definition: widget_type.h:346
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:85
Scrollbar::ScrollbarStepping
ScrollbarStepping
Stepping sizes when scrolling.
Definition: widget_type.h:690
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:666
NWidgetContainer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1184
NWidgetContainer::Add
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition: widget.cpp:1161
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:823
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
NWidgetPartPaddings
Widget part for storing padding.
Definition: widget_type.h:992
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:583
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1132
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:54
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2235
NWidgetBase::FillWidgetLookup
virtual void FillWidgetLookup(WidgetLookup &widget_lookup)=0
NWidgetBase::GetHorizontalStepSize
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
Definition: widget_type.h:252
NDB_DROPDOWN_CLOSED
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition: widget_type.h:336
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:343
NWidgetPIPContainer::pip_ratio_pre
uint8_t pip_ratio_pre
Ratio of remaining space before first widget.
Definition: widget_type.h:529
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
math_func.hpp
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:379
NWidgetSpacer::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1729
NWidgetBase::uz_padding
RectPadding uz_padding
Unscaled padding, for resize calculation.
Definition: widget_type.h:240
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NWidgetStacked::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1280
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
NWidgetMatrix::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1906
NWidgetLeaf::stickybox_dimension
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:904
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:42
NDB_SCROLLBAR_DOWN
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
Definition: widget_type.h:333
NDB_SHADE_DIMMED
@ NDB_SHADE_DIMMED
Display dimmed colours in the viewport.
Definition: widget_type.h:328
window_type.h
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
NWidgetBase::parent
NWidgetBase * parent
Parent widget of this widget, automatically filled in when added to container.
Definition: widget_type.h:242
ArrowWidgetValues
ArrowWidgetValues
Values for an arrow widget.
Definition: widget_type.h:32
NWID_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition: widget_type.h:78
NWidgetSpacer
Spacer widget.
Definition: widget_type.h:619
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
WWT_ARROWBTN
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition: widget_type.h:56
NWidgetBase::NWidgetBase
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:851
Scrollbar::SetStepSize
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:750
NWidgetResizeBase::uz_min_y
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition: widget_type.h:313
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1176
NWidgetPIPContainer::pip_ratio_inter
uint8_t pip_ratio_inter
Ratio of remaining space between widgets.
Definition: widget_type.h:530
MAT_ROW_START
@ MAT_ROW_START
Lowest bit of the number of rows.
Definition: widget_type.h:27
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
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:2341
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:886
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
NWidgetResizeBase::UpdateVerticalSize
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1056
Scrollbar::count
uint16_t count
Number of elements in the list.
Definition: widget_type.h:683
NWidgetMatrix::SetScrollbar
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1811
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:337
NWidgetMatrix::count
int count
Amount of valid elements.
Definition: widget_type.h:602
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
NWID_CUSTOM
@ NWID_CUSTOM
General Custom widget.
Definition: widget_type.h:87
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:380
GetWidgetFromPos
WidgetID GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:266
NWidgetContainer::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1139
MakeWindowNWidgetTree
std::unique_ptr< NWidgetBase > MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:3164
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1281
strings_type.h
NWidgetPart::NWidgetPartUnion::text_style
NWidgetPartTextStyle text_style
Part with text style data.
Definition: widget_type.h:1049
NWidgetLeaf::shadebox_dimension
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:901
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition: widget_type.h:80
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:231
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
NCB_BIGFIRST
@ NCB_BIGFIRST
Allocate space to biggest resize first.
Definition: widget_type.h:507
NWidgetCore::text_size
FontSize text_size
Size of text within widget.
Definition: widget_type.h:384
NWidgetPIPContainer::pip_pre
uint8_t pip_pre
Amount of space before first widget.
Definition: widget_type.h:526
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
NWidgetScrollbar::NWidgetScrollbar
NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index)
Scrollbar widget.
Definition: widget.cpp:2357
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
NWidgetMatrix::sb
Scrollbar * sb
The scrollbar we're associated with.
Definition: widget_type.h:604
MAT_COL_START
@ MAT_COL_START
Lowest bit of the number of columns.
Definition: widget_type.h:23
NWidgetPartPIP::post
uint8_t post
Amount of space before/between/after child widgets.
Definition: widget_type.h:1000
SETBITS
#define SETBITS(x, y)
Sets several bits in a variable.
Definition: bitmath_func.hpp:136
NWidgetPIPContainer::pip_inter
uint8_t pip_inter
Amount of space between widgets.
Definition: widget_type.h:527
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:704
alloc_type.hpp
NWidgetMatrix::current_element
int current_element
The element currently being processed.
Definition: widget_type.h:603
NWidgetBase::StoreSizePosition
void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:274
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:1022
NWidgetBase::Draw
virtual void Draw(const Window *w)=0
NWidgetMatrix::SetCount
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1787
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
NWidgetStacked::widget_lookup
WidgetLookup * widget_lookup
Window's widget lookup, updated in SetDisplayedPlane().
Definition: widget_type.h:501
NWidgetPart::NWidgetPartUnion::data_tip
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:1044
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:2288
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2455
NWidgetResizeBase::NWidgetResizeBase
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:939
NWidgetPIPContainer::uz_pip_post
uint8_t uz_pip_post
Unscaled space after last widget.
Definition: widget_type.h:535
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition: geometry_type.hpp:51
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:510
NWidgetResizeBase::uz_text_spacing
uint8_t uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition: widget_type.h:316
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:344
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:806
bitmath_func.hpp
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:1190
NWidgetPart::NWidgetPartUnion::func_ptr
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:1051
AWV_LEFT
@ AWV_LEFT
Force the arrow to the left.
Definition: widget_type.h:35
NWidgetMatrix::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1846
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
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
WPT_FILL
@ WPT_FILL
Widget part for specifying fill.
Definition: widget_type.h:93
ComputeMaxSize
uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:914
NDB_HIGHLIGHT
@ NDB_HIGHLIGHT
Highlight of widget is on.
Definition: widget_type.h:335
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:109
NWidgetLeaf::dropdown_dimension
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:897
NWidgetStacked::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1249
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:118
NWidgetPartPIP
Widget part for storing pre/inter/post spaces.
Definition: widget_type.h:999
ND_HIGHLIGHT
@ ND_HIGHLIGHT
Bit value of the highlight flag.
Definition: widget_type.h:340
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:985
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2244
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
NWidgetHorizontal::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1431
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:83
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
NWidgetPart::NWidgetPartUnion
Definition: widget_type.h:1042
NWidgetPart::NWidgetPartUnion::align
NWidgetPartAlignment align
Part with internal alignment.
Definition: widget_type.h:1050
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
NWidgetPartTextLines::lines
uint8_t lines
Number of text lines.
Definition: widget_type.h:1008
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:1009
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:230
NWidgetLeaf::debugbox_dimension
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:902
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:923
WPT_PIPSPACE
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:96
NWidgetContainer::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1168
ZeroedMemoryAllocator
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
IsContainerWidgetType
bool IsContainerWidgetType(WidgetType tp)
Test if WidgetType is a container widget.
Definition: widget.cpp:3086
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidgetPIPContainer::gaps
uint8_t gaps
Number of gaps between widgets.
Definition: widget_type.h:537
NWidgetBackground::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:2135
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
NWidgetBackground::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:2190
NWidgetContainer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1175
Scrollbar::IsVertical
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:741
NWidgetMatrix::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1876
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:713
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:2045
WPT_SCROLLBAR
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition: widget_type.h:102
NWidgetPIPContainer::pip_ratio_post
uint8_t pip_ratio_post
Ratio of remaining space after last widget.
Definition: widget_type.h:531
MAT_COL_BITS
@ MAT_COL_BITS
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:24
NWidgetMatrix::index
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:599
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
NWidgetResizeBase::uz_text_size
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
Definition: widget_type.h:317
NWidgetDisplay
NWidgetDisplay
Nested widget flags that affect display and interaction with 'real' widgets.
Definition: widget_type.h:321
NWidgetLeaf::defsizebox_dimension
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:903
ND_LOWERED
@ ND_LOWERED
Bit value of the lowered flag.
Definition: widget_type.h:338
NWidgetPartTextLines
Widget part for storing minimal text line data.
Definition: widget_type.h:1007
NWidgetVertical::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1556
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:74
WPT_ALIGNMENT
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition: widget_type.h:99
NWidgetStacked::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1269
ND_DISABLED
@ ND_DISABLED
Bit value of the disabled flag.
Definition: widget_type.h:339
Scrollbar::SS_RAW
@ SS_RAW
Step in single units.
Definition: widget_type.h:691
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:332
NWidgetVertical::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1620
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WPT_MINSIZE
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition: widget_type.h:91
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:420
NWidgetPartWidget
Widget part for storing basic widget information.
Definition: widget_type.h:983
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition: widget_type.h:776
NDB_NO_TRANSPARENCY
@ NDB_NO_TRANSPARENCY
Viewport is never transparent.
Definition: widget_type.h:326
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:62
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:847
NWidgetStacked::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1289
NWidgetBase::GetParentWidget
const NWID * GetParentWidget() const
Get parent widget of type NWID.
Definition: widget_type.h:168
NWidgetPartDataTip
Widget part for storing data and tooltip information.
Definition: widget_type.h:974
NWidgetHorizontal::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1367
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:234
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:484
NWidgetScrollbar::vertical_dimension
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:878
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:48
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:998
Scrollbar::GetScrolledRowFromWidget
int 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:2267
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:58
MakeNWidgets
std::unique_ptr< NWidgetBase > MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:3144
NWidgetSpacer::SetDirty
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1751
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WPT_MINTEXTLINES
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:92
NWidgetContainer::IsEmpty
bool IsEmpty()
Return whether the container is empty.
Definition: widget_type.h:457
Scrollbar::cap
uint16_t cap
Number of visible elements of the scroll bar.
Definition: widget_type.h:684
NWidgetBase::GetWidgetFromPos
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
NWidgetMatrix::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1870
NWidgetBase::SetPadding
void SetPadding(const RectPadding &padding)
Set additional space (padding) around the widget.
Definition: widget_type.h:200
NWidgetBackground::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:2180
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:1961
NWidgetSpacer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1739
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:224
NWidgetBackground::child
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
Definition: widget_type.h:654
NWidgetHorizontalLTR::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1546
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:3203
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
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:2026
ND_DROPDOWN_CLOSED
@ ND_DROPDOWN_CLOSED
Bit value of the 'dropdown closed' flag.
Definition: widget_type.h:348
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:376
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:544
NWidgetPIPContainer::pip_post
uint8_t pip_post
Amount of space after last widget.
Definition: widget_type.h:528
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:119
WidgetLookup
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition: widget_type.h:127
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:732
Scrollbar::pos
uint16_t pos
Index of first visible item of the list.
Definition: widget_type.h:685
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
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:1222
NWidgetPIPContainer
Container with pre/inter/post child space.
Definition: widget_type.h:516
NWidgetLeaf::NWidgetLeaf
NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2482
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:223
NWidgetSpacer::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1735
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:866
NWidgetBackground::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2141
WPT_RESIZE
@ WPT_RESIZE
Widget part for specifying resizing.
Definition: widget_type.h:90
NWidgetPIPContainer::flags
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:525
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w)=0
NDB_SHADE_GREY
@ NDB_SHADE_GREY
Shade viewport to grey-scale.
Definition: widget_type.h:327
NWidgetPartTextLines::spacing
uint8_t spacing
Extra spacing around lines.
Definition: widget_type.h:1009
NWidgetCore::scrollbar_index
WidgetID scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:381
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
NWidgetPart::NWidgetPartUnion::pip
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:1047
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1304
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
NWidgetPIPContainer::uz_pip_inter
uint8_t uz_pip_inter
Unscaled space between widgets.
Definition: widget_type.h:534
NWidgetPartAlignment
Widget part for setting text/image alignment within a widget.
Definition: widget_type.h:1026
ResizeWidgetValues
ResizeWidgetValues
WidgetData values for a resize box widget.
Definition: widget_type.h:40
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
NWidgetFunctionType
std::unique_ptr< NWidgetBase > NWidgetFunctionType()
Pointer to function returning a nested widget.
Definition: widget_type.h:1034
EventState
EventState
State of handling an event.
Definition: window_type.h:738
NWidgetVertical
Vertical container.
Definition: widget_type.h:567
NWidgetMatrix::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1825
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
NWidgetStacked::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1210
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:377
NWidgetMatrix::widget_h
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:607
NWidgetCore::highlight_colour
TextColour highlight_colour
Colour of highlight.
Definition: widget_type.h:382
NCB_EQUALSIZE
@ NCB_EQUALSIZE
Containers should keep all their (resizing) children equally large.
Definition: widget_type.h:506
NWidgetMatrix::GetCurrentElement
int GetCurrentElement() const
Get current element.
Definition: widget.cpp:1820
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:445
NC_NONE
@ NC_NONE
All flags cleared.
Definition: widget_type.h:509
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
NWidgetCore::index
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:378
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
NWidgetResizeBase::uz_text_lines
uint8_t uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition: widget_type.h:315
NWidgetBackground::NWidgetBackground
NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr< NWidgetPIPContainer > &&child=nullptr)
Constructor parent nested widgets.
Definition: widget.cpp:1992
NWidgetPart::NWidgetPartUnion::cont_flags
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:1052
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
StackedZeroSizePlanes
StackedZeroSizePlanes
Display planes with zero size for NWidgetStacked.
Definition: widget_type.h:466
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:1234
NWidgetHorizontalLTR::NWidgetHorizontalLTR
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1541
NWidgetPartDataTip::data
uint32_t data
Data value of the widget.
Definition: widget_type.h:975
NWidgetResizeBase::min_x
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:308
NWidgetStacked::NWidgetStacked
NWidgetStacked(WidgetID index)
Widgets stacked on top of each other.
Definition: widget.cpp:1198
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
NWidgetResizeBase::UpdateSize
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1042
ND_SCROLLBAR_UP
@ ND_SCROLLBAR_UP
Bit value of the 'scrollbar up' flag.
Definition: widget_type.h:345
NWidgetCore::align
StringAlignment align
Alignment of text/image within widget.
Definition: widget_type.h:385
Scrollbar::SS_BIG
@ SS_BIG
Step in cap units.
Definition: widget_type.h:693
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:342
WPT_PADDING
@ WPT_PADDING
Widget part for specifying a padding.
Definition: widget_type.h:95
NWidgetCore::text_colour
TextColour text_colour
Colour of text within widget.
Definition: widget_type.h:383
NWidgetPart::type
WidgetType type
Type of the part.
Definition: widget_type.h:1041
NWidgetResizeBase::min_y
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:309
NWidgetHorizontalLTR
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition: widget_type.h:556
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
NWidgetMatrix::widget_w
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:606
NWidgetViewport::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2202
MAT_ROW_BITS
@ MAT_ROW_BITS
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:28
Window
Data structure for an opened window.
Definition: window_gui.h:267
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:117
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:187
NWidContainerFlags
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:505
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:467
RWV_SHOW_BEVEL
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition: widget_type.h:41
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
NWidgetResizeBase::absolute
bool absolute
Set if minimum size is fixed and should not be resized.
Definition: widget_type.h:311
MatrixWidgetValues
MatrixWidgetValues
Bits of the WWT_MATRIX widget data.
Definition: widget_type.h:21
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:635
NDB_DISABLED
@ NDB_DISABLED
Widget is disabled (greyed out) bit.
Definition: widget_type.h:324
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
NWidgetVertical::NWidgetVertical
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1552
NWidgetViewport::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2208
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:1111
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
NWidgetMatrix::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:600
NWidgetResizeBase::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1063
NWidgetPart::NWidgetPartUnion::padding
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:1046
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:66
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:899
NWidgetLeaf::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2573
AWV_RIGHT
@ AWV_RIGHT
Force the arrow to the right.
Definition: widget_type.h:36
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:65
gfx_type.h
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
NWidgetPartDataTip::tooltip
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:976
WPT_FUNCTION
@ WPT_FUNCTION
Widget part for calling a user function.
Definition: widget_type.h:101
NWidgetLeaf::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2743
WPT_TEXTSTYLE
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition: widget_type.h:98
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:225
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
NWidgetPartWidget::colour
Colours colour
Widget colour.
Definition: widget_type.h:984
NWidgetPartTextLines::size
FontSize size
Font size of text lines.
Definition: widget_type.h:1010
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:233
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:498
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:959
NWidgetScrollbar::horizontal_dimension
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:879
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:972
NWidgetScrollbar::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2399
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:2883
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1122
NWidgetHorizontal::NWidgetHorizontal
NWidgetHorizontal(NWidContainerFlags flags=NC_NONE)
Horizontal container widget.
Definition: widget.cpp:1363
NWidgetPartTextStyle::colour
TextColour colour
TextColour for DrawString.
Definition: widget_type.h:1018
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition: widget_type.h:429
NWidgetPart::NWidgetPartUnion::xy
Point xy
Part with an x/y size.
Definition: widget_type.h:1043
NWidgetBase::padding
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition: widget_type.h:239
NWidgetStacked::index
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:499
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:347
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
NWidgetPartWidget::index
WidgetID index
Index of the widget.
Definition: widget_type.h:985
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:84
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:792
NWidgetMatrix::widgets_x
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:608
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
ND_NO_TRANSPARENCY
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition: widget_type.h:341
NC_BIGFIRST
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
Definition: widget_type.h:511
NDB_DROPDOWN_ACTIVE
@ NDB_DROPDOWN_ACTIVE
Dropdown menu of the button dropdown widget is active.
Definition: widget_type.h:330
NWidgetPartAlignment::align
StringAlignment align
Alignment of text/image.
Definition: widget_type.h:1027
NWidgetBackground::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:2123
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
NWidgetBackground::Add
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition: widget.cpp:2007
NWidgetPart::NWidgetPartUnion::widget
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:1045
NWidgetMatrix::SetClicked
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition: widget.cpp:1770
WPT_ENDCONTAINER
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition: widget_type.h:100
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103