Files
XCEngine/docs/api/XCEngine/Editor/UI/PopupState/TextInputPopupState.md

65 lines
1.6 KiB
Markdown
Raw Normal View History

2026-04-03 13:36:57 +08:00
# TextInputPopupState
**命名空间**: `XCEngine::Editor::UI`
**类型**: `template class`
**源文件**: `editor/src/UI/PopupState.h`
## 签名
```cpp
template <size_t BufferCapacity>
class TextInputPopupState;
```
## 作用
为单字段文本输入 popup 提供固定容量缓冲区和延迟打开状态。
## 公开接口
```cpp
void RequestOpen(const char* initialValue = "");
void ConsumeOpenRequest(const char* popupId);
void SetValue(const char* value);
void Clear();
bool Empty() const;
char* Buffer();
const char* Buffer() const;
constexpr size_t BufferSize() const;
```
## 当前实现行为
- `RequestOpen(initialValue)`
- 先把初始值写入内部字符缓冲区
- 再通过内部 `DeferredPopupState` 记录待开请求
- `ConsumeOpenRequest(...)`
- 转发给内部 popup 状态,在合适帧调用 `ImGui::OpenPopup(...)`
- `SetValue(value)`
- 当传入非空且非空串时,使用 `strcpy_s` 写入缓冲区
- 否则会把缓冲区首字符置零
- `Clear()`
- 当前只清空文本缓冲区
- 不会额外清掉内部 popup 请求状态
- `Empty()`
- 通过检查首字符是否为 `'\0'` 判断内容是否为空
- `Buffer()` / `BufferSize()`
-`ImGui::InputText(...)` 一类 API 直接消费
## 设计含义
- 这个 helper 适合“打开 popup 后输入一段名字”的轻量对话框。
- 它把常见的 `char buffer[N] + OpenPopup` 模式封装成可复用状态。
## 当前实现边界
- 容量是模板参数,调用方需要自己选择缓冲区大小。
- 当前不提供校验、提交态或多字段表单状态。
## 相关文档
- [PopupState](PopupState.md)
- [DeferredPopupState](DeferredPopupState.md)