Loading...
Searching...
No Matches
ml::TextInputBase Class Reference

Shared base for TextInput and TextArea. More...

#include <Malena/Graphics/Text/TextInputBase.h>

Inheritance diagram for ml::TextInputBase:
[legend]

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

Detailed Description

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.

See also
TextInput, TextArea, TextInputManifest

Definition at line 66 of file TextInputBase.h.

Member Typedef Documentation

◆ Flag

Convenience alias for TextInputManifest::Flag.

Definition at line 70 of file TextInputBase.h.

◆ State

Convenience alias for TextInputManifest::State.

Definition at line 72 of file TextInputBase.h.

Constructor & Destructor Documentation

◆ TextInputBase()

ml::TextInputBase::TextInputBase ( const sf::Font & font = FontManager<>::getDefault())
explicit

Construct a text input base with an optional font.

Parameters
fontFont for placeholder and text. Defaults to built-in Arial.

Member Function Documentation

◆ applyBackgroundState()

void ml::TextInputBase::applyBackgroundState ( )
protected

◆ getCharacterSize()

unsigned int ml::TextInputBase::getCharacterSize ( ) const
nodiscard

Return the current character size in points.

◆ getGlobalBounds()

sf::FloatRect ml::TextInputBase::getGlobalBounds ( ) const
override

◆ getPadding()

float ml::TextInputBase::getPadding ( ) const
nodiscard

Return the current padding in pixels.

◆ getPlaceholder()

std::string ml::TextInputBase::getPlaceholder ( ) const
nodiscard

Return the current placeholder string.

◆ getPosition()

sf::Vector2f ml::TextInputBase::getPosition ( ) const
override

◆ getSize()

sf::Vector2f ml::TextInputBase::getSize ( ) const
nodiscard

Return the current size of the input field.

◆ hasError()

bool ml::TextInputBase::hasError ( ) const
nodiscard

Return true if the field is currently in error state.

◆ isEnabled()

bool ml::TextInputBase::isEnabled ( ) const
nodiscard

Return true if the field is currently enabled.

◆ isReadOnly()

bool ml::TextInputBase::isReadOnly ( ) const
nodiscard

Return true if the field is read-only.

◆ onChange()

void ml::TextInputBase::onChange ( std::function< void(const std::string &)> callback)

Register a callback invoked whenever the text content changes.

Parameters
callbackFunction invoked with the current text value.

◆ setBackgroundColor()

void ml::TextInputBase::setBackgroundColor ( const sf::Color & color)

Set the background fill color in the idle state.

◆ setBackgroundFocusedColor()

void ml::TextInputBase::setBackgroundFocusedColor ( const sf::Color & color)

Set the background fill color when focused.

◆ setBorderColor()

void ml::TextInputBase::setBorderColor ( const sf::Color & color)

Set the border color in the idle state.

◆ setBorderErrorColor()

void ml::TextInputBase::setBorderErrorColor ( const sf::Color & color)

Set the border color in the error state.

◆ setBorderFocusedColor()

void ml::TextInputBase::setBorderFocusedColor ( const sf::Color & color)

Set the border color when focused.

◆ setBorderThickness()

void ml::TextInputBase::setBorderThickness ( float thickness)

Set the border outline thickness in pixels.

◆ setCharacterSize()

virtual void ml::TextInputBase::setCharacterSize ( unsigned int size)
virtual

Set the character size in points.

Parameters
sizeCharacter size. Defaults to 16.

◆ setEnabled()

void ml::TextInputBase::setEnabled ( bool enabled)

Enable or disable the input field.

Parameters
enabledtrue to enable, false to disable.

◆ setError()

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.

Parameters
errortrue to show error state, false to clear it.

◆ setFont() [1/2]

void ml::TextInputBase::setFont ( const sf::Font && )
delete

Deleted — rvalue font references are not supported.

◆ setFont() [2/2]

virtual void ml::TextInputBase::setFont ( const sf::Font & font)
virtual

Set the font used for text and placeholder.

Parameters
fontConst reference to the font.

◆ setPadding()

void ml::TextInputBase::setPadding ( float padding)

Set the padding between the border and the text.

◆ setPlaceholder()

void ml::TextInputBase::setPlaceholder ( const std::string & text)

Set the placeholder text shown when the field is empty.

Parameters
textPlaceholder string.

◆ setPlaceholderColor()

void ml::TextInputBase::setPlaceholderColor ( const sf::Color & color)

Set the placeholder text color.

◆ setPosition()

void ml::TextInputBase::setPosition ( const sf::Vector2f & position)
override

◆ setReadOnly()

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.

Parameters
readonlytrue for read-only, false for editable.

◆ setSize()

virtual void ml::TextInputBase::setSize ( const sf::Vector2f & size)
virtual

Set the width and height of the input field.

Parameters
sizeWidth and height in pixels.

◆ setTextColor()

void ml::TextInputBase::setTextColor ( const sf::Color & color)

Set the text color.

◆ updatePlaceholderPosition()

void ml::TextInputBase::updatePlaceholderPosition ( )
protected

Member Data Documentation

◆ _background

sf::RectangleShape ml::TextInputBase::_background
protected

Definition at line 76 of file TextInputBase.h.

◆ _bgColor

sf::Color ml::TextInputBase::_bgColor = sf::Color(40, 40, 40)
protected

Definition at line 82 of file TextInputBase.h.

◆ _bgDisabledColor

sf::Color ml::TextInputBase::_bgDisabledColor = sf::Color(30, 30, 30)
protected

Definition at line 84 of file TextInputBase.h.

◆ _bgFocusedColor

sf::Color ml::TextInputBase::_bgFocusedColor = sf::Color(50, 50, 50)
protected

Definition at line 83 of file TextInputBase.h.

◆ _borderColor

sf::Color ml::TextInputBase::_borderColor = sf::Color(100, 100, 100)
protected

Definition at line 85 of file TextInputBase.h.

◆ _borderDisabledColor

sf::Color ml::TextInputBase::_borderDisabledColor =sf::Color(60, 60, 60)
protected

Definition at line 88 of file TextInputBase.h.

◆ _borderErrorColor

sf::Color ml::TextInputBase::_borderErrorColor = sf::Color(220, 70, 70)
protected

Definition at line 87 of file TextInputBase.h.

◆ _borderFocusedColor

sf::Color ml::TextInputBase::_borderFocusedColor = sf::Color(70, 130, 230)
protected

Definition at line 86 of file TextInputBase.h.

◆ _borderThickness

float ml::TextInputBase::_borderThickness = 1.5f
protected

Definition at line 92 of file TextInputBase.h.

◆ _charSize

unsigned int ml::TextInputBase::_charSize = 16
protected

Definition at line 100 of file TextInputBase.h.

◆ _disabledTextColor

sf::Color ml::TextInputBase::_disabledTextColor = sf::Color(80, 80, 80)
protected

Definition at line 91 of file TextInputBase.h.

◆ _font

const sf::Font* ml::TextInputBase::_font = &FontManager<>::getDefault()
protected

Definition at line 99 of file TextInputBase.h.

◆ _onChange

std::function<void(const std::string&)> ml::TextInputBase::_onChange
protected

Definition at line 103 of file TextInputBase.h.

◆ _padding

float ml::TextInputBase::_padding = 8.f
protected

Definition at line 79 of file TextInputBase.h.

◆ _placeholder

sf::Text ml::TextInputBase::_placeholder
protected

Definition at line 95 of file TextInputBase.h.

◆ _placeholderColor

sf::Color ml::TextInputBase::_placeholderColor = sf::Color(120, 120, 120)
protected

Definition at line 90 of file TextInputBase.h.

◆ _position

sf::Vector2f ml::TextInputBase::_position = {0.f, 0.f}
protected

Definition at line 78 of file TextInputBase.h.

◆ _showPlaceholder

bool ml::TextInputBase::_showPlaceholder = true
protected

Definition at line 96 of file TextInputBase.h.

◆ _size

sf::Vector2f ml::TextInputBase::_size = {200.f, 36.f}
protected

Definition at line 77 of file TextInputBase.h.

◆ _textColor

sf::Color ml::TextInputBase::_textColor = sf::Color::White
protected

Definition at line 89 of file TextInputBase.h.


The documentation for this class was generated from the following file: