Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::UI::CUITextBox Class Reference

Single-line / multi-line editable text box control. More...

#include <UserInterface/CUITextBox.h>

Inheritance diagram for Skylicht::UI::CUITextBox:
Skylicht::UI::CUIBase

Public Member Functions

 CUITextBox (CUIContainer *container, CGUIElement *element)
 Create a CUITextBox by locating child elements named "Background", "Text", and "Hint".
 CUITextBox (CUIContainer *container, CGUIElement *element, CGUIElement *background, CGUIText *text, CGUIText *hint)
 Create a CUITextBox with explicitly supplied background and text elements.
CGUIElementgetBackground ()
 Get the background GUI element (may be null).
CGUITextgetTextGUI ()
 Get the underlying CGUIText used by this text box.
void setText (const char *text)
 Set the text content (UTF-8 / narrow string).
void setText (const wchar_t *text)
 Set the text content (wide string).
void setHintText (const char *text)
 Set the hint text content (UTF-8 / narrow string).
void setHintText (const wchar_t *text)
 Set the hint text content (wide string).
const char * getText ()
 Get the current text (UTF-8 / narrow C string). Returns empty string if no m_text.
const wchar_t * getTextW ()
 Get the current text (wide string). Returns empty wide string if no m_text.
int getTextLength ()
 Get the current text length in characters.
void setEditable (bool b)
 Enable or disable user editing.
bool isEditable ()
 Returns true when the control is editable.
void setPassword (bool b)
 Enable or disable user editing password.
bool isPassword ()
 Returns true when the control is password.
void setMaxLength (int l)
 Set maximum allowed characters that can be inserted.
int getMaxLength ()
 Get maximum allowed characters.
virtual void onPointerHover (int pointerId, float pointerX, float pointerY)
 Called when pointer enters or hovers over the element.
virtual void onPointerOut (int pointerId, float pointerX, float pointerY)
 Called when pointer leaves the element.
virtual void onPointerDown (int pointerId, float pointerX, float pointerY)
 Called when pointer is pressed down on the element.
virtual void onPointerUp (int pointerId, float pointerX, float pointerY)
 Called when pointer is released over the element.
virtual void onPointerMove (int pointerId, float pointerX, float pointerY)
 Called when pointer moves while over or dragging the element.
virtual void onFocus ()
 Called when element receives focus.
virtual void onLostFocus ()
 Called when element loses focus.
virtual void onKeyEvent (const SEvent &event)
 Keyboard event handler for navigation and editing.
Public Member Functions inherited from Skylicht::UI::CUIBase
 CUIBase (CUIContainer *container, CGUIElement *element)
 Constructor.
virtual ~CUIBase ()
 Virtual destructor.
void remove ()
 Remove this UI object from its container and perform cleanup.
virtual void update ()
virtual void setEnable (bool b)
 Enable or disable this UI object.
virtual void setVisible (bool b)
 Set visibility of this UI object.
bool isEnable ()
 Returns true if the object is enabled.
bool isVisible ()
 Returns true if the object is visible.
int getPointerId ()
 Get the pointer ID associated with this UI object.
void setPointerId (int id)
 Set the pointer ID for this UI object.
void resetTouch ()
 Reset pointer internal state (hover/down).
void setContinueGameEvent (bool b)
 Control whether input events continue to the game layer.
bool isContinueGameEvent ()
 Returns true when events are allowed to continue to the game layer.
bool isContinueKeyEvent ()
void setSkipPointerEventWhenDrag (bool b)
 When true pointer events will be skipped while dragging.
bool isPointerHover ()
 Returns true if pointer is hovering this object.
bool isPointerDown ()
 Returns true if pointer is down on this object.
CGUIElementgetElement ()
 Get the underlying CGUIElement pointer.
CCanvasgetCanvas ()
 Retrieve the canvas that the underlying element belongs to.
CUIContainergetContainer ()
 Get parent container.
core::vector3dfgetRectTransform ()
 Returns a pointer to the internal rect transform (4 corners).
void getRectTransform (CGUIElement *element, core::vector3df *t)
virtual void onPressed ()
 Called when the element is considered "pressed" (high-level event). Subclasses may trigger OnPressed callback from here.
void startMotion (EMotionEvent event)
 Start motions associated with a specific motion event.
void stopMotion (EMotionEvent event)
 Stop motions associated with a specific motion event.
bool isMotionPlaying (EMotionEvent event)
 Query whether any motion is currently playing for the given event.
virtual CMotionaddMotion (EMotionEvent event, CMotion *motion)
 Add a CMotion instance to the list for the given event. The motion will be initialized and managed by this object.
virtual CMotionaddMotion (EMotionEvent event, CGUIElement *element, CMotion *motion)
 Add a CMotion instance bound to a specific CGUIElement for the given event.
bool removeMotion (EMotionEvent event, CMotion *motion)
 Remove a motion instance from the given event list.
void removeMotions (EMotionEvent event)
 Remove all motions attached to the specified event.
std::vector< CMotion * > & getMotions (EMotionEvent event)
 Access the motion vector for a specific event.
void convertToUICoordinate (float &pointerX, float &pointerY)
 Convert screen pointer coordinates to this UI object's local UI coordinates.
void convertWorldToLocal (CGUIElement *element, float &x, float &y)
 Convert world coordinates to the local coordinate space of a CGUIElement.
void convertLocalToWorld (CGUIElement *element, float &x, float &y)
 Convert local coordinates of a CGUIElement to world coordinates.
virtual bool acceptDragFocus ()
 Whether this UI element should accept drag-focus when the pointer is already down and the user drags over it.
void setSoundId (int slot, int soundId)
 Set the sound id associated with this UI object.
int getSoundId (int slot)
 Get the sound id associated with this UI object.
void setUserData (void *data)
 Attach an application-defined pointer to this UI object.
void * getUserData ()
 Retrieve the pointer previously set via setUserData.

Public Attributes

std::function< void(CUIBase *)> OnTextChanged
 Callback fired when the text content changes.
Public Attributes inherited from Skylicht::UI::CUIBase
std::function< void(int, float, float)> OnPointerHover
std::function< void(int, float, float)> OnPointerOut
std::function< void(int, float, float)> OnPointerDown
std::function< void(int, float, float)> OnPointerUp
std::function< void(int, float, float, bool)> OnPointerMove
std::function< void(CUIBase *)> OnPressed
std::function< void(CUIBase *)> OnFocus
std::function< void(CUIBase *)> OnLostFocus
std::function< void(CUIBase *, const SEvent &)> OnKeyEvent
std::function< void(CUIBase *, EMotionEvent)> OnMotionFinish [(int) EMotionEvent::NumEvent]

Protected Member Functions

void updateHintVisibility ()

Protected Attributes

CGUIElementm_background
CGUITextm_text
CGUITextm_hint
bool m_hasFocus
bool m_editable
int m_maxLength
Protected Attributes inherited from Skylicht::UI::CUIBase
CUIContainerm_container
CGUIElementm_element
core::vector3df m_rectTransform [4]
std::vector< CMotion * > m_motions [(int) EMotionEvent::NumEvent]
bool m_enable
bool m_visible
bool m_isPointerHover
bool m_isPointerDown
bool m_skipPointerEventWhenDrag
bool m_continueGameEvent
bool m_continueKeyEvent
int m_pointerId
float m_pointerDownX
float m_pointerDownY
int m_soundId [4]
void * m_userData

Detailed Description

Single-line / multi-line editable text box control.

CUITextBox wraps a CGUIText element and provides basic text editing behaviour: caret management, text insertion/deletion, keyboard navigation, and mouse caret placement. The control forwards focus and capture to the global CUIEventManager when the user interacts with the text area.

Important behaviours implemented by this class:

  • Shows the I-beam cursor while hovering and resets it on pointer out.
  • On pointer down: places the caret at the clicked character, shows the caret, sets focus and capture to this control.
  • While pointer is down and moved: caret follows the pointer.
  • On lost focus: hides the caret.
  • Keyboard handling (in onKeyEvent):
    • Arrow keys, Home/End, Page Up/Down (skeleton) move the caret.
    • Backspace/Delete perform editing when m_editable is true and invoke OnTextChanged.
    • Character input is inserted when current length < m_maxLength.

By default, the control is editable and the maximum text length is 64.

Note: the internal CGUIText has setEnableTextFormnat(false) applied by the constructors to disable automatic text formatting behaviour.

Constructor & Destructor Documentation

◆ CUITextBox() [1/2]

Skylicht::UI::CUITextBox::CUITextBox ( CUIContainer * container,
CGUIElement * element )

Create a CUITextBox by locating child elements named "Background", "Text", and "Hint".

Parameters
containerParent UI container that owns this control.
elementRoot CGUIElement for the control.

The constructor sets m_editable = true, m_maxLength = 64, and disables text formatting on the underlying CGUIText.

◆ CUITextBox() [2/2]

Skylicht::UI::CUITextBox::CUITextBox ( CUIContainer * container,
CGUIElement * element,
CGUIElement * background,
CGUIText * text,
CGUIText * hint )

Create a CUITextBox with explicitly supplied background and text elements.

Parameters
containerParent UI container that owns this control.
elementRoot CGUIElement for the control.
backgroundBackground element to use.
textCGUIText element used for rendering and editing.
hintCGUIText element used for showing hint text.

Member Function Documentation

◆ onFocus()

virtual void Skylicht::UI::CUITextBox::onFocus ( )
virtual

Called when element receives focus.

Reimplemented from Skylicht::UI::CUIBase.

◆ onKeyEvent()

virtual void Skylicht::UI::CUITextBox::onKeyEvent ( const SEvent & event)
virtual

Keyboard event handler for navigation and editing.

Behaviour summary:

  • Arrow keys / Home / End move the caret across lines and characters.
  • Backspace/Delete modify text when m_editable is true and invoke OnTextChanged.
  • Printable characters are inserted when current length < m_maxLength.
Parameters
eventOriginal input SEvent from the engine.

Reimplemented from Skylicht::UI::CUIBase.

◆ onLostFocus()

virtual void Skylicht::UI::CUITextBox::onLostFocus ( )
virtual

Called when element loses focus.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerDown()

virtual void Skylicht::UI::CUITextBox::onPointerDown ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer is pressed down on the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate where press occurred.
pointerYWorld Y coordinate where press occurred.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerHover()

virtual void Skylicht::UI::CUITextBox::onPointerHover ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer enters or hovers over the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate of pointer.
pointerYWorld Y coordinate of pointer.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerMove()

virtual void Skylicht::UI::CUITextBox::onPointerMove ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer moves while over or dragging the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate of pointer.
pointerYWorld Y coordinate of pointer.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerOut()

virtual void Skylicht::UI::CUITextBox::onPointerOut ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer leaves the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate at time of out event.
pointerYWorld Y coordinate at time of out event.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerUp()

virtual void Skylicht::UI::CUITextBox::onPointerUp ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer is released over the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate where release occurred.
pointerYWorld Y coordinate where release occurred.

Reimplemented from Skylicht::UI::CUIBase.

◆ setHintText() [1/2]

void Skylicht::UI::CUITextBox::setHintText ( const char * text)

Set the hint text content (UTF-8 / narrow string).

Parameters
textC string to set as hint content.

◆ setHintText() [2/2]

void Skylicht::UI::CUITextBox::setHintText ( const wchar_t * text)

Set the hint text content (wide string).

Parameters
textWide string to set as hint content.

◆ setText() [1/2]

void Skylicht::UI::CUITextBox::setText ( const char * text)

Set the text content (UTF-8 / narrow string).

Parameters
textC string to set as content.

◆ setText() [2/2]

void Skylicht::UI::CUITextBox::setText ( const wchar_t * text)

Set the text content (wide string).

Parameters
textWide string to set as content.

Member Data Documentation

◆ OnTextChanged

std::function<void(CUIBase*)> Skylicht::UI::CUITextBox::OnTextChanged

Callback fired when the text content changes.

Parameters
senderPointer to the CUIBase (this control).

Invoked after editing operations that modify the text.


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