66 lines
1.6 KiB
Markdown
66 lines
1.6 KiB
Markdown
|
|
# TargetedPopupState
|
||
|
|
|
||
|
|
**命名空间**: `XCEngine::Editor::UI`
|
||
|
|
|
||
|
|
**类型**: `template class`
|
||
|
|
|
||
|
|
**源文件**: `editor/src/UI/PopupState.h`
|
||
|
|
|
||
|
|
## 签名
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
template <typename Target>
|
||
|
|
class TargetedPopupState;
|
||
|
|
```
|
||
|
|
|
||
|
|
## 作用
|
||
|
|
|
||
|
|
在延迟打开 popup 的同时,把一个目标对象或目标句柄绑定到该 popup 状态上。
|
||
|
|
|
||
|
|
## 公开接口
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
void RequestOpen(Target target);
|
||
|
|
void ConsumeOpenRequest(const char* popupId);
|
||
|
|
bool HasPendingOpenRequest() const;
|
||
|
|
bool HasTarget() const;
|
||
|
|
Target& TargetValue();
|
||
|
|
const Target& TargetValue() const;
|
||
|
|
void Clear();
|
||
|
|
```
|
||
|
|
|
||
|
|
## 当前实现行为
|
||
|
|
|
||
|
|
- `RequestOpen(target)`
|
||
|
|
- 会把 `target` 移入 `m_target`
|
||
|
|
- 把 `m_hasTarget` 设为 `true`
|
||
|
|
- 再通过内部 `DeferredPopupState` 记录一次待开请求
|
||
|
|
- `ConsumeOpenRequest(...)`
|
||
|
|
- 直接转发给内部 `DeferredPopupState`
|
||
|
|
- `HasPendingOpenRequest()`
|
||
|
|
- 返回当前是否还存在未消费的 popup 打开请求
|
||
|
|
- `HasTarget()`
|
||
|
|
- 返回当前是否已绑定有效目标
|
||
|
|
- `TargetValue()`
|
||
|
|
- 返回当前绑定目标
|
||
|
|
- `Clear()`
|
||
|
|
- 清空内部 popup 请求
|
||
|
|
- 把目标重置为 `Target{}`
|
||
|
|
- 把 `m_hasTarget` 设回 `false`
|
||
|
|
|
||
|
|
## 典型使用位置
|
||
|
|
|
||
|
|
- `HierarchyActionRouter` 用 `TargetedPopupState<GameObject*>` 维护实体右键菜单目标
|
||
|
|
- `ProjectActionRouter` 用 `TargetedPopupState<AssetItemPtr>` 维护项目资源项上下文菜单目标
|
||
|
|
|
||
|
|
## 当前实现边界
|
||
|
|
|
||
|
|
- 目标对象的生命周期不由该类型管理。
|
||
|
|
- 它只保存一个值或句柄,不做失效检测。
|
||
|
|
|
||
|
|
## 相关文档
|
||
|
|
|
||
|
|
- [PopupState](PopupState.md)
|
||
|
|
- [DeferredPopupState](DeferredPopupState.md)
|
||
|
|
- [ProjectActionRouter](../../Actions/ProjectActionRouter/ProjectActionRouter.md)
|