cangine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
cangine::InputFieldComponent Class Reference

Editable single-line text input field. More...

#include <inputfield_component.hpp>

Inheritance diagram for cangine::InputFieldComponent:
Inheritance graph
[legend]
Collaboration diagram for cangine::InputFieldComponent:
Collaboration graph
[legend]

Public Member Functions

 InputFieldComponent ()
 
 ~InputFieldComponent ()
 
void firstFrame () override
 Called once before the first frame update.
 
void frame (double dt) override
 Called every frame to update the component.
 
void updateView ()
 Recomputes the visible text window from the caret position.
 
void inputEventHandler (std::string s)
 Inserts typed characters at the caret.
 
void keyEventHandler (KeyEvent event)
 Handles editing keys (arrows, backspace, enter, ...).
 
void onMouseEvent (const MouseEvent *e) override
 Called when a mouse event is dispatched to the owning object.
 
- Public Member Functions inherited from cangine::TextRendererComponent
void firstFrame () override
 Called once before the first frame update.
 
void frame (double dt) override
 Called every frame to update the component.
 
Vector2 getSize ()
 Returns the rendered size of the current text.
 
void setFontHeight (int heightIn)
 Sets the font's pixel height (reloads the font).
 
int getFontHeight ()
 Returns the current font pixel height.
 
void setBackTexture (Texture *textureIn)
 Sets the background texture drawn behind the text.
 
Texture * getBackTexture () const
 Returns the background texture.
 
- Public Member Functions inherited from cangine::IComponent
 IComponent (GameObject *gameObject=nullptr)
 Constructs the component, optionally bound to a game object.
 
virtual ~IComponent ()
 
GameObject * getGameObject () const
 Returns the game object this component is attached to.
 

Public Attributes

int width = 128
 Field width in pixels.
 
int height = 25
 Field height in pixels.
 
std::string content
 Current text content.
 
int cursorpos = 0
 Caret position as an index into content.
 
std::function< void(std::string)> onReturn = nullptr
 Called with the content when Enter is pressed.
 
float borderWidth
 Border thickness in pixels.
 
std::string placeholder
 Text shown when the field is empty.
 
Color placeholderColor
 Color of the placeholder text.
 
Color borderColor
 Border color when not focused.
 
Color borderColorFocus
 Border color when focused.
 
Color cursorColor
 Caret color.
 
- Public Attributes inherited from cangine::TextRendererComponent
Color color
 Text color.
 
Color backgroundColor
 Background fill color.
 
float backgroundPadding
 Padding between text and background edges.
 
float scale
 Scale factor applied to the text.
 
std::string text
 The string to render.
 
Rectangle rect
 Background rectangle geometry.
 
- Public Attributes inherited from cangine::IComponent
bool isUnique = true
 If true, only one of this component type may exist per object.
 

Static Public Attributes

static InputFieldComponent * focused = nullptr
 The currently focused field, or nullptr.
 

Private Member Functions

void draw (double dt)
 Draws the field background, border, text and caret.
 

Private Attributes

float blinkTimer = 0
 Accumulator driving the caret blink.
 
size_t eventHandlerID
 Id of the registered character-event handler.
 
size_t keyEventHandlerID
 Id of the registered key-event handler.
 
size_t startIdx
 Index of the first visible character (horizontal scroll).
 
Transform * t
 Cached transform of the owning object.
 
QuadRenderer * qr
 Renderer used to draw border/caret.
 

Additional Inherited Members

- Protected Attributes inherited from cangine::TextRendererComponent
TextRenderer * tr
 Renderer used to draw the text.
 
std::string path
 Path of the loaded font file.
 
int fontHeight
 Pixel height the font is loaded at.
 
Font * font = nullptr
 Loaded font, or nullptr.
 
Texture * backTex = nullptr
 Optional background texture.
 

Detailed Description

Editable single-line text input field.

Extends TextRendererComponent to capture keyboard/character input, maintain a caret and content string, scroll the visible text, and fire a callback when Enter is pressed. Only one field is focused at a time.

Constructor & Destructor Documentation

◆ InputFieldComponent()

cangine::InputFieldComponent::InputFieldComponent ( )

◆ ~InputFieldComponent()

cangine::InputFieldComponent::~InputFieldComponent ( )

Member Function Documentation

◆ draw()

void cangine::InputFieldComponent::draw ( double  dt)
private

Draws the field background, border, text and caret.

Parameters
dtSeconds elapsed since the previous frame.

◆ firstFrame()

void cangine::InputFieldComponent::firstFrame ( )
overridevirtual

Called once before the first frame update.

Reimplemented from cangine::IComponent.

◆ frame()

void cangine::InputFieldComponent::frame ( double  deltaTime)
overridevirtual

Called every frame to update the component.

Parameters
deltaTimeSeconds elapsed since the previous frame.

Reimplemented from cangine::IComponent.

◆ inputEventHandler()

void cangine::InputFieldComponent::inputEventHandler ( std::string  s)

Inserts typed characters at the caret.

Parameters
sUTF-8 text that was typed.

◆ keyEventHandler()

void cangine::InputFieldComponent::keyEventHandler ( KeyEvent  event)

Handles editing keys (arrows, backspace, enter, ...).

Parameters
eventThe key event.

◆ onMouseEvent()

void cangine::InputFieldComponent::onMouseEvent ( const MouseEvent *  e)
overridevirtual

Called when a mouse event is dispatched to the owning object.

Parameters
eThe mouse event.

Reimplemented from cangine::IComponent.

◆ updateView()

void cangine::InputFieldComponent::updateView ( )

Recomputes the visible text window from the caret position.

Member Data Documentation

◆ blinkTimer

float cangine::InputFieldComponent::blinkTimer = 0
private

Accumulator driving the caret blink.

◆ borderColor

Color cangine::InputFieldComponent::borderColor

Border color when not focused.

◆ borderColorFocus

Color cangine::InputFieldComponent::borderColorFocus

Border color when focused.

◆ borderWidth

float cangine::InputFieldComponent::borderWidth

Border thickness in pixels.

◆ content

std::string cangine::InputFieldComponent::content

Current text content.

◆ cursorColor

Color cangine::InputFieldComponent::cursorColor

Caret color.

◆ cursorpos

int cangine::InputFieldComponent::cursorpos = 0

Caret position as an index into content.

◆ eventHandlerID

size_t cangine::InputFieldComponent::eventHandlerID
private

Id of the registered character-event handler.

◆ focused

InputFieldComponent * cangine::InputFieldComponent::focused = nullptr
static

The currently focused field, or nullptr.

◆ height

int cangine::InputFieldComponent::height = 25

Field height in pixels.

◆ keyEventHandlerID

size_t cangine::InputFieldComponent::keyEventHandlerID
private

Id of the registered key-event handler.

◆ onReturn

std::function<void(std::string)> cangine::InputFieldComponent::onReturn = nullptr

Called with the content when Enter is pressed.

◆ placeholder

std::string cangine::InputFieldComponent::placeholder

Text shown when the field is empty.

◆ placeholderColor

Color cangine::InputFieldComponent::placeholderColor

Color of the placeholder text.

◆ qr

QuadRenderer* cangine::InputFieldComponent::qr
private

Renderer used to draw border/caret.

◆ startIdx

size_t cangine::InputFieldComponent::startIdx
private

Index of the first visible character (horizontal scroll).

◆ t

Transform* cangine::InputFieldComponent::t
private

Cached transform of the owning object.

◆ width

int cangine::InputFieldComponent::width = 128

Field width in pixels.


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