10#ifndef DROPDOWN_COMMON_TYPE_H
11#define DROPDOWN_COMMON_TYPE_H
22#include "table/strings.h"
29template <
class TBase, FontSize TFs = FS_NORMAL>
30class DropDownDivider :
public TBase {
32 template <
typename... Args>
33 explicit DropDownDivider(Args&&... args) : TBase(std::forward<Args>(args)...) {}
35 bool Selectable()
const override {
return false; }
38 void Draw(
const Rect &full,
const Rect &,
bool,
int, Colours bg_colour)
const override
55template <
class TBase, FontSize TFs = FS_NORMAL,
bool TEnd = false>
56class DropDownString :
public TBase {
60 template <
typename... Args>
61 explicit DropDownString(std::string &&
string, Args&&... args) : TBase(std::forward<Args>(args)...)
63 this->SetString(std::move(
string));
66 void SetString(std::string &&
string)
68 this->
string = std::move(
string);
72 uint
Height()
const override
74 return std::max<uint>(this->
dim.height, this->TBase::Height());
77 uint Width()
const override {
return this->
dim.width + this->TBase::Width(); }
79 int OnClick(
const Rect &r,
const Point &pt)
const override
82 return this->TBase::OnClick(r.
Indent(this->dim.width, rtl), pt);
85 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
89 this->TBase::Draw(full, r.
Indent(this->dim.width, rtl), sel, click_result, bg_colour);
99 static bool NatSortFunc(std::unique_ptr<const DropDownListItem>
const &first, std::unique_ptr<const DropDownListItem>
const &second)
101 const std::string &str1 =
static_cast<const DropDownString*
>(first.get())->string;
102 const std::string &str2 =
static_cast<const DropDownString*
>(second.get())->string;
112template <
class TBase,
bool TEnd = false>
113class DropDownIcon :
public TBase {
119 template <
typename... Args>
123 this->dbounds = this->dsprite;
126 template <
typename... Args>
132 uint
Height()
const override {
return std::max(this->
dbounds.height, this->TBase::Height()); }
135 int OnClick(
const Rect &r,
const Point &pt)
const override
141 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
156template <
class TBase,
bool TEnd = false, FontSize TFs = FS_NORMAL>
157class DropDownCheck :
public TBase {
161 template <
typename... Args>
162 explicit DropDownCheck(
bool checked, Args&&... args) : TBase(std::forward<Args>(args)...),
checked(
checked)
167 uint
Height()
const override {
return std::max<uint>(this->dim.height, this->TBase::Height()); }
170 int OnClick(
const Rect &r,
const Point &pt)
const override
176 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
191template <
class TBase,
bool TEnd = false>
192class DropDownToggle :
public TBase {
198 template <
typename... Args>
204 uint
Height()
const override
209 uint Width()
const override
214 int OnClick(
const Rect &r,
const Point &pt)
const override
224 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
230 DrawBoolButton(br.left, br.top, this->button_colour, this->background_colour, this->on,
true);
241template <
class TBase,
bool TEnd = false>
242class DropDownIndent :
public TBase {
245 template <
typename... Args>
246 explicit DropDownIndent(uint indent, Args&&... args) : TBase(std::forward<Args>(args)...), indent(indent) {}
250 int OnClick(
const Rect &r,
const Point &pt)
const override
256 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
268template <
class TBase,
bool TEnd = false>
269class DropDownSpacer :
public TBase {
271 template <
typename... Args>
272 explicit DropDownSpacer(Args&&... args) : TBase(std::forward<Args>(args)...) {}
276 int OnClick(
const Rect &r,
const Point &pt)
const override
282 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
293template <
class TBase, FontSize TFs = FS_NORMAL>
294class DropDownUnselectable :
public TBase {
296 template <
typename... Args>
297 explicit DropDownUnselectable(Args&&... args) : TBase(std::forward<Args>(args)...) {}
299 bool Selectable()
const override {
return false; }
Dimension dim
Dimension of checkmark.
bool checked
Is item checked.
Drop down divider component.
Drop down icon component.
Drop down indent component.
Drop down string component.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Colours background_colour
Types related to the drop down widget.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Functions related to the gfx engine.
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ SA_CENTER
Center both horizontally and vertically.
uint32_t PaletteID
The number of the palette.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Functions related to palettes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
Colour for pixel/line drawing.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
int16_t Height
Fixed point type for heights.
Functions, definitions and such used only by the GUI.