10 #ifndef DROPDOWN_COMMON_TYPE_H
11 #define DROPDOWN_COMMON_TYPE_H
18 #include "table/strings.h"
26 template <
class TBase, FontSize TFs = FS_NORMAL>
29 template <
typename... Args>
30 explicit DropDownDivider(Args&&... args) : TBase(std::forward<Args>(args)...) {}
32 bool Selectable()
const override {
return false; }
35 void Draw(
const Rect &full,
const Rect &,
bool, Colours bg_colour)
const override
52 template <
class TBase, FontSize TFs = FS_NORMAL,
bool TEnd = false>
57 template <
typename... Args>
63 template <
typename... Args>
64 explicit DropDownString(
const std::string &
string, Args&&... args) : TBase(std::forward<Args>(args)...)
67 this->SetString(
GetString(STR_JUST_RAW_STRING));
70 void SetString(std::string &&
string)
72 this->
string = std::move(
string);
76 uint
Height()
const override
78 return std::max<uint>(this->dim.height, this->TBase::Height());
81 uint Width()
const override {
return this->dim.width + this->TBase::Width(); }
83 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
87 this->TBase::Draw(full, r.
Indent(this->dim.width, rtl), sel, bg_colour);
97 static bool NatSortFunc(std::unique_ptr<const DropDownListItem>
const &first, std::unique_ptr<const DropDownListItem>
const &second)
99 const std::string &str1 =
static_cast<const DropDownString*
>(first.get())->
string;
100 const std::string &str2 =
static_cast<const DropDownString*
>(second.get())->
string;
110 template <
class TBase,
bool TEnd = false>
117 template <
typename... Args>
124 template <
typename... Args>
130 uint
Height()
const override {
return std::max(this->dbounds.height, this->TBase::Height()); }
133 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
148 template <
class TBase,
bool TEnd = false, FontSize TFs = FS_NORMAL>
153 template <
typename... Args>
159 uint
Height()
const override {
return std::max<uint>(this->dim.height, this->TBase::Height()); }
162 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
Drop down checkmark component.
Dimension dim
Dimension of checkmark.
bool checked
Is item checked.
Drop down divider component.
Drop down icon component.
PaletteID palette
Palette ID to use.
Dimension dbounds
Bounding box dimensions of bounds.
Dimension dsprite
Bounding box dimensions of sprite.
SpriteID sprite
Sprite ID to be drawn.
Drop down string component.
std::string string
String to be drawn.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Dimension dim
Dimensions of string.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
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 GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
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.
Functions related to the gfx engine.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
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.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Functions related to palettes.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Specification of a rectangle with absolute coordinates of all edges.
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.
int16_t Height
Fixed point type for heights.
Functions, definitions and such used only by the GUI.