56 const char *clipboardText = GetClipboardText();
57 if (clipboardText ==
nullptr) {
61 std::string pasteText(clipboardText);
62 bool textChanged =
false;
65 for (
char c : pasteText) {
67 if (c >= 32 && c <= 126) {
94 bool shouldDelete =
false;
130 if (key >= 32 && key <= 126) {
131 char c =
static_cast<char>(key);
171 static_cast<int>(
_height), borderColor);
189 }
else if (!
_text.empty()) {
193 std::string maskedText(
_text.length(),
'*');
194 _graphics.
DrawText(maskedText.c_str(),
static_cast<int>(textX),
static_cast<int>(textY),
206 if (!
_text.empty()) {
209 std::string maskedText(
_text.length(),
'*');
210 textWidth = MeasureText(maskedText.c_str(),
_textSize);
215 float cursorX = textX +
static_cast<float>(textWidth);
216 float cursorY = textY;
217 float cursorHeight =
static_cast<float>(
_textSize);
286 if (!regexPattern.empty()) {
289 }
catch (
const std::regex_error &) {
343 _x = (
static_cast<float>(screenWidth) -
_width) / 2.0F;
346 _y = (
static_cast<float>(screenHeight) -
_height) / 2.0F;
349 _x = (
static_cast<float>(screenWidth) -
_width) / 2.0F;
350 _y = (
static_cast<float>(screenHeight) -
_height) / 2.0F;
381 return static_cast<float>(mouseX) >=
_x &&
static_cast<float>(mouseX) <=
_x +
_width &&
382 static_cast<float>(mouseY) >=
_y &&
static_cast<float>(mouseY) <=
_y +
_height;
390 std::string singleChar(1, c);
Abstract interface for graphics rendering operations.
virtual bool IsKeyPressed(int key) const =0
Check if a key was pressed (triggered once when key goes down)
virtual void DrawText(int fontHandle, const char *text, int x, int y, int fontSize, unsigned int color)=0
Draw text using a loaded font.
virtual int GetMouseX() const =0
Get the current X position of the mouse cursor.
virtual int GetScreenHeight() const =0
Get the screen height (same as window height)
virtual int GetMouseY() const =0
Get the current Y position of the mouse cursor.
virtual int GetCharPressed() const =0
Get the next character from the keyboard input queue.
virtual bool IsMouseButtonPressed(int button) const =0
Check if a mouse button was pressed (triggered once when button goes down)
virtual void DrawRectangleLines(int x, int y, int width, int height, unsigned int color)=0
Draw a rectangle outline (alias for DrawRect)
virtual float GetDeltaTime() const =0
Get the time elapsed for the last frame.
virtual bool IsKeyDown(int key) const =0
Check if a key is currently being held down.
virtual int GetScreenWidth() const =0
Get the screen width (same as window width)
virtual void DrawRectangle(int x, int y, int width, int height, unsigned int color)=0
Draw a filled rectangle (alias for DrawRectFilled)
void GetSize(float &width, float &height) const override
Get the current size of the text input.
const std::string & GetText() const override
Get the current text content.
std::string _regexPattern
void GetPosition(float &x, float &y) const override
Get the current top-left position of the text input.
bool IsPasswordMode() const override
Check if password mode is enabled.
RaylibTextInput(Graphics::IGraphics &graphics)
Construct a new RaylibTextInput.
void SetTextSize(int size) override
Set the text size in pixels.
void SetFocused(bool focused) override
Set focus state programmatically.
static constexpr float BACKSPACE_REPEAT_DELAY
static constexpr float CURSOR_BLINK_RATE
void HandleBackspace()
Handle backspace key with repeat support.
void ResetCursor()
Show cursor and reset blink timer.
bool TryAddCharacter(char c)
Add a character to the text if valid.
void SetOnTextChanged(std::function< void(const std::string &)> callback) override
Set callback invoked when text changes.
bool IsEnabled() const override
Check if the text input is enabled.
unsigned int _activeBorderColor
void SetValidationRegex(const std::string ®exPattern) override
Set a regex pattern to restrict allowed characters.
bool IsMouseOver() const
Check whether the mouse cursor is currently over the input rectangle.
unsigned int _backgroundColor
void SetActiveBorderColor(unsigned int color) override
Set the border color when the input is focused/active.
void SetAlign(Align align) override
Set alignment mode relative to the window.
bool IsFocused() const override
Check if the text input is currently focused/active.
void SetBorderColor(unsigned int color) override
Set the border color when the input is not focused.
void SetText(const std::string &text) override
Set the text content programmatically.
void HandleFocusClick()
Handle mouse click to set focus state.
void SetTextColor(unsigned int color) override
Set the text color.
void ApplyAlignment() override
Apply the current alignment mode to the position.
void SetPasswordMode(bool passwordMode) override
Enable or disable password mode (masks characters with asterisks).
void Clear() override
Clear the text content.
void SetFont(int fontHandle) override
Set the font handle for rendering text.
Graphics::IGraphics & _graphics
void SetPlaceholderColor(unsigned int color) override
Set the placeholder text color (when input is empty).
void SetPosition(float x, float y) override
Set the top-left position of the text input.
std::function< void(const std::string &)> _onTextChanged
void Render() override
Render the text input box.
void SetSize(float width, float height) override
Set the text input size.
void SetBackgroundColor(unsigned int color) override
Set the background color of the text input box.
void SetEnabled(bool enabled) override
Enable or disable the text input.
void HandlePaste()
Handle paste operation (Ctrl+V or Cmd+V).
Align GetAlign() const override
Get the current alignment mode.
void UpdateCursorBlink()
Update cursor blink animation.
void HandleCharacterInput()
Handle regular character input.
void SetMaxLength(size_t maxLength) override
Set the maximum number of characters allowed.
void Update() override
Update the text input internal state (focus, cursor, input).
bool IsCharValid(char c) const
Validate a character against the current regex pattern.
static constexpr float BACKSPACE_REPEAT_RATE
void SetPlaceholder(const std::string &placeholder) override
Set the placeholder text displayed when the input is empty.
static constexpr float TEXT_PADDING
std::unique_ptr< std::regex > _validationRegex
unsigned int _placeholderColor
unsigned int _borderColor
Align
Alignment modes relative to the current window.
@ CENTER_VERTICAL
Center on the Y axis.
@ CENTER_BOTH
Center on both axes.
@ CENTER_HORIZONTAL
Center on the X axis.