-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockPanel.cs
86 lines (71 loc) · 2.8 KB
/
DockPanel.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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace DockGUI
{
public class DockPanel : VisualElement
{
public List<DockPanel> dockedPanels;
private string _title;
public string Title => _title;
public DockPanelLayout DockPanelLayoutParent => (DockPanelLayout) parent;
public bool HasDockLayoutParent => parent is DockPanelLayout;
public bool IsFloating => DockPanelLayoutParent.IsFloating;
public bool HasDockPanelLayoutParent {
get
{
if (parent == null)
{
return false;
}
return parent.GetType() == typeof(DockPanelLayout);
}
}
public DockPanel(string title) : this(title, DockGUIStyles.DefaultStyle) { }
public DockPanel(string title, StyleSheet styleSheet)
{
_title = title;
styleSheets.Add(styleSheet);
AddToClassList("DockPanel");
}
public DockPanelLayout FreeFloat(float x, float y)
{
DockPanelLayout dockPanelLayoutParent = DockPanelLayoutParent;
List<DockPanel> dockPanels = dockPanelLayoutParent.DockPanels;
DockPanelLayout floatingLayout = null;
DockLayout rootElement = dockPanelLayoutParent.GetRootDockLayout();
if (dockPanels.Count > 1)
{
// just detach this panel from the panelLayout
dockPanelLayoutParent.RemovePanel(this);
}
else
{
// no panels left in the panelLayout, destroy it
if (dockPanelLayoutParent.IsFloating)
{
// if it's floating, it's not a flex/docked container, so just remove it normally
dockPanelLayoutParent.DockLayoutParent.Remove(dockPanelLayoutParent);
}
else
{
dockPanelLayoutParent.DockLayoutParent.RemoveContainer(dockPanelLayoutParent);
}
}
// create a new floating layout for this panel
floatingLayout = new DockPanelLayout {IsFloating = true};
floatingLayout.AddPanel(this);
floatingLayout.AddToClassList("FloatingLayout");
floatingLayout.transform.position = new Vector3(x,y, floatingLayout.transform.position.z);
rootElement.Add(floatingLayout);
return floatingLayout;
}
private new void Add(VisualElement element)
{
throw new Exception();
}
}
}