Shared base for TextInput and TextArea.
More...
#include <Malena/Graphics/Text/TextInputBase.h>
Public Types | |
| using | Flag = TextInputManifest::Flag |
Convenience alias for TextInputManifest::Flag. | |
| using | State = TextInputManifest::State |
Convenience alias for TextInputManifest::State. | |
Public Member Functions | |
| TextInputBase (const sf::Font &font=FontManager<>::getDefault()) | |
| Construct a text input base with an optional font. | |
| unsigned int | getCharacterSize () const |
| Return the current character size in points. | |
| sf::FloatRect | getGlobalBounds () const override |
| float | getPadding () const |
| Return the current padding in pixels. | |
| std::string | getPlaceholder () const |
| Return the current placeholder string. | |
| sf::Vector2f | getPosition () const override |
| sf::Vector2f | getSize () const |
| Return the current size of the input field. | |
| bool | hasError () const |
Return true if the field is currently in error state. | |
| bool | isEnabled () const |
Return true if the field is currently enabled. | |
| bool | isReadOnly () const |
Return true if the field is read-only. | |
| void | onChange (std::function< void(const std::string &)> callback) |
| Register a callback invoked whenever the text content changes. | |
| void | setBackgroundColor (const sf::Color &color) |
| Set the background fill color in the idle state. | |
| void | setBackgroundFocusedColor (const sf::Color &color) |
| Set the background fill color when focused. | |
| void | setBorderColor (const sf::Color &color) |
| Set the border color in the idle state. | |
| void | setBorderErrorColor (const sf::Color &color) |
| Set the border color in the error state. | |
| void | setBorderFocusedColor (const sf::Color &color) |
| Set the border color when focused. | |
| void | setBorderThickness (float thickness) |
| Set the border outline thickness in pixels. | |
| virtual void | setCharacterSize (unsigned int size) |
| Set the character size in points. | |
| void | setEnabled (bool enabled) |
| Enable or disable the input field. | |
| void | setError (bool error) |
| Put the field into or out of the error visual state. | |
| void | setFont (const sf::Font &&)=delete |
| Deleted — rvalue font references are not supported. | |
| virtual void | setFont (const sf::Font &font) |
| Set the font used for text and placeholder. | |
| void | setPadding (float padding) |
| Set the padding between the border and the text. | |
| void | setPlaceholder (const std::string &text) |
| Set the placeholder text shown when the field is empty. | |
| void | setPlaceholderColor (const sf::Color &color) |
| Set the placeholder text color. | |
| void | setPosition (const sf::Vector2f &position) override |
| void | setReadOnly (bool readonly) |
| Set the field to read-only mode. | |
| virtual void | setSize (const sf::Vector2f &size) |
| Set the width and height of the input field. | |
| void | setTextColor (const sf::Color &color) |
| Set the text color. | |
Protected Member Functions | |
| void | applyBackgroundState () |
| void | updatePlaceholderPosition () |
Protected Attributes | |
| sf::RectangleShape | _background |
| sf::Color | _bgColor = sf::Color(40, 40, 40) |
| sf::Color | _bgDisabledColor = sf::Color(30, 30, 30) |
| sf::Color | _bgFocusedColor = sf::Color(50, 50, 50) |
| sf::Color | _borderColor = sf::Color(100, 100, 100) |
| sf::Color | _borderDisabledColor =sf::Color(60, 60, 60) |
| sf::Color | _borderErrorColor = sf::Color(220, 70, 70) |
| sf::Color | _borderFocusedColor = sf::Color(70, 130, 230) |
| float | _borderThickness = 1.5f |
| unsigned int | _charSize = 16 |
| sf::Color | _disabledTextColor = sf::Color(80, 80, 80) |
| const sf::Font * | _font = &FontManager<>::getDefault() |
| std::function< void(const std::string &)> | _onChange |
| float | _padding = 8.f |
| sf::Text | _placeholder |
| sf::Color | _placeholderColor = sf::Color(120, 120, 120) |
| sf::Vector2f | _position = {0.f, 0.f} |
| bool | _showPlaceholder = true |
| sf::Vector2f | _size = {200.f, 36.f} |
| sf::Color | _textColor = sf::Color::White |
Shared base for TextInput and TextArea.
Provides the styling, state management, placeholder logic, and callback infrastructure common to both single-line and multi-line text input controls. Not intended to be used directly.
Definition at line 66 of file TextInputBase.h.
Convenience alias for TextInputManifest::Flag.
Definition at line 70 of file TextInputBase.h.
Convenience alias for TextInputManifest::State.
Definition at line 72 of file TextInputBase.h.
|
explicit |
Construct a text input base with an optional font.
| font | Font for placeholder and text. Defaults to built-in Arial. |
|
protected |
|
nodiscard |
Return the current character size in points.
|
override |
|
nodiscard |
Return the current padding in pixels.
|
nodiscard |
Return the current placeholder string.
|
override |
|
nodiscard |
Return the current size of the input field.
|
nodiscard |
Return true if the field is currently in error state.
|
nodiscard |
Return true if the field is currently enabled.
|
nodiscard |
Return true if the field is read-only.
| void ml::TextInputBase::onChange | ( | std::function< void(const std::string &)> | callback | ) |
Register a callback invoked whenever the text content changes.
| callback | Function invoked with the current text value. |
| void ml::TextInputBase::setBackgroundColor | ( | const sf::Color & | color | ) |
Set the background fill color in the idle state.
| void ml::TextInputBase::setBackgroundFocusedColor | ( | const sf::Color & | color | ) |
Set the background fill color when focused.
| void ml::TextInputBase::setBorderColor | ( | const sf::Color & | color | ) |
Set the border color in the idle state.
| void ml::TextInputBase::setBorderErrorColor | ( | const sf::Color & | color | ) |
Set the border color in the error state.
| void ml::TextInputBase::setBorderFocusedColor | ( | const sf::Color & | color | ) |
Set the border color when focused.
| void ml::TextInputBase::setBorderThickness | ( | float | thickness | ) |
Set the border outline thickness in pixels.
|
virtual |
Set the character size in points.
| size | Character size. Defaults to 16. |
| void ml::TextInputBase::setEnabled | ( | bool | enabled | ) |
Enable or disable the input field.
| enabled | true to enable, false to disable. |
| void ml::TextInputBase::setError | ( | bool | error | ) |
Put the field into or out of the error visual state.
The error state renders the border in _borderErrorColor. Useful for validation feedback.
| error | true to show error state, false to clear it. |
|
delete |
Deleted — rvalue font references are not supported.
|
virtual |
Set the font used for text and placeholder.
| font | Const reference to the font. |
| void ml::TextInputBase::setPadding | ( | float | padding | ) |
Set the padding between the border and the text.
| void ml::TextInputBase::setPlaceholder | ( | const std::string & | text | ) |
Set the placeholder text shown when the field is empty.
| text | Placeholder string. |
| void ml::TextInputBase::setPlaceholderColor | ( | const sf::Color & | color | ) |
Set the placeholder text color.
|
override |
| void ml::TextInputBase::setReadOnly | ( | bool | readonly | ) |
Set the field to read-only mode.
A read-only field can be focused and text can be selected, but no editing is permitted.
| readonly | true for read-only, false for editable. |
|
virtual |
Set the width and height of the input field.
| size | Width and height in pixels. |
| void ml::TextInputBase::setTextColor | ( | const sf::Color & | color | ) |
Set the text color.
|
protected |
|
protected |
Definition at line 76 of file TextInputBase.h.
Definition at line 82 of file TextInputBase.h.
Definition at line 84 of file TextInputBase.h.
Definition at line 83 of file TextInputBase.h.
Definition at line 85 of file TextInputBase.h.
Definition at line 88 of file TextInputBase.h.
Definition at line 87 of file TextInputBase.h.
Definition at line 86 of file TextInputBase.h.
|
protected |
Definition at line 92 of file TextInputBase.h.
|
protected |
Definition at line 100 of file TextInputBase.h.
Definition at line 91 of file TextInputBase.h.
|
protected |
Definition at line 99 of file TextInputBase.h.
|
protected |
Definition at line 103 of file TextInputBase.h.
|
protected |
Definition at line 79 of file TextInputBase.h.
|
protected |
Definition at line 95 of file TextInputBase.h.
Definition at line 90 of file TextInputBase.h.
|
protected |
Definition at line 78 of file TextInputBase.h.
|
protected |
Definition at line 96 of file TextInputBase.h.
|
protected |
Definition at line 77 of file TextInputBase.h.
|
protected |
Definition at line 89 of file TextInputBase.h.