10#ifndef DROPDOWN_COMMON_TYPE_H
11#define DROPDOWN_COMMON_TYPE_H
22#include "table/strings.h"
29template <
class TBase, FontSize TFs = FS_NORMAL>
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>
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;
99 static bool NatSortFunc(std::unique_ptr<const DropDownListItem>
const &first, std::unique_ptr<const DropDownListItem>
const &second) {
…}
112template <
class TBase,
bool TEnd = false>
119 template <
typename... Args>
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>
161 template <
typename... Args>
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>
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>
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
267template <
class TBase, FontSize TFs = FS_NORMAL>
270 template <
typename... Args>
273 bool Selectable()
const override {
return false; }
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 indent component.
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.
Drop down boolean toggle component.
Colours button_colour
Colour of toggle button.
int click
Click result when toggle used.
Colours background_colour
Colour of toggle background.
Drop down component that makes the item unselectable.
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 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.
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.
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.
Coordinates of a point 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 CentreTo(int width, int height) const
Centre a dimension within this Rect.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
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.