SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Textbox Class Reference

A UI text input field component. More...

#include <Textbox.h>

Inheritance diagram for Textbox:
Inheritance graph

Public Member Functions

 Textbox ()=default
 Default constructor (for serialization).
 
 Textbox (const Textbox &)=delete
 
Textboxoperator= (const Textbox &)=delete
 
 Textbox (const std::string &textureKey, const std::string &fontKey, float width, float height)
 Constructs a Textbox with specified texture key, font key, width, and height.
 
void SetPosition (float x, float y)
 Sets the text label of the textbox.
 
void SetScale (float x, float y)
 Sets the scale of the textbox.
 
void SetLayer (int layer) override
 Sets the rendering layer of the textbox.
 
const std::string & GetText () const
 Gets the current text in the textbox.
 
void LoseFocus ()
 Removes focus from the textbox (stops receiving keyboard input).
 
char GetCharFromKey (AZUL_KEY key, bool shiftHeld)
 Sets the focus to the textbox (starts receiving keyboard input).
 
void ClearText ()
 Clears the current text in the textbox.
 
void SetCharacterLimit (int limit)
 Sets the maximum number of characters allowed in the textbox.
 
void SetTextSize (float x, float y)
 Sets the size of the text in the textbox.
 
void SetTextSizePixel (float x, float y)
 Sets the size of the text in the textbox by pixel dimensions.
 
- Public Member Functions inherited from UIComponent
virtual ~UIComponent ()=default
 Virtual destructor.
 
int GetLayer () const
 Gets the rendering layer of the component.
 
UIComponentType GetType () const
 Gets the type of the UI component.
 
bool IsEnabled () const
 Returns whether the component is enabled or not.
 
void SetEnabled (bool enabled)
 Sets the enabled state of the component.
 
void SetOwningCanvas (Canvas *canvas)
 Gets the owning canvas of the component.
 

Private Member Functions

void KeyPress (AZUL_KEY key) override
 Handles key press events for text input and editing.
 
void KeyHeld (AZUL_KEY key) override
 Handles key held events for text input and editing.
 
void KeyRelease (AZUL_KEY key) override
 Handles key release events.
 
void Render () override
 Renders the textbox background and text label.
 
bool IsMouseOver (float x, float y) override
 Checks if the mouse is over the textbox.
 
void OnPress () override
 Handles mouse press events (focuses the textbox).
 
void UpdateTextLabel ()
 Updates the world matrix of the textbox.
 
void KeyboardReg ()
 Handles registration when the textbox is focused.
 
void KeyboardDereg ()
 Handles deregistration when the textbox is unfocused.
 

Private Attributes

SUNENGINESpritepBackgroundSprite
 Background sprite for the textbox.
 
SpriteStringpTextLabel
 Text label for displaying input.
 
std::string text
 Current text in the textbox.
 
std::string fontKey
 Font key for the text label.
 
float posX
 X position of the textbox center.
 
float posY
 Y position of the textbox center.
 
float width
 Width of the textbox.
 
float height
 Height of the textbox.
 
float scaleX
 X scale factor.
 
float scaleY
 Y scale factor.
 
bool isFocused
 True if the textbox is focused for input.
 
bool shiftHeld
 True if shift is currently held.
 
bool capsLock
 True if caps lock is active.
 
int characterLimit
 Maximum number of characters allowed in the textbox.
 

Additional Inherited Members

- Protected Member Functions inherited from Inputable
 Inputable (const Inputable &)=delete
 
Inputableoperator= (const Inputable &)=delete
 
void SubmitKeyRegistration (AZUL_KEY k, EventType e)
 Submits the key registration for the GameObject.
 
void SubmitKeyDeregistration (AZUL_KEY k, EventType e)
 Submits the key deregistration for the GameObject.
 
void SubmitMouseKeyRegistration (AZUL_MOUSE m, EventType e)
 Submits the mouse key registration for the GameObject.
 
void SubmitMouseKeyDeregistration (AZUL_MOUSE m, EventType e)
 Submits the mouse key deregistration for the GameObject.
 
- Protected Attributes inherited from UIComponent
bool Enabled = true
 Indicates if the component is enabled or not.
 
int Layer = 0
 Rendering layer in.
 
UIComponentType Type = UIComponentType::None
 Type of the UI component.
 
CanvaspOwningCanvas = nullptr
 Pointer to the owning canvas, if any.
 

Detailed Description

A UI text input field component.

The Textbox class provides a user interface element for text input. It supports mouse and keyboard interaction, including focus management, character input, and text editing. The textbox displays a background sprite and a text label, and can be positioned and scaled. It inherits from both UIComponent and Inputable to handle rendering and input events.

Example usage:

Textbox* textbox = new Textbox("TextboxBG", "Courier_New", 300.0f, 100.0f);
textbox->SetPosition(400.0f, 200.0f);
textbox->SetScale(1.0f, 1.0f);
canvas->AddComponent(textbox);
void SetScale(float x, float y)
Sets the scale of the textbox.
Definition Textbox.cpp:46
void SetPosition(float x, float y)
Sets the text label of the textbox.
Definition Textbox.cpp:38
Textbox()=default
Default constructor (for serialization).
See also
Canvas, SpriteString, Inputable

Constructor & Destructor Documentation

◆ Textbox()

Textbox::Textbox ( const std::string & textureKey,
const std::string & fontKey,
float width,
float height )

Constructs a Textbox with specified texture key, font key, width, and height.

Parameters
textureKeyThe texture key for the background sprite.
fontKeyThe font key for the text label.
widthThe width of the textbox in pixels.
heightThe height of the textbox in pixels.
Here is the call graph for this function:

Member Function Documentation

◆ GetText()

const std::string & Textbox::GetText ( ) const

Gets the current text in the textbox.

Returns
The current text string.

◆ IsMouseOver()

bool Textbox::IsMouseOver ( float x,
float y )
overrideprivatevirtual

Checks if the mouse is over the textbox.

Parameters
xThe x-coordinate of the mouse.
yThe y-coordinate of the mouse.
Returns
True if the mouse is over the textbox, false otherwise.

Implements UIComponent.

◆ KeyHeld()

void Textbox::KeyHeld ( AZUL_KEY key)
overrideprivatevirtual

Handles key held events for text input and editing.

Parameters
keyThe key that is being held.

Reimplemented from Inputable.

◆ KeyPress()

void Textbox::KeyPress ( AZUL_KEY key)
overrideprivatevirtual

Handles key press events for text input and editing.

Parameters
keyThe key that was pressed.

Reimplemented from Inputable.

Here is the call graph for this function:

◆ KeyRelease()

void Textbox::KeyRelease ( AZUL_KEY key)
overrideprivatevirtual

Handles key release events.

Parameters
keyThe key that was released.

Reimplemented from Inputable.

◆ OnPress()

void Textbox::OnPress ( )
overrideprivatevirtual

Handles mouse press events (focuses the textbox).

Implements UIComponent.

Here is the call graph for this function:

◆ Render()

void Textbox::Render ( )
overrideprivatevirtual

Renders the textbox background and text label.

Implements UIComponent.

◆ SetCharacterLimit()

void Textbox::SetCharacterLimit ( int limit)

Sets the maximum number of characters allowed in the textbox.

Parameters
limitThe character limit.

◆ SetLayer()

void Textbox::SetLayer ( int layer)
overridevirtual

Sets the rendering layer of the textbox.

Parameters
layerThe layer index.

Reimplemented from UIComponent.

◆ SetPosition()

void Textbox::SetPosition ( float x,
float y )

Sets the text label of the textbox.

Parameters
textThe text to display in the textbox.
Here is the call graph for this function:

◆ SetScale()

void Textbox::SetScale ( float x,
float y )

Sets the scale of the textbox.

Parameters
xThe x-scale factor.
yThe y-scale factor.
Here is the call graph for this function:

◆ SetTextSize()

void Textbox::SetTextSize ( float x,
float y )

Sets the size of the text in the textbox.

Parameters
xThe x-scale factor for the text.
yThe y-scale factor for the text.

◆ SetTextSizePixel()

void Textbox::SetTextSizePixel ( float x,
float y )

Sets the size of the text in the textbox by pixel dimensions.

Parameters
xThe x-scale in pixels for the text.
yThe y-scale in pixels for the text.

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