10#ifndef DROPDOWN_COMMON_TYPE_H
11#define DROPDOWN_COMMON_TYPE_H
23#include "table/strings.h"
30template <
class TBase, FontSize TFs = FS_NORMAL>
31class DropDownDivider :
public TBase {
33 template <
typename... Args>
34 explicit DropDownDivider(Args&&... args) : TBase(std::forward<Args>(args)...) {}
36 bool Selectable()
const override {
return false; }
39 void Draw(
const Rect &full,
const Rect &,
bool,
int, Colours bg_colour)
const override
56template <
class TBase, FontSize TFs = FS_NORMAL,
bool TEnd = false>
57class DropDownString :
public TBase {
61 template <
typename... Args>
62 explicit DropDownString(std::string &&
string, Args&&... args) : TBase(std::forward<Args>(args)...)
64 this->SetString(std::move(
string));
70 string_filter.AddLine(this->
string);
71 this->TBase::FilterText(string_filter);
74 void SetString(std::string &&
string)
76 this->
string = std::move(
string);
80 uint
Height()
const override
82 return std::max<uint>(this->
dim.height, this->TBase::Height());
85 uint Width()
const override {
return this->
dim.width + this->TBase::Width(); }
87 int OnClick(
const Rect &r,
const Point &pt)
const override
90 return this->TBase::OnClick(r.
Indent(this->dim.width, rtl), pt);
93 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
97 this->TBase::Draw(full, r.
Indent(this->dim.width, rtl), sel, click_result, bg_colour);
107 static bool NatSortFunc(std::unique_ptr<const DropDownListItem>
const &first, std::unique_ptr<const DropDownListItem>
const &second)
109 const std::string &str1 =
static_cast<const DropDownString*
>(first.get())->string;
110 const std::string &str2 =
static_cast<const DropDownString*
>(second.get())->string;
120template <
class TBase,
bool TEnd = false>
121class DropDownIcon :
public TBase {
127 template <
typename... Args>
131 this->dbounds = this->dsprite;
134 template <
typename... Args>
140 uint
Height()
const override {
return std::max(this->
dbounds.height, this->TBase::Height()); }
143 int OnClick(
const Rect &r,
const Point &pt)
const override
149 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
164template <
class TBase,
bool TEnd = false, FontSize TFs = FS_NORMAL>
165class DropDownCheck :
public TBase {
169 template <
typename... Args>
170 explicit DropDownCheck(
bool checked, Args&&... args) : TBase(std::forward<Args>(args)...),
checked(
checked)
175 uint
Height()
const override {
return std::max<uint>(this->dim.height, this->TBase::Height()); }
178 int OnClick(
const Rect &r,
const Point &pt)
const override
184 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
199template <
class TBase,
bool TEnd = false>
200class DropDownToggle :
public TBase {
206 template <
typename... Args>
212 uint
Height()
const override
217 uint Width()
const override
222 int OnClick(
const Rect &r,
const Point &pt)
const override
232 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
238 DrawBoolButton(br.left, br.top, this->button_colour, this->background_colour, this->on,
true);
249template <
class TBase,
bool TEnd = false>
250class DropDownIndent :
public TBase {
253 template <
typename... Args>
254 explicit DropDownIndent(uint indent, Args&&... args) : TBase(std::forward<Args>(args)...), indent(indent) {}
258 int OnClick(
const Rect &r,
const Point &pt)
const override
264 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
276template <
class TBase,
bool TEnd = false>
277class DropDownSpacer :
public TBase {
279 template <
typename... Args>
280 explicit DropDownSpacer(Args&&... args) : TBase(std::forward<Args>(args)...) {}
284 int OnClick(
const Rect &r,
const Point &pt)
const override
290 void Draw(
const Rect &full,
const Rect &r,
bool sel,
int click_result, Colours bg_colour)
const override
301template <
class TBase, FontSize TFs = FS_NORMAL>
302class DropDownUnselectable :
public TBase {
304 template <
typename... Args>
305 explicit DropDownUnselectable(Args&&... args) : TBase(std::forward<Args>(args)...) {}
307 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().
void FilterText(StringFilter &string_filter) const override
Add text from this dropdown item to a string filter.
Colours background_colour
DropDownIcon< DropDownString< DropDownListItem > > DropDownListIconItem
Drop down list item that contains a single string and an icon.
DropDownDivider< DropDownListItem > DropDownListDividerItem
Drop down list item that divides list horizontally into two parts.
DropDownIndent< DropDownCheck< DropDownString< DropDownListItem > > > DropDownListCheckedItem
Drop down list item with a single string and a space for tick.
DropDownString< DropDownListItem > DropDownListStringItem
Drop down list item that contains a single string.
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.
Searching and filtering using a stringterm.
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.