Skylicht Engine
Loading...
Searching...
No Matches
CUITextBox.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CUIBase.h"
28
29namespace Skylicht
30{
31 namespace UI
32 {
59 class CUITextBox : public CUIBase
60 {
61 protected:
62 CGUIElement* m_background;
63 CGUIText* m_text;
64 CGUIText* m_hint;
65 bool m_hasFocus;
66
67 bool m_editable;
68
69 int m_maxLength;
70
71 void updateHintVisibility();
72
73 public:
74
81 std::function<void(CUIBase*)> OnTextChanged;
82
83 public:
92 CUITextBox(CUIContainer* container, CGUIElement* element);
93
102 CUITextBox(CUIContainer* container, CGUIElement* element, CGUIElement* background, CGUIText* text, CGUIText* hint);
103
104 virtual ~CUITextBox();
105
108 {
109 return m_background;
110 }
111
114 {
115 return m_text;
116 }
117
122 void setText(const char* text);
123
128 void setText(const wchar_t* text);
129
134 void setHintText(const char* text);
135
140 void setHintText(const wchar_t* text);
141
143 const char* getText();
144
146 const wchar_t* getTextW();
147
150
152 inline void setEditable(bool b)
153 {
154 m_editable = b;
155 }
156
158 inline bool isEditable()
159 {
160 return m_editable;
161 }
162
164 void setPassword(bool b);
165
168
170 inline void setMaxLength(int l)
171 {
172 m_maxLength = l;
173 }
174
176 inline int getMaxLength()
177 {
178 return m_maxLength;
179 }
180
181 virtual void onPointerHover(int pointerId, float pointerX, float pointerY);
182
183 virtual void onPointerOut(int pointerId, float pointerX, float pointerY);
184
185 virtual void onPointerDown(int pointerId, float pointerX, float pointerY);
186
187 virtual void onPointerUp(int pointerId, float pointerX, float pointerY);
188
189 virtual void onPointerMove(int pointerId, float pointerX, float pointerY);
190
191 virtual void onFocus();
192
193 virtual void onLostFocus();
194
205 virtual void onKeyEvent(const SEvent& event);
206 };
207 }
208}
This is the base object class from which other GUIs inherit. It's an empty GUI and can contain child ...
Definition CGUIElement.h:51
This is the object class for displaying a text.
Definition CGUIText.h:60
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
Top-level UI container and event router.
Definition CUIContainer.h:59
virtual void onKeyEvent(const SEvent &event)
Keyboard event handler for navigation and editing.
bool isPassword()
Returns true when the control is password.
virtual void onLostFocus()
Called when element loses focus.
std::function< void(CUIBase *)> OnTextChanged
Callback fired when the text content changes.
Definition CUITextBox.h:81
void setPassword(bool b)
Enable or disable user editing password.
void setText(const wchar_t *text)
Set the text content (wide string).
const char * getText()
Get the current text (UTF-8 / narrow C string). Returns empty string if no m_text.
void setHintText(const wchar_t *text)
Set the hint text content (wide string).
virtual void onPointerUp(int pointerId, float pointerX, float pointerY)
Called when pointer is released over the element.
CGUIText * getTextGUI()
Get the underlying CGUIText used by this text box.
Definition CUITextBox.h:113
virtual void onPointerDown(int pointerId, float pointerX, float pointerY)
Called when pointer is pressed down on the element.
bool isEditable()
Returns true when the control is editable.
Definition CUITextBox.h:158
int getMaxLength()
Get maximum allowed characters.
Definition CUITextBox.h:176
CUITextBox(CUIContainer *container, CGUIElement *element)
Create a CUITextBox by locating child elements named "Background", "Text", and "Hint".
virtual void onPointerMove(int pointerId, float pointerX, float pointerY)
Called when pointer moves while over or dragging the element.
const wchar_t * getTextW()
Get the current text (wide string). Returns empty wide string if no m_text.
void setMaxLength(int l)
Set maximum allowed characters that can be inserted.
Definition CUITextBox.h:170
virtual void onFocus()
Called when element receives focus.
virtual void onPointerHover(int pointerId, float pointerX, float pointerY)
Called when pointer enters or hovers over the element.
void setEditable(bool b)
Enable or disable user editing.
Definition CUITextBox.h:152
CGUIElement * getBackground()
Get the background GUI element (may be null).
Definition CUITextBox.h:107
void setHintText(const char *text)
Set the hint text content (UTF-8 / narrow string).
void setText(const char *text)
Set the text content (UTF-8 / narrow string).
int getTextLength()
Get the current text length in characters.
CUITextBox(CUIContainer *container, CGUIElement *element, CGUIElement *background, CGUIText *text, CGUIText *hint)
Create a CUITextBox with explicitly supplied background and text elements.
virtual void onPointerOut(int pointerId, float pointerX, float pointerY)
Called when pointer leaves the element.
Classes used to build the User Interface (UI).
Definition CAlphaMotion.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
SEvents hold information about an event. See irr::IEventReceiver for details on event handling.
Definition IEventReceiver.h:273