OpenTTD Source: QueryString Struct Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Data Fields | Static Public Attributes
QueryString Struct Reference

Data stored about a string that can be modified in the GUI. More...

`#include <querystring_gui.h>`

## Public Member Functions
| QueryString (uint16_t size, uint16_t chars=UINT16_MAX)
| Initialize string.
void | DrawEditBox (const Window *w, WidgetID wid) const
void | ClickEditBox (Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed)
void | HandleEditBox (Window *w, WidgetID wid)
Point | GetCaretPosition (const Window *w, WidgetID wid) const
| Get the current caret position.
Rect | GetBoundingRect (const Window *w, WidgetID wid, size_t from, size_t to) const
| Get the bounding rectangle for a range of the query string.
ptrdiff_t | GetCharAtPosition (const Window *w, WidgetID wid, const Point &pt) const
| Get the character that is rendered at a position.

## Data Fields
StringID | caption {}
int | ok_button = ACTION_NOTHING
| Widget button of parent window to simulate when pressing OK in OSK.
int | cancel_button = ACTION_DESELECT
| Widget button of parent window to simulate when pressing CANCEL in OSK.
Textbuf | text
std::optional< std::string > | orig {}
bool | handled = false

## Static Public Attributes
static const int | ACTION_NOTHING = -1
| Nothing.
static const int | ACTION_DESELECT = -2
| Deselect editbox.
static const int | ACTION_CLEAR = -3
| Clear editbox.

## Detailed Description

Data stored about a string that can be modified in the GUI.

Definition at line 20 of file querystring_gui.h.

## Constructor & Destructor Documentation

## ◆ QueryString()

QueryString::QueryString | ( | uint16_t | size,
|  | uint16_t | chars = `UINT16_MAX`
| ) |  |
| inline

Initialize string.

Parameters

  size | Maximum size in bytes.
  chars | Maximum size in chars.

Definition at line 38 of file querystring_gui.h.

## Member Function Documentation

## ◆ ClickEditBox()

void QueryString::ClickEditBox | ( | Window * | w,
|  | Point | pt,
|  | WidgetID | wid,
|  | int | click_count,
|  | bool | focus_changed
| ) |  |

Definition at line 872 of file misc_gui.cpp.

## ◆ DrawEditBox()

void QueryString::DrawEditBox | ( | const Window * | w,
|  | WidgetID | wid
| ) |  | const

Definition at line 736 of file misc_gui.cpp.

## ◆ GetBoundingRect()

Rect QueryString::GetBoundingRect | ( | const Window * | w,
|  | WidgetID | wid,
|  | size_t | from,
|  | size_t | to
| ) |  | const

Get the bounding rectangle for a range of the query string.

Parameters

  w | Window the edit box is in.
  wid | Widget index.
  from | Start of the string range.
  to | End of the string range.

Returns
  Rectangle encompassing the string range, relative to the window.

Definition at line 821 of file misc_gui.cpp.

References _current_text_dir, Clamp(), FS_NORMAL, GetCharPosInString(), GetScaledSpriteSize(), Textbuf::GetText(), Window::GetWidget(), RectPadding::Horizontal(), WidgetDimensions::imgbtn, Rect::Indent(), WidgetDimensions::scaled, ScrollEditBoxTextRect(), Rect::Shrink(), TD_RTL, NWidgetBase::type, Rect::WithX(), and WWT_EDITBOX.

Referenced by Window::GetTextBoundingRect().

## ◆ GetCaretPosition()

Point QueryString::GetCaretPosition | ( | const Window * | w,
|  | WidgetID | wid
| ) |  | const

Get the current caret position.

Parameters

  w | Window the edit box is in.
  wid | Widget index.

Returns
  Top-left location of the caret, relative to the window.

Definition at line 793 of file misc_gui.cpp.

References _current_text_dir, Textbuf::caretxoffs, GetScaledSpriteSize(), Window::GetWidget(), RectPadding::Horizontal(), WidgetDimensions::imgbtn, Rect::Indent(), WidgetDimensions::scaled, ScrollEditBoxTextRect(), Rect::Shrink(), TD_RTL, NWidgetBase::type, and WWT_EDITBOX.

Referenced by Window::GetCaretPosition().

## ◆ GetCharAtPosition()

ptrdiff_t QueryString::GetCharAtPosition | ( | const Window * | w,
|  | WidgetID | wid,
|  | const Point & | pt
| ) |  | const

Get the character that is rendered at a position.

Parameters

  w | Window the edit box is in.
  wid | Widget index.
  pt | Position to test.

Returns
  Index of the character position or -1 if no character is at the position.

Definition at line 851 of file misc_gui.cpp.

References _current_text_dir, GetScaledSpriteSize(), Textbuf::GetText(), Window::GetWidget(), RectPadding::Horizontal(), WidgetDimensions::imgbtn, Rect::Indent(), IsInsideMM(), WidgetDimensions::scaled, ScrollEditBoxTextRect(), Rect::Shrink(), TD_RTL, NWidgetBase::type, WWT_EDITBOX, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by Window::GetTextCharacterAtPosition().

## ◆ HandleEditBox()

void QueryString::HandleEditBox | ( | Window * | w,
|  | WidgetID | wid
| ) |  |

Definition at line 702 of file misc_gui.cpp.

## Field Documentation

## ◆ ACTION_CLEAR

const int QueryString::ACTION_CLEAR = -3
| static

Clear editbox.

Definition at line 24 of file querystring_gui.h.

Referenced by Window::HandleEditBoxKey(), and NetworkContentListWindow::NetworkContentListWindow().

## ◆ ACTION_DESELECT

const int QueryString::ACTION_DESELECT = -2
| static

Deselect editbox.

Definition at line 23 of file querystring_gui.h.

Referenced by Window::HandleEditBoxKey().

## ◆ ACTION_NOTHING

const int QueryString::ACTION_NOTHING = -1
| static

Nothing.

Definition at line 22 of file querystring_gui.h.

Referenced by Window::HandleEditBoxKey().

## ◆ cancel_button

int QueryString::cancel_button = ACTION_DESELECT

Widget button of parent window to simulate when pressing CANCEL in OSK.

Definition at line 28 of file querystring_gui.h.

Referenced by Window::HandleEditBoxKey(), NetworkChatWindow::NetworkChatWindow(), NetworkContentListWindow::NetworkContentListWindow(), and OskWindow::OnClick().

## ◆ caption

StringID QueryString::caption {}

Definition at line 26 of file querystring_gui.h.

## ◆ handled

bool QueryString::handled = false

Definition at line 31 of file querystring_gui.h.

## ◆ ok_button

int QueryString::ok_button = ACTION_NOTHING

Widget button of parent window to simulate when pressing OK in OSK.

Definition at line 27 of file querystring_gui.h.

Referenced by Window::HandleEditBoxKey(), NetworkChatWindow::NetworkChatWindow(), OskWindow::OnClick(), and SavePresetWindow::SavePresetWindow().

## ◆ orig

std::optional<std::string> QueryString::orig {}

Definition at line 30 of file querystring_gui.h.

## ◆ text

Textbuf QueryString::text

Definition at line 29 of file querystring_gui.h.

The documentation for this struct was generated from the following files:

- src/querystring_gui.h
- src/misc_gui.cpp