|
R-Type
Distributed multiplayer game engine in C++
|
Raylib implementation of the ITextInput interface. More...
#include <RaylibTextInput.hpp>


Public Member Functions | |
| RaylibTextInput (Graphics::IGraphics &graphics) | |
| Construct a new RaylibTextInput. | |
| ~RaylibTextInput () override=default | |
| Destroy the RaylibTextInput. | |
| void | Update () override |
| Update the text input internal state (focus, cursor, input). | |
| void | Render () override |
| Render the text input box. | |
| void | SetOnTextChanged (std::function< void(const std::string &)> callback) override |
| Set callback invoked when text changes. | |
| void | SetPosition (float x, float y) override |
| Set the top-left position of the text input. | |
| void | GetPosition (float &x, float &y) const override |
| Get the current top-left position of the text input. | |
| void | SetSize (float width, float height) override |
| Set the text input size. | |
| void | GetSize (float &width, float &height) const override |
| Get the current size of the text input. | |
| void | SetBackgroundColor (unsigned int color) override |
| Set the background color of the text input box. | |
| void | SetBorderColor (unsigned int color) override |
| Set the border color when the input is not focused. | |
| void | SetActiveBorderColor (unsigned int color) override |
| Set the border color when the input is focused/active. | |
| void | SetTextColor (unsigned int color) override |
| Set the text color. | |
| void | SetPlaceholderColor (unsigned int color) override |
| Set the placeholder text color (when input is empty). | |
| void | SetTextSize (int size) override |
| Set the text size in pixels. | |
| void | SetPlaceholder (const std::string &placeholder) override |
| Set the placeholder text displayed when the input is empty. | |
| void | SetMaxLength (size_t maxLength) override |
| Set the maximum number of characters allowed. | |
| void | SetValidationRegex (const std::string ®exPattern) override |
| Set a regex pattern to restrict allowed characters. | |
| const std::string & | GetText () const override |
| Get the current text content. | |
| void | SetText (const std::string &text) override |
| Set the text content programmatically. | |
| void | Clear () override |
| Clear the text content. | |
| bool | IsFocused () const override |
| Check if the text input is currently focused/active. | |
| void | SetFocused (bool focused) override |
| Set focus state programmatically. | |
| void | SetFont (int fontHandle) override |
| Set the font handle for rendering text. | |
| void | SetAlign (Align align) override |
| Set alignment mode relative to the window. | |
| Align | GetAlign () const override |
| Get the current alignment mode. | |
| void | ApplyAlignment () override |
| Apply the current alignment mode to the position. | |
| void | SetEnabled (bool enabled) override |
| Enable or disable the text input. | |
| bool | IsEnabled () const override |
| Check if the text input is enabled. | |
| void | SetPasswordMode (bool passwordMode) override |
| Enable or disable password mode (masks characters with asterisks). | |
| bool | IsPasswordMode () const override |
| Check if password mode is enabled. | |
Public Member Functions inherited from UI::ITextInput | |
| virtual | ~ITextInput ()=default |
| Virtual destructor. | |
Private Member Functions | |
| bool | IsMouseOver () const |
| Check whether the mouse cursor is currently over the input rectangle. | |
| bool | IsCharValid (char c) const |
| Validate a character against the current regex pattern. | |
| void | HandleFocusClick () |
| Handle mouse click to set focus state. | |
| void | UpdateCursorBlink () |
| Update cursor blink animation. | |
| void | HandlePaste () |
| Handle paste operation (Ctrl+V or Cmd+V). | |
| void | HandleBackspace () |
| Handle backspace key with repeat support. | |
| void | HandleCharacterInput () |
| Handle regular character input. | |
| bool | TryAddCharacter (char c) |
| Add a character to the text if valid. | |
| void | ResetCursor () |
| Show cursor and reset blink timer. | |
Private Attributes | |
| Graphics::IGraphics & | _graphics |
| std::function< void(const std::string &)> | _onTextChanged {} |
| float | _x {0.0F} |
| float | _y {0.0F} |
| float | _width {200.0F} |
| float | _height {40.0F} |
| unsigned int | _backgroundColor {0xFF2A2A2A} |
| unsigned int | _borderColor {0xFF505050} |
| unsigned int | _activeBorderColor {0xFF4CAF50} |
| unsigned int | _textColor {0xFFFFFFFF} |
| unsigned int | _placeholderColor {0xFF808080} |
| std::string | _text |
| std::string | _placeholder |
| int | _textSize {20} |
| int | _fontHandle {-1} |
| size_t | _maxLength {0} |
| std::string | _regexPattern |
| std::unique_ptr< std::regex > | _validationRegex {} |
| bool | _focused {false} |
| bool | _enabled {true} |
| bool | _passwordMode {false} |
| float | _cursorBlinkTimer {0.0F} |
| bool | _cursorVisible {true} |
| float | _backspaceTimer {0.0F} |
| int | _lastBackspaceRepeat {0} |
| Align | _align {Align::NONE} |
Static Private Attributes | |
| static constexpr float | CURSOR_BLINK_RATE = 0.5F |
| static constexpr float | BORDER_THICKNESS = 2.0F |
| static constexpr float | TEXT_PADDING = 8.0F |
| static constexpr float | BACKSPACE_REPEAT_DELAY = 0.5F |
| static constexpr float | BACKSPACE_REPEAT_RATE = 0.05F |
Raylib implementation of the ITextInput interface.
Features:
Definition at line 31 of file RaylibTextInput.hpp.
|
explicit |
Construct a new RaylibTextInput.
| graphics | Graphics wrapper used for input and drawing. |
Definition at line 14 of file RaylibTextInput.cpp.
|
overridedefault |
Destroy the RaylibTextInput.
|
overridevirtual |
Apply the current alignment mode to the position.
Implements UI::ITextInput.
Definition at line 337 of file RaylibTextInput.cpp.
References _align, _graphics, _height, _width, _x, _y, UI::CENTER_BOTH, UI::CENTER_HORIZONTAL, UI::CENTER_VERTICAL, Graphics::IGraphics::GetScreenHeight(), Graphics::IGraphics::GetScreenWidth(), and UI::NONE.

|
overridevirtual |
Clear the text content.
Implements UI::ITextInput.
Definition at line 309 of file RaylibTextInput.cpp.
References _text.
|
overridevirtual |
Get the current alignment mode.
Implements UI::ITextInput.
Definition at line 333 of file RaylibTextInput.cpp.
References _align.
|
overridevirtual |
Get the current top-left position of the text input.
| x | Output X position in pixels. |
| y | Output Y position in pixels. |
Implements UI::ITextInput.
Definition at line 233 of file RaylibTextInput.cpp.
|
overridevirtual |
Get the current size of the text input.
| width | Output width in pixels. |
| height | Output height in pixels. |
Implements UI::ITextInput.
Definition at line 243 of file RaylibTextInput.cpp.
|
overridevirtual |
Get the current text content.
Implements UI::ITextInput.
Definition at line 297 of file RaylibTextInput.cpp.
References _text.
|
private |
Handle backspace key with repeat support.
Definition at line 86 of file RaylibTextInput.cpp.
References _backspaceTimer, _graphics, _lastBackspaceRepeat, _onTextChanged, _text, BACKSPACE_REPEAT_DELAY, BACKSPACE_REPEAT_RATE, Graphics::IGraphics::GetDeltaTime(), Graphics::IGraphics::IsKeyDown(), Graphics::IGraphics::IsKeyPressed(), and ResetCursor().
Referenced by Update().

|
private |
Handle regular character input.
Definition at line 126 of file RaylibTextInput.cpp.
References _graphics, _onTextChanged, _text, Graphics::IGraphics::GetCharPressed(), ResetCursor(), and TryAddCharacter().
Referenced by Update().

|
private |
Handle mouse click to set focus state.
Definition at line 31 of file RaylibTextInput.cpp.
References _graphics, Graphics::IGraphics::IsMouseButtonPressed(), IsMouseOver(), and SetFocused().
Referenced by Update().

|
private |
Handle paste operation (Ctrl+V or Cmd+V).
Definition at line 47 of file RaylibTextInput.cpp.
References _graphics, _onTextChanged, _text, Graphics::IGraphics::IsKeyDown(), Graphics::IGraphics::IsKeyPressed(), ResetCursor(), and TryAddCharacter().
Referenced by Update().

|
private |
Validate a character against the current regex pattern.
| c | Character to validate. |
Definition at line 385 of file RaylibTextInput.cpp.
References _validationRegex.
Referenced by TryAddCharacter().
|
overridevirtual |
Check if the text input is enabled.
Implements UI::ITextInput.
Definition at line 365 of file RaylibTextInput.cpp.
References _enabled.
|
overridevirtual |
Check if the text input is currently focused/active.
Implements UI::ITextInput.
Definition at line 313 of file RaylibTextInput.cpp.
References _focused.
|
private |
Check whether the mouse cursor is currently over the input rectangle.
Definition at line 377 of file RaylibTextInput.cpp.
References _graphics, _height, _width, _x, _y, Graphics::IGraphics::GetMouseX(), and Graphics::IGraphics::GetMouseY().
Referenced by HandleFocusClick().

|
overridevirtual |
Check if password mode is enabled.
Implements UI::ITextInput.
Definition at line 373 of file RaylibTextInput.cpp.
References _passwordMode.
|
overridevirtual |
Render the text input box.
Implements UI::ITextInput.
Definition at line 163 of file RaylibTextInput.cpp.
References _activeBorderColor, _backgroundColor, _borderColor, _cursorVisible, _enabled, _focused, _graphics, _height, _passwordMode, _placeholder, _placeholderColor, _text, _textColor, _textSize, _width, _x, _y, Graphics::IGraphics::DrawRectangle(), Graphics::IGraphics::DrawRectangleLines(), Graphics::IGraphics::DrawText(), and TEXT_PADDING.

|
private |
Show cursor and reset blink timer.
Definition at line 158 of file RaylibTextInput.cpp.
References _cursorBlinkTimer, and _cursorVisible.
Referenced by HandleBackspace(), HandleCharacterInput(), and HandlePaste().
|
overridevirtual |
Set the border color when the input is focused/active.
| color | Color in ARGB format (0xAARRGGBB). |
Implements UI::ITextInput.
Definition at line 256 of file RaylibTextInput.cpp.
References _activeBorderColor.
|
overridevirtual |
Set alignment mode relative to the window.
| align | Alignment mode. |
Implements UI::ITextInput.
Definition at line 329 of file RaylibTextInput.cpp.
References _align.
|
overridevirtual |
Set the background color of the text input box.
| color | Color in ARGB format (0xAARRGGBB). |
Implements UI::ITextInput.
Definition at line 248 of file RaylibTextInput.cpp.
References _backgroundColor.
|
overridevirtual |
Set the border color when the input is not focused.
| color | Color in ARGB format (0xAARRGGBB). |
Implements UI::ITextInput.
Definition at line 252 of file RaylibTextInput.cpp.
References _borderColor.
|
overridevirtual |
Enable or disable the text input.
| enabled | true to enable, false to disable. |
Implements UI::ITextInput.
Definition at line 358 of file RaylibTextInput.cpp.
|
overridevirtual |
Set focus state programmatically.
| focused | true to focus, false to blur. |
Implements UI::ITextInput.
Definition at line 317 of file RaylibTextInput.cpp.
References _cursorBlinkTimer, _cursorVisible, and _focused.
Referenced by HandleFocusClick().
|
overridevirtual |
Set the font handle for rendering text.
| fontHandle | Font handle (-1 for default font). |
Implements UI::ITextInput.
Definition at line 325 of file RaylibTextInput.cpp.
References _fontHandle.
|
overridevirtual |
Set the maximum number of characters allowed.
| maxLength | Maximum character count (0 = unlimited). |
Implements UI::ITextInput.
Definition at line 276 of file RaylibTextInput.cpp.
References _maxLength, and _text.
|
overridevirtual |
Set callback invoked when text changes.
| callback | Function called when the text content changes. |
Implements UI::ITextInput.
Definition at line 224 of file RaylibTextInput.cpp.
References _onTextChanged.
|
overridevirtual |
Enable or disable password mode (masks characters with asterisks).
| passwordMode | true to mask characters, false to show them normally. |
Implements UI::ITextInput.
Definition at line 369 of file RaylibTextInput.cpp.
References _passwordMode.
|
overridevirtual |
Set the placeholder text displayed when the input is empty.
| placeholder | Placeholder string. |
Implements UI::ITextInput.
Definition at line 272 of file RaylibTextInput.cpp.
References _placeholder.
|
overridevirtual |
Set the placeholder text color (when input is empty).
| color | Color in ARGB format (0xAARRGGBB). |
Implements UI::ITextInput.
Definition at line 264 of file RaylibTextInput.cpp.
References _placeholderColor.
|
overridevirtual |
Set the top-left position of the text input.
| x | X position in pixels. |
| y | Y position in pixels. |
Implements UI::ITextInput.
Definition at line 228 of file RaylibTextInput.cpp.
|
overridevirtual |
Set the text input size.
| width | Width in pixels. |
| height | Height in pixels. |
Implements UI::ITextInput.
Definition at line 238 of file RaylibTextInput.cpp.
|
overridevirtual |
Set the text content programmatically.
| text | New text content. |
Implements UI::ITextInput.
Definition at line 301 of file RaylibTextInput.cpp.
References _maxLength, and _text.
|
overridevirtual |
Set the text color.
| color | Color in ARGB format (0xAARRGGBB). |
Implements UI::ITextInput.
Definition at line 260 of file RaylibTextInput.cpp.
References _textColor.
|
overridevirtual |
Set the text size in pixels.
| size | Font size. |
Implements UI::ITextInput.
Definition at line 268 of file RaylibTextInput.cpp.
References _textSize.
|
overridevirtual |
Set a regex pattern to restrict allowed characters.
| regexPattern | Regex pattern string (e.g., "[a-zA-Z0-9]+" for alphanumeric only). Empty string = no restriction. |
Implements UI::ITextInput.
Definition at line 284 of file RaylibTextInput.cpp.
References _regexPattern, and _validationRegex.
|
private |
Add a character to the text if valid.
| c | Character to add. |
Definition at line 143 of file RaylibTextInput.cpp.
References _maxLength, _text, and IsCharValid().
Referenced by HandleCharacterInput(), and HandlePaste().

|
overridevirtual |
Update the text input internal state (focus, cursor, input).
Implements UI::ITextInput.
Definition at line 16 of file RaylibTextInput.cpp.
References _enabled, _focused, HandleBackspace(), HandleCharacterInput(), HandleFocusClick(), HandlePaste(), and UpdateCursorBlink().

|
private |
Update cursor blink animation.
Definition at line 39 of file RaylibTextInput.cpp.
References _cursorBlinkTimer, _cursorVisible, _graphics, CURSOR_BLINK_RATE, and Graphics::IGraphics::GetDeltaTime().
Referenced by Update().

|
private |
Definition at line 193 of file RaylibTextInput.hpp.
Referenced by Render(), and SetActiveBorderColor().
|
private |
Definition at line 216 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), GetAlign(), and SetAlign().
|
private |
Definition at line 191 of file RaylibTextInput.hpp.
Referenced by Render(), and SetBackgroundColor().
|
private |
Definition at line 213 of file RaylibTextInput.hpp.
Referenced by HandleBackspace().
|
private |
Definition at line 192 of file RaylibTextInput.hpp.
Referenced by Render(), and SetBorderColor().
|
private |
Definition at line 209 of file RaylibTextInput.hpp.
Referenced by ResetCursor(), SetFocused(), and UpdateCursorBlink().
|
private |
Definition at line 210 of file RaylibTextInput.hpp.
Referenced by Render(), ResetCursor(), SetFocused(), and UpdateCursorBlink().
|
private |
Definition at line 207 of file RaylibTextInput.hpp.
Referenced by IsEnabled(), Render(), SetEnabled(), and Update().
|
private |
Definition at line 206 of file RaylibTextInput.hpp.
Referenced by IsFocused(), Render(), SetEnabled(), SetFocused(), and Update().
|
private |
Definition at line 200 of file RaylibTextInput.hpp.
Referenced by SetFont().
|
private |
Definition at line 183 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), HandleBackspace(), HandleCharacterInput(), HandleFocusClick(), HandlePaste(), IsMouseOver(), Render(), and UpdateCursorBlink().
|
private |
Definition at line 189 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), GetSize(), IsMouseOver(), Render(), and SetSize().
|
private |
Definition at line 214 of file RaylibTextInput.hpp.
Referenced by HandleBackspace().
|
private |
Definition at line 202 of file RaylibTextInput.hpp.
Referenced by SetMaxLength(), SetText(), and TryAddCharacter().
|
private |
Definition at line 184 of file RaylibTextInput.hpp.
Referenced by HandleBackspace(), HandleCharacterInput(), HandlePaste(), and SetOnTextChanged().
|
private |
Definition at line 208 of file RaylibTextInput.hpp.
Referenced by IsPasswordMode(), Render(), and SetPasswordMode().
|
private |
Definition at line 198 of file RaylibTextInput.hpp.
Referenced by Render(), and SetPlaceholder().
|
private |
Definition at line 195 of file RaylibTextInput.hpp.
Referenced by Render(), and SetPlaceholderColor().
|
private |
Definition at line 203 of file RaylibTextInput.hpp.
Referenced by SetValidationRegex().
|
private |
Definition at line 197 of file RaylibTextInput.hpp.
Referenced by Clear(), GetText(), HandleBackspace(), HandleCharacterInput(), HandlePaste(), Render(), SetMaxLength(), SetText(), and TryAddCharacter().
|
private |
Definition at line 194 of file RaylibTextInput.hpp.
Referenced by Render(), and SetTextColor().
|
private |
Definition at line 199 of file RaylibTextInput.hpp.
Referenced by Render(), and SetTextSize().
|
private |
Definition at line 204 of file RaylibTextInput.hpp.
Referenced by IsCharValid(), and SetValidationRegex().
|
private |
Definition at line 188 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), GetSize(), IsMouseOver(), Render(), and SetSize().
|
private |
Definition at line 186 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), GetPosition(), IsMouseOver(), Render(), and SetPosition().
|
private |
Definition at line 187 of file RaylibTextInput.hpp.
Referenced by ApplyAlignment(), GetPosition(), IsMouseOver(), Render(), and SetPosition().
|
staticconstexprprivate |
Definition at line 221 of file RaylibTextInput.hpp.
Referenced by HandleBackspace().
|
staticconstexprprivate |
Definition at line 222 of file RaylibTextInput.hpp.
Referenced by HandleBackspace().
|
staticconstexprprivate |
Definition at line 219 of file RaylibTextInput.hpp.
|
staticconstexprprivate |
Definition at line 218 of file RaylibTextInput.hpp.
Referenced by UpdateCursorBlink().
|
staticconstexprprivate |
Definition at line 220 of file RaylibTextInput.hpp.
Referenced by Render().