BlueRoseNote/03-UnrealEngine/UI/STreeView与STableRow.md
2023-06-29 11:55:02 +08:00

40 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: STreeView与STableRow
date: 2022-08-09 13:55:15
tags: Slate
rating: ⭐️
---
# STreeView
参考网址:[UE4 STreeView的使用和示例(C++实现)](https://blog.csdn.net/wymdhr/article/details/104313596)
- RequestTreeRefresh 更新树形结构
## TreeView鼠标多选功能
代码位于STableRow.h的OnMouseButtonDown()。它作用是按住Ctrl 或者Shift时按下方向键可以多选物体。
### DragDrop机制
STreeView的拖拽事件会先在STableRow相应
- OnDragDetected():检测到拖拽事件。
- OnDragEnter():鼠标(拖拽状态)进入。
- OnDragLeave():鼠标(拖拽状态)离开。
- OnDragOver():鼠标拖拽物体过来。
- OnDrop拖拽结束。
拖拽操作类都继承自FDragDropOperation并调用类中的New函数来填充数据。并在对应的Event中获取到数据。
```c++
TSharedPtr<FDragAIGraphNode> DragNodeOp = DragDropEvent.GetOperationAs<FDragAIGraphNode>();
const TArray< TSharedRef<SGraphNode> >& DraggedNodes = DragNodeOp->GetNodes();
for (int32 Idx = 0; Idx < DraggedNodes.Num(); Idx++)
{
UAIGraphNode* DraggedNode = Cast<UAIGraphNode>(DraggedNodes[Idx]->GetNodeObj());
}
```
DragDrop不适用于多选的实现所以可以使用使用给Event绑定Lambda之后将节点实例传入进行操作。
### SListView的选择机制
STreeView的选择实现代码位于SListView声明于ITypedTableView.h几个主要的接口函数为
- Private_IsItemSelected()
- Private_IsItemSelectableOrNavigable()
- Private_SetItemSelection()
- Private_ClearSelection()
- Private_SelectRangeFromCurrentTo()