Velvet 0.1a
A beginner-friendly C++ GUI framework built on SFML.
Loading...
Searching...
No Matches
InputField Class Reference

Single-line text input widget with placeholder and basic styling. More...

#include <InputField.hpp>

+ Inheritance diagram for InputField:

Public Member Functions

void render (sf::RenderWindow &window) override
 Render the input field.
 
void setPosition (float x, float y) override
 Set top-left position of the input box.
 
void handleEvent (const sf::Event &event, sf::RenderWindow &window) override
 Handle focus changes and text input/backspace events.
 
sf::Vector2f getDimensions () override
 Get input field dimensions (container bounds).
 
 InputField (std::string placeholder="", std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling={})
 Create an input field with optional placeholder and style overrides.
 
void overrideStyling (std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling)
 Apply/override style properties at runtime.
 
std::string getContent ()
 Get text content in the field.
 
std::string getPlaceholder ()
 Get value of placeholder text .
 
void setPlaceholder (std::string placeholderString)
 Set value of placeholder.
 
- Public Member Functions inherited from Widget
 Widget ()
 Construct a widget with default font loading.
 

Additional Inherited Members

- Public Attributes inherited from Widget
sf::Font font
 Shared font loaded by the base widget.
 
- Protected Attributes inherited from Widget
float x
 
float y
 

Detailed Description

Single-line text input widget with placeholder and basic styling.

Supported style keys (std::unordered_map<std::string, std::variant<unsigned int, float, std::string>>):

  • fontPath (std::string)
  • fontSize (float)
  • letterSpacing (float)
  • fontColor (unsigned int) text color, RGBA hex like 0xRRGGBBAA
  • outlineColor (unsigned int) inactive border color
  • activeOutlineColor (unsigned int) active border color when focused
  • backgroundColor (unsigned int) input background fill
  • placeholderColor (unsigned int) color of the placeholder text
  • width (float) logical width of the input box

Constructor & Destructor Documentation

◆ InputField()

InputField::InputField ( std::string  placeholder = "",
std::unordered_map< std::string, std::variant< unsigned int, float, std::string > >  styling = {} 
)

Create an input field with optional placeholder and style overrides.

Parameters
placeholderPlaceholder text to display when empty.
stylingOptional style overrides map; unknown keys are ignored with a warning.

Member Function Documentation

◆ getContent()

std::string InputField::getContent ( )

Get text content in the field.

◆ getDimensions()

sf::Vector2f InputField::getDimensions ( )
overridevirtual

Get input field dimensions (container bounds).

Implements Widget.

◆ getPlaceholder()

std::string InputField::getPlaceholder ( )

Get value of placeholder text .

◆ handleEvent()

void InputField::handleEvent ( const sf::Event &  event,
sf::RenderWindow &  window 
)
overridevirtual

Handle focus changes and text input/backspace events.

Reimplemented from Widget.

◆ overrideStyling()

void InputField::overrideStyling ( std::unordered_map< std::string, std::variant< unsigned int, float, std::string > >  styling)

Apply/override style properties at runtime.

Unknown keys are ignored with a warning.

◆ render()

void InputField::render ( sf::RenderWindow &  window)
overridevirtual

Render the input field.

Reimplemented from Widget.

◆ setPlaceholder()

void InputField::setPlaceholder ( std::string  placeholderString)

Set value of placeholder.

◆ setPosition()

void InputField::setPosition ( float  x,
float  y 
)
overridevirtual

Set top-left position of the input box.

Implements Widget.


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