Jazz2::UI::Windows::TextBox class

Single line of text that can be edited.

Base classes

class Element
Element of the interface.

Derived classes

class NumberBox
Number that can be dragged or typed.

Constructors, destructors, conversion operators

TextBox(StringView text = {}) explicit
Creates a new instance.
~TextBox() override

Public functions

void BeginEdit()
Starts editing with all of the text selected.
auto ShowScreenKeyboard() -> bool
Starts editing with the screen keyboard of the system, for a gamepad or a touch screen.
auto Measure(const Context& context, Vector2f available) -> Vector2f override
Returns the size the element wants, in pixels.
auto MeasureDependsOnAvailable() const -> bool override
Returns false if what Measure() returns doesn't depend on the available size, it's measured once a frame then.
void Draw(Painter& painter) override
Draws the element and its children.
void Update(float timeMult) override
Advances animations of the element and its children.
auto AcceptsPointer() const -> bool override
Returns true if the element takes the pointer itself.
auto OnPointerDown(const PointerEvent& event) -> bool override
Called when the pointer is pressed over the element, returns true to keep getting it until released.
void OnPointerMove(const PointerEvent& event) override
Called when the pointer moves while pressed over the element.
auto OnKeyPressed(const KeyboardEvent& event) -> bool override
Called when a key is pressed while the element has the focus, returns true if it was used.
auto OnTextInput(const TextInputEvent& event) -> bool override
Called when text is typed while the element has the focus.
auto IsFocusable() const -> bool override
Returns true if the element can take the keyboard focus.
void OnFocusChanged(bool focused) override
Called when the element gets or loses the keyboard focus.

Public variables

String Text
Text.
String Placeholder
Text shown while it's empty.
Function<String()> PlaceholderFunc
Returns the text shown while it's empty, replaces Placeholder when set.
Function<String()> TextFunc
Returns the text to show while it's not being edited, replaces Text then.
Function<void(StringView)> OnCommit
Called when the edit is confirmed, by Enter or by leaving it, only if something was typed since the edit started.
Function<void(StringView)> OnChanged
Called whenever the text changes while it's edited.
Function<bool(const KeyboardEvent&)> OnKeyPreview
Gets the keys first while it's edited, returns true for a key it used, such as a dialog moving through a list by Up.
std::int32_t MaxLength
Longest text in bytes.
bool Multiline
Whether the text can have more lines, it grows with them — Enter breaks a line then, Ctrl+Enter confirms.

Protected static functions

static auto GetLineOf(ArrayView<const std::int32_t> starts, std::int32_t offset) -> std::int32_t
Returns the line of a byte offset.

Protected functions

auto GetShownText() -> StringView
Returns the text shown, the one being edited, or the one from TextFunc made at most once a frame of layout.
auto GetOffsetAt(Vector2f pos) const -> std::int32_t
Returns the byte offset in the text closest to a position.
auto GetOffsetInLine(std::int32_t line, float x) const -> std::int32_t
Returns the byte offset in a line of the text closest to a horizontal position from the start of the line.
void GetLineStarts(StringView text, SmallVectorImpl<std::int32_t>& starts) const
Fills the byte offsets the lines of a text start at, a single line unless it's Multiline.
auto GetLineEnd(ArrayView<const std::int32_t> starts, std::int32_t line) const -> std::int32_t
Returns the end of a line, before its line break.
void GetLineLayout(const Context& context, std::int32_t lineCount, float& lineHeight, float& top) const
Returns the height of a line in pixels and where the first line is.
auto DeleteSelection() -> bool
Deletes the selection, returns false if nothing was selected.
void Insert(StringView text)
Inserts a text at the caret, characters a text can't have are left out.
void NotifyChanged()
Called after the text changed.
void ClampCaret()
Keeps the caret and the start of the selection inside of the text, it may have been replaced.
auto FindWordBoundary(std::int32_t offset, bool forward) const -> std::int32_t
Returns the byte offset of the start of the next word, or of the word before.

Protected variables

std::int32_t _caret
std::int32_t _selectionStart
float _scrollX
float _blinkTime
bool _cancelled
String _editStartText
String _shownText
std::uint32_t _shownTextLayout
Context _lastContext

Function documentation

bool Jazz2::UI::Windows::TextBox::ShowScreenKeyboard()

Starts editing with the screen keyboard of the system, for a gamepad or a touch screen.

Returns false if the system has none. Where the keyboard collects the whole text, the text is replaced by it and confirmed.

Vector2f Jazz2::UI::Windows::TextBox::Measure(const Context& context, Vector2f available) override

Returns the size the element wants, in pixels.

The available size is what the parent can give, a size without limit is a very large number.