-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabLayout.cs
198 lines (157 loc) · 5.36 KB
/
TabLayout.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.UIElements;
namespace DockGUI
{
public class TabLayout : VisualElement, IDroppable
{
public List<Tab> tabs;
private Dictionary<DockPanel, Tab> _panelToTabDict;
private Dictionary<Tab, DockPanel> _tabToPanelDict;
private Tab _selectedTab;
private VisualElement _flexSpace;
private VisualElement _tabLayoutBg;
public DockPanelLayout DockPanelLayoutParent => (DockPanelLayout) parent;
public VisualElement TargetElement => this;
public TabLayout()
{
tabs = new List<Tab>();
_panelToTabDict = new Dictionary<DockPanel, Tab>();
_tabToPanelDict = new Dictionary<Tab, DockPanel>();
styleSheets.Add(DockGUIStyles.DefaultStyle);
AddToClassList("TabLayoutHeight");
AddToClassList("TabLayout");
_tabLayoutBg = new VisualElement();
_tabLayoutBg.styleSheets.Add(DockGUIStyles.DefaultStyle);
_tabLayoutBg.AddToClassList("TabLayoutBg");
Add(_tabLayoutBg);
RegisterCallback<MouseDownEvent>(OnMouseDown);
}
private void OnMouseDown(MouseDownEvent evt)
{
}
public bool ContainsTab(DockPanel dockPanel)
{
return _panelToTabDict.ContainsKey(dockPanel);
}
public Tab GetTab(DockPanel dockPanel)
{
return _panelToTabDict[dockPanel];
}
public Tab AddTab(DockPanel targetPanel)
{
Tab tab = new Tab(targetPanel,this);
tab.text = targetPanel.Title;
_panelToTabDict.Add(targetPanel, tab);
_tabToPanelDict.Add(tab, targetPanel);
if (targetPanel.DockPanelLayoutParent != null)
{
// if (targetPanel.DockLayoutParent.parent != null)
// {
// targetPanel.DockLayoutParent.DockLayoutParent.Remove(targetPanel.DockLayoutParent);
// }
// targetPanel.DockLayoutParent.Remove(targetPanel);
}
tabs.Add(tab);
Deselect(tab);
Add(tab);
return tab;
}
public void MoveTab(int index, Tab tab)
{
int curIndex = tabs.IndexOf(tab);
if (curIndex == index)
{
return;
}
tabs.Remove(tab);
if (index > tabs.Count)
{
tabs.Add(tab);
}
else
{
tabs.Insert(index, tab);
}
Remove(tab);
Insert(index + 1, tab);
}
public void RemoveTab(DockPanel targetPanel)
{
RemoveTab(_panelToTabDict[targetPanel]);
}
public void RemoveTab(Tab tab)
{
DockPanel dockPanel = _tabToPanelDict[tab];
_panelToTabDict.Remove(dockPanel);
_tabToPanelDict.Remove(tab);
tabs.Remove(tab);
Remove(tab);
// select the first tab if we remove the currently selected tab
if (_selectedTab == tab && tabs.Count > 0)
{
_selectedTab = null;
Select(tabs[0]);
}
}
public void OnTabClicked(Tab tab)
{
if (_selectedTab == tab)
{
return;
}
Select(tab);
}
public void Select(DockPanel dockPanel)
{
Select(_panelToTabDict[dockPanel]);
}
private void Select(Tab tab)
{
if (_selectedTab != null)
{
Deselect(_selectedTab);
}
_tabToPanelDict[tab].style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
tab.Highlight(true);
_selectedTab = tab;
}
public void Deselect(DockPanel dockPanel)
{
Deselect(_panelToTabDict[dockPanel]);
}
private void Deselect(Tab tab)
{
tab.Highlight(false);
if (!_tabToPanelDict.ContainsKey(tab))
{
Debug.Log(tab.text);
foreach (var key in _tabToPanelDict.Keys)
{
Debug.Log(key.text);
}
}
_tabToPanelDict[tab].style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
private new void Add(VisualElement element)
{
base.Add(element);
}
public DockPanel GetPanel(Tab tab)
{
if (!_tabToPanelDict.ContainsKey(tab))
{
Debug.Log("Looking for" + tab.text);
foreach (var kvp in _tabToPanelDict)
{
Debug.Log(kvp.Key.text);
Debug.Log(kvp.Key == tab);
}
}
return _tabToPanelDict[tab];
}
}
}