OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
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
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Drop down divider component.
int16_t Height
Fixed point type for heights.
Dimensions (a width and height) of a rectangle in 2D.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
uint32_t PaletteID
The number of the palette.
Drop down icon component.
Dimension dbounds
Bounding box dimensions of bounds.
SpriteID sprite
Sprite ID to be drawn.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
std::string string
String to be drawn.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
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.
Dimension dim
Dimensions of string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ SA_CENTER
Center both horizontally and vertically.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Drop down checkmark component.
Dimension dim
Dimension of checkmark.
Specification of a rectangle with absolute coordinates of all edges.
bool checked
Is item checked.
Drop down string component.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
PaletteID palette
Palette ID to use.
Dimension dsprite
Bounding box dimensions of sprite.