|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
文本输入控件抽象基类 更多...
#include <UITextInput.h>
Public 成员函数 | |
| 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、无法自动触发的引擎状态"(如精灵纹理加载)。 | |
| Component (const Component &)=delete | |
| Component & | operator= (const Component &)=delete |
| Component (Component &&)=delete | |
| Component & | operator= (Component &&)=delete |
| GameObject * | getOwner () const |
| bool | isRegistered () const |
Protected 成员函数 | |
| void | onRender (const SDL_FRect &screenRect) override=0 |
| 子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制) | |
| virtual bool | onKeyDown (KeyCode key, bool shift, bool ctrl) |
| 子类可覆写:处理键盘控制键(方向键、退格、删除、Home/End、回车) | |
| virtual void | insertText (const std::string &utf8) |
| 子类可覆写:向缓冲插入一段 UTF-8 文本 | |
| virtual void | insertNewline () |
| 子类可覆写:当前选区是否被替换为换行(UITextBox 拒绝) | |
| 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 成员函数 | |
| 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 属性 | |
| 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 |
友元 | |
| class | TextInputGate |
文本输入控件抽象基类
负责所有输入控件共享的状态与行为:
单行 vs 多行的差异由子类覆写 onRender / onKeyDown / 插入换行策略实现。 不直接绘制背景:背景由同 GameObject 上的 UIImage 提供(与按钮一致)。
|
default |
|
override |
|
protected |
获取或加载字体(进程级缓存,跨 UITextInput/UITextBox/UITextArea 共享)
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
以"字符"计算文本长度
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
protectedvirtual |
子类可覆写:当前选区是否被替换为换行(UITextBox 拒绝)
被 UITextArea 重载.
|
protectedvirtual |
子类可覆写:向缓冲插入一段 UTF-8 文本
被 UITextBox 重载.
|
inline |
|
inline |
|
inlineprotected |
标记脏位(下一帧重建纹理/布局)
|
protected |
|
protected |
|
protectedvirtual |
|
overrideprotectedpure virtual |
| void onTextEditing | ( | const char * | utf8Text, |
| int | start, | ||
| int | length ) |
| void onTextInput | ( | const char * | utf8Text | ) |
|
inline |
| void setFocused | ( | bool | focused | ) |
由 UIRenderSystem 在命中时调用,切换聚焦
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
virtual |
|
inline |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |