ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
UITextArea类 参考

多行文本输入区域 更多...

#include <UITextArea.h>

类 UITextArea 继承关系图:
UITextInput UIRendererComponent Component

Public 成员函数

 UITextArea ()
 ~UITextArea () override=default
Public 成员函数 继承自 UITextInput
 UITextInput ()=default
 ~UITextInput () override
const std::string & getText () const
virtual void setText (const std::string &text)
const std::string & getPlaceholder () const
void setPlaceholder (const std::string &placeholder)
const std::string & getFontPath () const
void setFontPath (const std::string &fontPath)
float getFontSize () const
void setFontSize (float fontSize)
float getFontHeight () const
const Color & getTextColor () const
void setTextColor (const Color &color)
const Color & getPlaceholderColor () const
void setPlaceholderColor (const Color &color)
const Color & getCursorColor () const
void setCursorColor (const Color &color)
const Color & getSelectionColor () const
void setSelectionColor (const Color &color)
bool isFocused () const
bool isMultiline () const
void onTextInput (const char *utf8Text)
void onTextEditing (const char *utf8Text, int start, int length)
void setFocused (bool focused)
 由 UIRenderSystem 在命中时调用,切换聚焦
Public 成员函数 继承自 UIRendererComponent
 UIRendererComponent ()
 ~UIRendererComponent () override=default
void onAttach () override
virtual bool containsPoint (const SDL_FRect &screenRect, const Vector2 &point) const
 点击命中检测:默认矩形内即命中,子类可覆写为更精确的形状
int getZIndex () const
void setZIndex (int zIndex)
bool isVisible () const
void setVisible (bool visible)
Public 成员函数 继承自 Component
 Component ()
virtual ~Component ()=default
virtual void onCreate ()
virtual void onAfterDeserialize ()
 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。
virtual void onFieldChanged (const std::string &fieldName)
 检查器直接写反射字段后回调(字段名)。用于绕过 setter 的直写完成后 重新同步引擎状态(如 Box2D 刚体/形状)。默认无操作。
 Component (const Component &)=delete
Component & operator= (const Component &)=delete
 Component (Component &&)=delete
Component & operator= (Component &&)=delete
GameObject * getOwner () const
bool isRegistered () const
uint64_t getUuid () const
 组件持久 ID(随 .scene 序列化,是 ComponentRef<T> 引用字段的寻址依据)
void setUuid (uint64_t uuid)
 直接设置组件 ID(仅引擎反序列化/索引维护使用;正常流程由构造函数随机分配)

Protected 成员函数

void onRender (const SDL_FRect &screenRect) override
 子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)
bool onKeyDown (KeyCode key, bool shift, bool ctrl) override
 子类可覆写:处理键盘控制键(方向键、退格、删除、Home/End、回车)
void insertNewline () override
 子类可覆写:当前选区是否被替换为换行(UITextBox 拒绝)
Protected 成员函数 继承自 UITextInput
virtual void insertText (const std::string &utf8)
 子类可覆写:向缓冲插入一段 UTF-8 文本
size_t getCharacterCount () const
 以"字符"计算文本长度
void markDirty ()
 标记脏位(下一帧重建纹理/布局)
TTF_Font * acquireFont ()
 获取或加载字体(进程级缓存,跨 UITextInput/UITextBox/UITextArea 共享)
void deleteSelection ()
void moveCursor (int deltaChars, bool selecting)
void moveCursorToBoundary (bool toStart, bool selecting)
void clampCursor ()
Protected 成员函数 继承自 UIRendererComponent
void requestSort ()
 components变更后通知系统重排(实例:zIndex 变化)
Protected 成员函数 继承自 Component
void setRegistered (bool registered)

额外继承的成员函数

静态 Protected 成员函数 继承自 UITextInput
static size_t charToByte (const std::string &s, size_t charIdx)
static size_t byteToChar (const std::string &s, size_t byteOff)
静态 Protected 成员函数 继承自 UIRendererComponent
static SDL_Color toSDLColor (const Color &color)
 Color → SDL_Color 边界转换(供 UIText / UITextInput 系列传给 SDL_ttf 用)
Protected 属性 继承自 UITextInput
bool m_isFocused = false
bool m_isMultiline = false
std::string m_text
std::string m_placeholder
std::string m_fontPath
float m_fontSize = 24.0f
float m_fontHeight = 0.0f
Color m_textColor { 30, 30, 30, 255 }
Color m_placeholderColor { 140, 140, 140, 255 }
Color m_cursorColor { 80, 140, 220, 255 }
Color m_selectionColor { 80, 140, 220, 120 }
bool m_isDirty = true
size_t m_cursor = 0
size_t m_selectionAnchor = 0
std::string m_preedit
int m_preeditStart = 0
int m_preeditLength = 0
Protected 属性 继承自 UIRendererComponent
int m_zIndex = 0
 渲染层级(值越大越靠上)
bool m_isVisible = true
 是否参与渲染与命中
Protected 属性 继承自 Component
GameObject * m_owner = nullptr
bool m_isRegistered = false
uint64_t m_uuid = 0
 持久 ID(构造时随机分配;0 仅在序列化前尚未赋值时短暂存在)

详细描述

多行文本输入区域

支持换行(Enter 插入 '
')。自动换行(按宽度软包裹)尚未实现。 上下方向键按"逻辑行"移动光标(按 '
' 切分文本)。

用法与 UITextBox 一致,构造即可用。

构造及析构函数说明

◆ UITextArea()

UITextArea ( )

◆ ~UITextArea()

~UITextArea ( )
overridedefault

成员函数说明

◆ insertNewline()

void insertNewline ( )
overrideprotectedvirtual

子类可覆写:当前选区是否被替换为换行(UITextBox 拒绝)

重载 UITextInput .

◆ onKeyDown()

bool onKeyDown ( KeyCode key,
bool shift,
bool ctrl )
overrideprotectedvirtual

子类可覆写:处理键盘控制键(方向键、退格、删除、Home/End、回车)

返回
true 表示已处理该按键,不继续传播

重载 UITextInput .

◆ onRender()

void onRender ( const SDL_FRect & screenRect)
overrideprotectedvirtual

子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)

实现了 UITextInput.


该类的文档由以下文件生成: