OpenTTD Source  20241108-master-g80f628063a
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 /* Number of column bits of the WWT_MATRIX widget data. */
22 static constexpr uint8_t MAT_COL_START = 0;
23 static constexpr uint8_t MAT_COL_BITS = 8;
24 
25 /* Number of row bits of the WWT_MATRIX widget data. */
26 static constexpr uint8_t MAT_ROW_START = 8;
27 static constexpr uint8_t MAT_ROW_BITS = 8;
28 
35 };
36 
41 };
42 
46 enum WidgetType {
47  /* Window widget types. */
49 
62 
67 
73 
74  /* Nested widget types. */
86 
87  /* Nested widget part types. */
102 
105 
106  /* Pushable window widget types. */
107  WWT_MASK = 0x7F,
108 
109  WWB_PUSHBUTTON = 1 << 7,
110 
111  WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON,
112  WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON,
113  WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON,
114  WWT_PUSHARROWBTN = WWT_ARROWBTN | WWB_PUSHBUTTON,
115  NWID_PUSHBUTTON_DROPDOWN = NWID_BUTTON_DROPDOWN | WWB_PUSHBUTTON,
116 };
117 
122 };
123 
124 enum class AspectFlags : uint8_t {
125  ResizeX = 1U << 0,
126  ResizeY = 1U << 1,
127  ResizeXY = ResizeX | ResizeY,
128 };
129 DECLARE_ENUM_AS_BIT_SET(AspectFlags)
130 
131 /* Forward declarations. */
132 class NWidgetCore;
133 class Scrollbar;
134 
136 using WidgetLookup = std::map<WidgetID, class NWidgetBase *>;
137 
145 public:
147 
148  void ApplyAspectRatio();
149  virtual void AdjustPaddingForZoom();
150  virtual void SetupSmallestSize(Window *w) = 0;
151  virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
152 
153  virtual void FillWidgetLookup(WidgetLookup &widget_lookup) = 0;
154 
155  virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
157 
163  template <class NWID>
165  {
166  for (NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
167  if (NWID *nwid = dynamic_cast<NWID *>(nwid_parent); nwid != nullptr) return nwid;
168  }
169  return nullptr;
170  }
171 
177  template <class NWID>
178  const NWID *GetParentWidget() const
179  {
180  for (const NWidgetBase *nwid_parent = this->parent; nwid_parent != nullptr; nwid_parent = nwid_parent->parent) {
181  if (const NWID *nwid = dynamic_cast<const NWID *>(nwid_parent); nwid != nullptr) return nwid;
182  }
183  return nullptr;
184  }
185 
186  virtual bool IsHighlighted() const { return false; }
187  virtual TextColour GetHighlightColour() const { return TC_INVALID; }
188  virtual void SetHighlighted([[maybe_unused]] TextColour highlight_colour) {}
189 
197  inline void SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
198  {
199  this->uz_padding.top = top;
200  this->uz_padding.right = right;
201  this->uz_padding.bottom = bottom;
202  this->uz_padding.left = left;
203  this->AdjustPaddingForZoom();
204  }
205 
210  inline void SetPadding(const RectPadding &padding)
211  {
212  this->uz_padding = padding;
213  this->AdjustPaddingForZoom();
214  }
215 
216  inline uint GetHorizontalStepSize(SizingType sizing) const;
217  inline uint GetVerticalStepSize(SizingType sizing) const;
218 
219  virtual void Draw(const Window *w) = 0;
220  virtual void SetDirty(const Window *w) const;
221 
222  Rect GetCurrentRect() const
223  {
224  Rect r;
225  r.left = this->pos_x;
226  r.top = this->pos_y;
227  r.right = this->pos_x + this->current_x - 1;
228  r.bottom = this->pos_y + this->current_y - 1;
229  return r;
230  }
231 
233  uint fill_x;
234  uint fill_y;
235  uint resize_x;
236  uint resize_y;
237  /* Size of the widget in the smallest window possible.
238  * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
239  */
240  uint smallest_x;
241  uint smallest_y;
242  /* Current widget size (that is, after resizing). */
243  uint current_x;
244  uint current_y;
245  float aspect_ratio = 0;
246  AspectFlags aspect_flags = AspectFlags::ResizeX;
247 
248  int pos_x;
249  int pos_y;
250 
253 
255 
256 protected:
257  inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
258 };
259 
265 {
266  return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
267 }
268 
274 {
275  return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
276 }
277 
286 inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
287 {
288  this->pos_x = x;
289  this->pos_y = y;
290  if (sizing == ST_SMALLEST) {
291  this->smallest_x = given_width;
292  this->smallest_y = given_height;
293  }
294  this->current_x = given_width;
295  this->current_y = given_height;
296 }
297 
298 
304 public:
305  NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
306 
307  void AdjustPaddingForZoom() override;
308  void SetMinimalSize(uint min_x, uint min_y);
309  void SetMinimalSizeAbsolute(uint min_x, uint min_y);
310  void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size);
311  void SetFill(uint fill_x, uint fill_y);
312  void SetResize(uint resize_x, uint resize_y);
313  void SetAspect(float ratio, AspectFlags flags = AspectFlags::ResizeX);
314  void SetAspect(int x_ratio, int y_ratio, AspectFlags flags = AspectFlags::ResizeX);
315 
316  bool UpdateMultilineWidgetSize(const std::string &str, int max_lines);
317  bool UpdateSize(uint min_x, uint min_y);
318  bool UpdateVerticalSize(uint min_y);
319 
320  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
321 
322  uint min_x;
323  uint min_y;
324 
325  bool absolute;
326  uint uz_min_x;
327  uint uz_min_y;
328 
329  uint8_t uz_text_lines;
330  uint8_t uz_text_spacing;
332 };
333 
336  /* Generic. */
339  /* Viewport widget. */
343  /* Button dropdown widget. */
345  /* Scrollbar widget. */
348  /* Generic. */
351 
363 };
365 
366 
371 public:
372  NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip);
373 
374  void SetDataTip(uint32_t widget_data, StringID tool_tip);
375  void SetToolTip(StringID tool_tip);
376  void SetTextStyle(TextColour colour, FontSize size);
377  void SetAlignment(StringAlignment align);
378 
379  inline void SetLowered(bool lowered);
380  inline bool IsLowered() const;
381  inline void SetDisabled(bool disabled);
382  inline bool IsDisabled() const;
383 
384  void FillWidgetLookup(WidgetLookup &widget_lookup) override;
385  NWidgetCore *GetWidgetFromPos(int x, int y) override;
386  bool IsHighlighted() const override;
387  TextColour GetHighlightColour() const override;
388  void SetHighlighted(TextColour highlight_colour) override;
389 
391  Colours colour;
392  const WidgetID index;
393  uint32_t widget_data;
400 };
401 
406 inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
407 {
408  this->disp_flags = highlight_colour != TC_INVALID ? SETBITS(this->disp_flags, ND_HIGHLIGHT) : CLRBITS(this->disp_flags, ND_HIGHLIGHT);
409  this->highlight_colour = highlight_colour;
410 }
411 
413 inline bool NWidgetCore::IsHighlighted() const
414 {
415  return HasBit(this->disp_flags, NDB_HIGHLIGHT);
416 }
417 
420 {
421  return this->highlight_colour;
422 }
423 
428 inline void NWidgetCore::SetLowered(bool lowered)
429 {
430  this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
431 }
432 
434 inline bool NWidgetCore::IsLowered() const
435 {
436  return HasBit(this->disp_flags, NDB_LOWERED);
437 }
438 
443 inline void NWidgetCore::SetDisabled(bool disabled)
444 {
445  this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
446 }
447 
449 inline bool NWidgetCore::IsDisabled() const
450 {
451  return HasBit(this->disp_flags, NDB_DISABLED);
452 }
453 
454 
460 public:
462 
463  void AdjustPaddingForZoom() override;
464  void Add(std::unique_ptr<NWidgetBase> &&wid);
465  void FillWidgetLookup(WidgetLookup &widget_lookup) override;
466 
467  void Draw(const Window *w) override;
468  NWidgetCore *GetWidgetFromPos(int x, int y) override;
469 
471  inline bool IsEmpty() { return this->children.empty(); }
472 
473  NWidgetBase *GetWidgetOfType(WidgetType tp) override;
474 
475 protected:
476  std::vector<std::unique_ptr<NWidgetBase>> children;
477 };
478 
481  SZSP_VERTICAL = INT_MAX / 2,
484 
486 };
487 
499 public:
501 
502  void AdjustPaddingForZoom() override;
503  void SetupSmallestSize(Window *w) override;
504  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
506 
507  void Draw(const Window *w) override;
508  NWidgetCore *GetWidgetFromPos(int x, int y) override;
509 
510  bool SetDisplayedPlane(int plane);
511 
513  const WidgetID index;
514 private:
516 };
517 
522 
523  NC_NONE = 0,
526 };
528 
529 
531 public:
533 
534  void AdjustPaddingForZoom() override;
535  void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
536  void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post);
537 
538 protected:
540  uint8_t pip_pre;
541  uint8_t pip_inter;
542  uint8_t pip_post;
543  uint8_t pip_ratio_pre;
544  uint8_t pip_ratio_inter;
545  uint8_t pip_ratio_post;
546 
547  uint8_t uz_pip_pre;
548  uint8_t uz_pip_inter;
549  uint8_t uz_pip_post;
550 
551  uint8_t gaps;
552 };
553 
559 public:
561 
562  void SetupSmallestSize(Window *w) override;
563  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
564 };
565 
571 public:
573 
574  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
575 };
576 
582 public:
584 
585  void SetupSmallestSize(Window *w) override;
586  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
587 };
588 
598 public:
600 
601  void SetClicked(int clicked);
602  void SetCount(int count);
603  void SetScrollbar(Scrollbar *sb);
604  int GetCurrentElement() const;
605 
606  void SetupSmallestSize(Window *w) override;
607  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
608  void FillWidgetLookup(WidgetLookup &widget_lookup) override;
609 
610  NWidgetCore *GetWidgetFromPos(int x, int y) override;
611  void Draw(const Window *w) override;
612 protected:
613  const WidgetID index;
614  Colours colour;
615  int clicked;
616  int count;
619 private:
620  int widget_w;
621  int widget_h;
622  int widgets_x;
623  int widgets_y;
624 
625  void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
626 };
627 
628 
634 public:
635  NWidgetSpacer(int width, int height);
636 
637  void SetupSmallestSize(Window *w) override;
638  void FillWidgetLookup(WidgetLookup &widget_lookup) override;
639 
640  void Draw(const Window *w) override;
641  void SetDirty(const Window *w) const override;
642  NWidgetCore *GetWidgetFromPos(int x, int y) override;
643 };
644 
650 public:
651  NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child = nullptr);
652 
653  void Add(std::unique_ptr<NWidgetBase> &&nwid);
654  void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
655  void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
656 
657  void AdjustPaddingForZoom() override;
658  void SetupSmallestSize(Window *w) override;
659  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
660 
661  void FillWidgetLookup(WidgetLookup &widget_lookup) override;
662 
663  void Draw(const Window *w) override;
664  NWidgetCore *GetWidgetFromPos(int x, int y) override;
665  NWidgetBase *GetWidgetOfType(WidgetType tp) override;
666 
667 private:
668  std::unique_ptr<NWidgetPIPContainer> child;
669 };
670 
680 class NWidgetViewport : public NWidgetCore {
681 public:
683 
684  void SetupSmallestSize(Window *w) override;
685  void Draw(const Window *w) override;
686 
687  void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
689 };
690 
694 class Scrollbar {
695 public:
696  using size_type = int32_t;
697  static constexpr size_type max_size_type = std::numeric_limits<size_type>::max();
698  static constexpr size_type npos = max_size_type;
699 private:
700  const bool is_vertical;
701  size_type count;
702  size_type cap;
703  size_type pos;
704  size_type stepsize;
705 
706 public:
712  };
713 
715  {
716  }
717 
722  inline size_type GetCount() const
723  {
724  return this->count;
725  }
726 
731  inline size_type GetCapacity() const
732  {
733  return this->cap;
734  }
735 
740  inline size_type GetPosition() const
741  {
742  return this->pos;
743  }
744 
750  inline bool IsVisible(size_type item) const
751  {
752  return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
753  }
754 
759  inline bool IsVertical() const
760  {
761  return this->is_vertical;
762  }
763 
768  void SetStepSize(size_t stepsize)
769  {
770  assert(stepsize > 0);
771 
772  this->stepsize = ClampTo<size_type>(stepsize);
773  }
774 
780  void SetCount(size_t num)
781  {
782  assert(num < Scrollbar::max_size_type);
783 
784  this->count = ClampTo<size_type>(num);
785  /* Ensure position is within bounds */
786  this->SetPosition(this->pos);
787  }
788 
794  void SetCapacity(size_t capacity)
795  {
796  assert(capacity < Scrollbar::max_size_type);
797 
798  this->cap = ClampTo<size_type>(capacity);
799  /* Ensure position is within bounds */
800  this->SetPosition(this->pos);
801  }
802 
803  void SetCapacityFromWidget(Window *w, WidgetID widget, int padding = 0);
804 
810  bool SetPosition(size_type position)
811  {
812  size_type old_pos = this->pos;
813  this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
814  return this->pos != old_pos;
815  }
816 
824  bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
825  {
826  if (difference == 0) return false;
827  switch (unit) {
828  case SS_SMALL: difference *= this->stepsize; break;
829  case SS_BIG: difference *= this->cap; break;
830  default: break;
831  }
832  return this->SetPosition(this->pos + difference);
833  }
834 
841  void ScrollTowards(size_type position)
842  {
843  if (position < this->GetPosition()) {
844  /* scroll up to the item */
845  this->SetPosition(position);
846  } else if (position >= this->GetPosition() + this->GetCapacity()) {
847  /* scroll down so that the item is at the bottom */
848  this->SetPosition(position - this->GetCapacity() + 1);
849  }
850  }
851 
852  size_type GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
853 
859  template <typename Tcontainer>
860  auto GetVisibleRangeIterators(Tcontainer &container) const
861  {
862  assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
863  auto first = std::next(std::begin(container), this->GetPosition());
864  auto last = std::next(first, std::min<size_t>(this->GetCapacity(), this->GetCount() - this->GetPosition()));
865  return std::make_pair(first, last);
866  }
867 
878  template <typename Tcontainer>
879  auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
880  {
881  assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
882  size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
883  if (row == Scrollbar::npos) return std::end(container);
884 
885  return std::next(std::begin(container), row);
886  }
887 
888  EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
889 };
890 
896 class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
897 public:
899 
900  void SetupSmallestSize(Window *w) override;
901  void Draw(const Window *w) override;
902 
903  static void InvalidateDimensionCache();
904  static Dimension GetVerticalDimension();
905  static Dimension GetHorizontalDimension();
906 
907 private:
910 };
911 
916 class NWidgetLeaf : public NWidgetCore {
917 public:
918  NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip);
919 
920  void SetupSmallestSize(Window *w) override;
921  void Draw(const Window *w) override;
922 
923  bool ButtonHit(const Point &pt);
924 
925  static void InvalidateDimensionCache();
926 
930 private:
935 };
936 
944 inline uint ComputeMaxSize(uint base, uint max_space, uint step)
945 {
946  if (base >= max_space || step == 0) return base;
947  if (step == 1) return max_space;
948  uint increment = max_space - base;
949  increment -= increment % step;
950  return base + increment;
951 }
952 
1005  uint32_t data;
1007 };
1008 
1014  Colours colour;
1016 };
1017 
1023 };
1024 
1030  uint8_t pre, inter, post;
1031 };
1032 
1038  uint8_t lines;
1039  uint8_t spacing;
1041 };
1042 
1050 };
1051 
1058 };
1059 
1061  float ratio;
1062  AspectFlags flags;
1063 };
1064 
1069 typedef std::unique_ptr<NWidgetBase> NWidgetFunctionType();
1070 
1075 struct NWidgetPart {
1089 
1090  /* Constructors for each NWidgetPartUnion data type. */
1091  constexpr NWidgetPartUnion() : xy() {}
1092  constexpr NWidgetPartUnion(Point xy) : xy(xy) {}
1093  constexpr NWidgetPartUnion(NWidgetPartDataTip data_tip) : data_tip(data_tip) {}
1094  constexpr NWidgetPartUnion(NWidgetPartWidget widget) : widget(widget) {}
1095  constexpr NWidgetPartUnion(NWidgetPartPaddings padding) : padding(padding) {}
1096  constexpr NWidgetPartUnion(NWidgetPartPIP pip) : pip(pip) {}
1097  constexpr NWidgetPartUnion(NWidgetPartTextLines text_lines) : text_lines(text_lines) {}
1098  constexpr NWidgetPartUnion(NWidgetPartTextStyle text_style) : text_style(text_style) {}
1099  constexpr NWidgetPartUnion(NWidgetPartAlignment align) : align(align) {}
1100  constexpr NWidgetPartUnion(NWidgetFunctionType *func_ptr) : func_ptr(func_ptr) {}
1101  constexpr NWidgetPartUnion(NWidContainerFlags cont_flags) : cont_flags(cont_flags) {}
1102  constexpr NWidgetPartUnion(NWidgetPartAspect aspect) : aspect(aspect) {}
1103  } u;
1104 
1105  /* Constructors for each NWidgetPart data type. */
1106  explicit constexpr NWidgetPart(WidgetType type) : type(type), u() {}
1107  constexpr NWidgetPart(WidgetType type, Point xy) : type(type), u(xy) {}
1108  constexpr NWidgetPart(WidgetType type, NWidgetPartDataTip data_tip) : type(type), u(data_tip) {}
1109  constexpr NWidgetPart(WidgetType type, NWidgetPartWidget widget) : type(type), u(widget) {}
1110  constexpr NWidgetPart(WidgetType type, NWidgetPartPaddings padding) : type(type), u(padding) {}
1111  constexpr NWidgetPart(WidgetType type, NWidgetPartPIP pip) : type(type), u(pip) {}
1112  constexpr NWidgetPart(WidgetType type, NWidgetPartTextLines text_lines) : type(type), u(text_lines) {}
1113  constexpr NWidgetPart(WidgetType type, NWidgetPartTextStyle text_style) : type(type), u(text_style) {}
1114  constexpr NWidgetPart(WidgetType type, NWidgetPartAlignment align) : type(type), u(align) {}
1115  constexpr NWidgetPart(WidgetType type, NWidgetFunctionType *func_ptr) : type(type), u(func_ptr) {}
1116  constexpr NWidgetPart(WidgetType type, NWidContainerFlags cont_flags) : type(type), u(cont_flags) {}
1117  constexpr NWidgetPart(WidgetType type, NWidgetPartAspect aspect) : type(type), u(aspect) {}
1118 };
1119 
1126 constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
1127 {
1128  return NWidgetPart{WPT_RESIZE, Point{dx, dy}};
1129 }
1130 
1137 constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
1138 {
1139  return NWidgetPart{WPT_MINSIZE, Point{x, y}};
1140 }
1141 
1149 constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size = FS_NORMAL)
1150 {
1151  return NWidgetPart{WPT_MINTEXTLINES, NWidgetPartTextLines{lines, spacing, size}};
1152 }
1153 
1161 {
1162  return NWidgetPart{WPT_TEXTSTYLE, NWidgetPartTextStyle{colour, size}};
1163 }
1164 
1171 {
1173 }
1174 
1181 constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
1182 {
1183  return NWidgetPart{WPT_FILL, Point{fill_x, fill_y}};
1184 }
1185 
1192 {
1193  return NWidgetPart{WPT_ENDCONTAINER};
1194 }
1195 
1202 constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
1203 {
1204  return NWidgetPart{WPT_DATATIP, NWidgetPartDataTip{data, tip}};
1205 }
1206 
1214 constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
1215 {
1216  return SetDataTip((rows << MAT_ROW_START) | (cols << MAT_COL_START), tip);
1217 }
1218 
1228 constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
1229 {
1230  return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{left, top, right, bottom}};
1231 }
1232 
1238 constexpr NWidgetPart SetPadding(const RectPadding &padding)
1239 {
1240  return NWidgetPart{WPT_PADDING, NWidgetPartPaddings{padding}};
1241 }
1242 
1248 constexpr NWidgetPart SetPadding(uint8_t padding)
1249 {
1250  return SetPadding(padding, padding, padding, padding);
1251 }
1252 
1260 constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
1261 {
1262  return NWidgetPart{WPT_PIPSPACE, NWidgetPartPIP{pre, inter, post}};
1263 }
1264 
1272 constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
1273 {
1274  return NWidgetPart{WPT_PIPRATIO, NWidgetPartPIP{ratio_pre, ratio_inter, ratio_post}};
1275 }
1276 
1285 {
1286  return NWidgetPart{WPT_SCROLLBAR, NWidgetPartWidget{INVALID_COLOUR, index}};
1287 }
1288 
1295 constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags = AspectFlags::ResizeX)
1296 {
1297  return NWidgetPart{WPT_ASPECT, NWidgetPartAspect{ratio, flags}};
1298 }
1299 
1309 constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx = -1)
1310 {
1311  return NWidgetPart{tp, NWidgetPartWidget{col, idx}};
1312 }
1313 
1321 {
1322  return NWidgetPart{tp, NWidContainerFlags{cont_flags}};
1323 }
1324 
1331 {
1332  return NWidgetPart{WPT_FUNCTION, func_ptr};
1333 }
1334 
1336 std::unique_ptr<NWidgetBase> MakeNWidgets(std::span<const NWidgetPart> nwid_parts, std::unique_ptr<NWidgetBase> &&container);
1337 std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(std::span<const NWidgetPart> nwid_parts, NWidgetStacked **shade_select);
1338 
1339 std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
1340 
1341 void SetupWidgetDimensions();
1342 
1343 #endif /* WIDGET_TYPE_H */
Helper types related to the allocation of memory.
Functions related to bit mathematics.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
#define CLRBITS(x, y)
Clears several bits in a variable.
#define SETBITS(x, y)
Sets several bits in a variable.
Nested widget with a child.
Definition: widget_type.h:649
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:2232
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:2242
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:2175
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:2110
NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr< NWidgetPIPContainer > &&child=nullptr)
Constructor parent nested widgets.
Definition: widget.cpp:2042
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:2076
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
Definition: widget_type.h:668
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2193
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition: widget.cpp:2057
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition: widget.cpp:2187
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:2095
Baseclass for nested widgets.
Definition: widget_type.h:144
void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:286
float aspect_ratio
Desired aspect ratio of widget.
Definition: widget_type.h:245
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
Definition: widget_type.h:264
virtual void SetupSmallestSize(Window *w)=0
Compute smallest size needed by the widget.
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:232
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:235
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:233
NWidgetBase * parent
Parent widget of this widget, automatically filled in when added to container.
Definition: widget_type.h:254
virtual void FillWidgetLookup(WidgetLookup &widget_lookup)=0
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
RectPadding uz_padding
Unscaled padding, for resize calculation.
Definition: widget_type.h:252
NWID * GetParentWidget()
Get parent widget of type NWID.
Definition: widget_type.h:164
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:240
AspectFlags aspect_flags
Which dimensions can be resized.
Definition: widget_type.h:246
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:243
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:249
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
Retrieve a widget by its position.
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:248
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:197
void SetPadding(const RectPadding &padding)
Set additional space (padding) around the widget.
Definition: widget_type.h:210
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:241
virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)=0
Assign size and position to the widget.
const NWID * GetParentWidget() const
Get parent widget of type NWID.
Definition: widget_type.h:178
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:923
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:234
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:236
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition: widget_type.h:251
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:851
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:244
uint GetVerticalStepSize(SizingType sizing) const
Get the vertical sizing step.
Definition: widget_type.h:273
Baseclass for container widgets.
Definition: widget_type.h:459
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition: widget.cpp:1197
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition: widget.cpp:1204
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1211
bool IsEmpty()
Return whether the container is empty.
Definition: widget_type.h:471
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in contaier.
Definition: widget_type.h:476
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1220
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1175
Base class for a 'real' widget.
Definition: widget_type.h:370
bool IsHighlighted() const override
Return whether the widget is highlighted.
Definition: widget_type.h:413
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:449
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:390
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:393
TextColour highlight_colour
Colour of highlight.
Definition: widget_type.h:396
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:392
StringAlignment align
Alignment of text/image within widget.
Definition: widget_type.h:399
FontSize text_size
Size of text within widget.
Definition: widget_type.h:398
void SetHighlighted(TextColour highlight_colour) override
Highlight the widget or not.
Definition: widget_type.h:406
WidgetID scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:395
TextColour text_colour
Colour of text within widget.
Definition: widget_type.h:397
Colours colour
Colour of this widget.
Definition: widget_type.h:391
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:428
TextColour GetHighlightColour() const override
Return the colour of the highlight.
Definition: widget_type.h:419
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:394
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition: widget_type.h:443
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:434
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition: widget_type.h:570
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:1589
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1584
Horizontal container.
Definition: widget_type.h:558
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1405
NWidgetHorizontal(NWidContainerFlags flags=NC_NONE)
Horizontal container widget.
Definition: widget.cpp:1401
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:1474
Leaf widget.
Definition: widget_type.h:916
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2835
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2537
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:928
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:931
NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2564
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:929
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:934
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:933
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:2664
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:927
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:932
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:2975
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:597
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1956
int count
Amount of valid elements.
Definition: widget_type.h:616
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition: widget.cpp:1819
int GetCurrentElement() const
Get current element.
Definition: widget.cpp:1869
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:613
Scrollbar * sb
The scrollbar we're associated with.
Definition: widget_type.h:618
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1874
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:620
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1860
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:2011
int current_element
The element currently being processed.
Definition: widget_type.h:617
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:622
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:621
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:1896
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition: widget.cpp:1920
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1926
int clicked
The currently clicked element.
Definition: widget_type.h:615
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1836
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:623
Colours colour
Colour of this widget.
Definition: widget_type.h:614
Container with pre/inter/post child space.
Definition: widget_type.h:530
uint8_t gaps
Number of gaps between widgets.
Definition: widget_type.h:551
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:539
uint8_t pip_pre
Amount of space before first widget.
Definition: widget_type.h:540
uint8_t uz_pip_pre
Unscaled space before first widget.
Definition: widget_type.h:547
uint8_t uz_pip_inter
Unscaled space between widgets.
Definition: widget_type.h:548
uint8_t pip_ratio_pre
Ratio of remaining space before first widget.
Definition: widget_type.h:543
uint8_t pip_post
Amount of space after last widget.
Definition: widget_type.h:542
uint8_t pip_ratio_inter
Ratio of remaining space between widgets.
Definition: widget_type.h:544
uint8_t pip_ratio_post
Ratio of remaining space after last widget.
Definition: widget_type.h:545
uint8_t uz_pip_post
Unscaled space after last widget.
Definition: widget_type.h:549
uint8_t pip_inter
Amount of space between widgets.
Definition: widget_type.h:541
Base class for a resizable nested widget.
Definition: widget_type.h:303
uint8_t uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition: widget_type.h:330
bool absolute
Set if minimum size is fixed and should not be resized.
Definition: widget_type.h:325
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:995
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1078
void SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Set desired aspect ratio of this widget.
Definition: widget.cpp:964
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:322
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
Definition: widget_type.h:331
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:953
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition: widget_type.h:326
uint8_t uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition: widget_type.h:329
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:1034
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:1021
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:323
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition: widget_type.h:327
bool UpdateMultilineWidgetSize(const std::string &str, int max_lines)
Try to set optimum widget size for a multiline text widget.
Definition: widget.cpp:1058
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition: widget.cpp:1099
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1092
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:1045
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1008
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:896
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2481
NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index)
Scrollbar widget.
Definition: widget.cpp:2439
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:2460
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:909
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:908
Spacer widget.
Definition: widget_type.h:633
NWidgetSpacer(int width, int height)
Generic spacer widget.
Definition: widget.cpp:1771
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition: widget.cpp:1784
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1805
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1800
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1788
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1777
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:498
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:512
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1246
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:513
WidgetLookup * widget_lookup
Window's widget lookup, updated in SetDisplayedPlane().
Definition: widget_type.h:515
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:1287
NWidgetStacked(WidgetID index)
Widgets stacked on top of each other.
Definition: widget.cpp:1234
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1318
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1342
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Fill the Window::widget_lookup with pointers to nested widgets in the tree.
Definition: widget.cpp:1307
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1327
Vertical container.
Definition: widget_type.h:581
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:1668
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1595
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1599
Nested widget to display a viewport in a window.
Definition: widget_type.h:680
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2297
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2261
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition: widget.cpp:2254
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2288
Scrollbar data structure.
Definition: widget_type.h:694
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:750
const bool is_vertical
Scrollbar has vertical orientation.
Definition: widget_type.h:700
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:731
size_type stepsize
Distance to scroll, when pressing the buttons or using the wheel.
Definition: widget_type.h:704
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:780
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:759
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:879
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:824
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition: widget_type.h:794
size_type cap
Number of visible elements of the scroll bar.
Definition: widget_type.h:702
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:2320
size_type count
Number of elements in the list.
Definition: widget_type.h:701
ScrollbarStepping
Stepping sizes when scrolling.
Definition: widget_type.h:708
@ SS_BIG
Step in cap units.
Definition: widget_type.h:711
@ SS_RAW
Step in single units.
Definition: widget_type.h:709
@ SS_SMALL
Step in stepsize units.
Definition: widget_type.h:710
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition: widget_type.h:810
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:2394
size_type GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:722
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:2341
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:841
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition: widget_type.h:860
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:768
size_type pos
Index of first visible item of the list.
Definition: widget_type.h:703
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:740
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:86
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Types related to the graphics and/or input devices.
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:342
FontSize
Available font sizes.
Definition: gfx_type.h:208
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1330
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1181
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:1260
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1284
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:1228
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
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:3239
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1160
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
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:1214
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
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:3258
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:1149
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1170
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition: widget_type.h:1295
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
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:1272
Integer math functions.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Dimensions (a width and height) of a rectangle in 2D.
Widget part for setting text/image alignment within a widget.
Definition: widget_type.h:1056
StringAlignment align
Alignment of text/image.
Definition: widget_type.h:1057
Widget part for storing data and tooltip information.
Definition: widget_type.h:1004
uint32_t data
Data value of the widget.
Definition: widget_type.h:1005
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:1006
Widget part for storing pre/inter/post spaces.
Definition: widget_type.h:1029
uint8_t post
Amount of space before/between/after child widgets.
Definition: widget_type.h:1030
Widget part for storing padding.
Definition: widget_type.h:1022
Widget part for storing minimal text line data.
Definition: widget_type.h:1037
uint8_t lines
Number of text lines.
Definition: widget_type.h:1038
uint8_t spacing
Extra spacing around lines.
Definition: widget_type.h:1039
FontSize size
Font size of text lines.
Definition: widget_type.h:1040
Widget part for storing text colour.
Definition: widget_type.h:1047
TextColour colour
TextColour for DrawString.
Definition: widget_type.h:1048
FontSize size
Font size of text.
Definition: widget_type.h:1049
Widget part for storing basic widget information.
Definition: widget_type.h:1013
Colours colour
Widget colour.
Definition: widget_type.h:1014
WidgetID index
Index of the widget.
Definition: widget_type.h:1015
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1075
WidgetType type
Type of the part.
Definition: widget_type.h:1076
Coordinates of a point in 2D.
Padding dimensions to apply to each side of a Rect.
Specification of a rectangle with absolute coordinates of all edges.
Data structure for an opened window.
Definition: window_gui.h:273
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:1083
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:1082
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:1081
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:1086
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:1087
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:1079
NWidgetPartAlignment align
Part with internal alignment.
Definition: widget_type.h:1085
NWidgetPartAspect aspect
Part to set aspect ratio.
Definition: widget_type.h:1088
NWidgetPartTextStyle text_style
Part with text style data.
Definition: widget_type.h:1084
Point xy
Part with an x/y size.
Definition: widget_type.h:1078
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:1080
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
StackedZeroSizePlanes
Display planes with zero size for NWidgetStacked.
Definition: widget_type.h:480
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:482
@ SZSP_BEGIN
First zero-size plane.
Definition: widget_type.h:485
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:481
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:483
NWidgetDisplay
Nested widget flags that affect display and interaction with 'real' widgets.
Definition: widget_type.h:335
@ NDB_DISABLED
Widget is disabled (greyed out) bit.
Definition: widget_type.h:338
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:356
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:358
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
Definition: widget_type.h:347
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:357
@ ND_DISABLED
Bit value of the disabled flag.
Definition: widget_type.h:353
@ NDB_DROPDOWN_ACTIVE
Dropdown menu of the button dropdown widget is active.
Definition: widget_type.h:344
@ NDB_SHADE_DIMMED
Display dimmed colours in the viewport.
Definition: widget_type.h:342
@ NDB_HIGHLIGHT
Highlight of widget is on.
Definition: widget_type.h:349
@ NDB_SHADE_GREY
Shade viewport to grey-scale.
Definition: widget_type.h:341
@ ND_SCROLLBAR_UP
Bit value of the 'scrollbar up' flag.
Definition: widget_type.h:359
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition: widget_type.h:355
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:346
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:361
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition: widget_type.h:350
@ NDB_LOWERED
Widget is lowered (pressed down) bit.
Definition: widget_type.h:337
@ ND_LOWERED
Bit value of the lowered flag.
Definition: widget_type.h:352
@ ND_HIGHLIGHT
Bit value of the highlight flag.
Definition: widget_type.h:354
@ NDB_NO_TRANSPARENCY
Viewport is never transparent.
Definition: widget_type.h:340
@ ND_SCROLLBAR_DOWN
Bit value of the 'scrollbar down' flag.
Definition: widget_type.h:360
@ ND_DROPDOWN_CLOSED
Bit value of the 'dropdown closed' flag.
Definition: widget_type.h:362
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:3300
uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:944
bool IsContainerWidgetType(WidgetType tp)
Test if WidgetType is a container widget.
Definition: widget.cpp:3182
ArrowWidgetValues
Values for an arrow widget.
Definition: widget_type.h:30
@ AWV_LEFT
Force the arrow to the left.
Definition: widget_type.h:33
@ AWV_RIGHT
Force the arrow to the right.
Definition: widget_type.h:34
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:31
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:32
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:519
@ NCB_BIGFIRST
Allocate space to biggest resize first.
Definition: widget_type.h:521
@ NC_NONE
All flags cleared.
Definition: widget_type.h:523
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:524
@ NCB_EQUALSIZE
Containers should keep all their (resizing) children equally large.
Definition: widget_type.h:520
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
Definition: widget_type.h:525
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:66
static constexpr uint8_t MAT_COL_BITS
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:23
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:46
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:112
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:51
@ WPT_FILL
Widget part for specifying fill.
Definition: widget_type.h:92
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition: widget_type.h:98
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:52
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:111
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:53
@ NWID_CUSTOM
General Custom widget.
Definition: widget_type.h:85
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:113
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition: widget_type.h:90
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:114
@ WWT_LABEL
Centered label.
Definition: widget_type.h:57
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:82
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:79
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:71
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition: widget_type.h:54
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:55
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition: widget_type.h:99
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WPT_ASPECT
Widget part for sepcifying aspect ratio.
Definition: widget_type.h:100
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
@ WPT_RESIZE
Widget part for specifying resizing.
Definition: widget_type.h:89
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:59
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition: widget_type.h:97
@ WPT_PADDING
Widget part for specifying a padding.
Definition: widget_type.h:94
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:56
@ WWT_FRAME
Frame.
Definition: widget_type.h:60
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:91
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:48
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:72
@ WPT_ATTRIBUTE_END
End marker for attribute NWidgetPart types.
Definition: widget_type.h:101
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:83
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition: widget_type.h:104
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition: widget_type.h:96
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition: widget_type.h:93
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:65
@ WPT_ATTRIBUTE_BEGIN
Begin marker for attribute NWidgetPart types.
Definition: widget_type.h:88
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:95
@ NWID_MATRIX
Matrix container.
Definition: widget_type.h:78
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:81
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:70
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:58
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition: widget_type.h:76
@ WPT_FUNCTION
Widget part for calling a user function.
Definition: widget_type.h:103
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:63
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
static constexpr uint8_t MAT_ROW_BITS
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:27
std::unique_ptr< NWidgetBase > NWidgetFunctionType()
Pointer to function returning a nested widget.
Definition: widget_type.h:1069
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition: widget_type.h:136
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:119
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:121
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:120
static constexpr uint8_t MAT_ROW_START
Lowest bit of the number of rows.
Definition: widget_type.h:26
static constexpr uint8_t MAT_COL_START
Bits of the WWT_MATRIX widget data.
Definition: widget_type.h:22
ResizeWidgetValues
WidgetData values for a resize box widget.
Definition: widget_type.h:38
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition: widget_type.h:39
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:40
Types related to windows.
int WidgetID
Widget ID.
Definition: window_type.h:18
EventState
State of handling an event.
Definition: window_type.h:743
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:16