Repository navigation
Expand file tree
/
Copy pathExample_MMTreeView.as
More file actions
109 lines (89 loc) · 2.52 KB
/
Copy pathExample_MMTreeView.as
File metadata and controls
109 lines (89 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#if EDITOR
class UExample_MMTreeView : UMMEditorUtilityTab
{
default TabTitle = "Example MM Tree View";
default Category = "Example Tabs";
default Icon = n"ClassIcon.Actor";
TArray<UExampleMMTreeViewItem> ExampleItems;
UFUNCTION(BlueprintOverride)
void DrawTab(float DeltaTime)
{
// Create a tree view and set the root items to show
mm<UTreeView> TreeView = mm::Widget(UTreeView);
TreeView.SetListItems(ExampleItems);
TreeView.SetEntryWidgetClass(UExampleMMTreeViewEntryWidget);
// Bind function to let the treeview discover children
TreeView.OnGetItemChildren(this, n"OnGetTreeViewChildren");
}
UFUNCTION()
private void OnGetTreeViewChildren(UObject Item, TArray<UObject>& Children)
{
UExampleMMTreeViewItem TreeItem = Cast<UExampleMMTreeViewItem>(Item);
Children = TreeItem.Children;
}
UFUNCTION(BlueprintOverride)
void OnTabOpened()
{
// Build a simple tree
{
UExampleMMTreeViewItem Item = UExampleMMTreeViewItem();
Item.ItemName = "First Parent";
ExampleItems.Add(Item);
{
UExampleMMTreeViewItem Child = UExampleMMTreeViewItem();
Child.ItemName = "Child 1-1";
Item.Children.Add(Child);
}
{
UExampleMMTreeViewItem Child = UExampleMMTreeViewItem();
Child.ItemName = "Child 1-2";
Item.Children.Add(Child);
}
}
{
UExampleMMTreeViewItem Item = UExampleMMTreeViewItem();
Item.ItemName = "Second Parent";
ExampleItems.Add(Item);
{
UExampleMMTreeViewItem Child = UExampleMMTreeViewItem();
Child.ItemName = "Child 2-1";
Item.Children.Add(Child);
}
}
{
UExampleMMTreeViewItem Item = UExampleMMTreeViewItem();
Item.ItemName = "Third Parent";
ExampleItems.Add(Item);
}
}
}
class UExampleMMTreeViewItem
{
FString ItemName;
TArray<UExampleMMTreeViewItem> Children;
}
class UExampleMMTreeViewEntryWidget : UMMListViewEntryWidget
{
UFUNCTION(BlueprintOverride)
void DrawWidget(float DeltaTime)
{
// Get the item data associated with the tree view
UExampleMMTreeViewItem Item = GetListItem(UExampleMMTreeViewItem);
// Draw a black background for the item widget
mm<UBorder> Border = mm::WithinBorder(FLinearColor::Black);
mm::BeginHorizontalBox();
// Show a plus if the item is expanded
if (IsListItemExpanded() && Item.Children.Num() != 0)
mm::Image(n"Plus", 16, 16);
else
mm::Spacer(16);
mm::Spacer(10);
// Show the name of the item
mm::Text(Item.ItemName);
mm::EndHorizontalBox();
// Expand the item if it's clicked
if (Border.WasClicked())
SetListItemExpanded(!IsListItemExpanded());
}
}
#endif