-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
MiscExample.cs
118 lines (97 loc) · 3.74 KB
/
MiscExample.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
using System.Linq;
using UnityEngine;
namespace RapidGUI.Example
{
/// <summary>
/// Misc examples
/// </summary>
public class MiscExample : ExampleBase
{
protected override string title => "Misc";
public bool useFastScrollView = true;
FastScrollView fastScrollView = new FastScrollView();
Vector2 scPos;
public int scrollViewItemCount = 1000;
int selectionPopupIdx;
string selectionPopupStr;
public override void DoGUI()
{
using (new RGUI.IndentScope())
{
GUILayout.Label("IndentScope");
}
using (new RGUI.ColorScope(Color.green))
{
GUILayout.Label("ColorScope");
}
using (new RGUI.BackgroundColorScope(Color.red))
{
GUILayout.Button("BackgroundColorScope");
}
using (new RGUI.EnabledScope(false))
{
GUILayout.Label("EnabledScope");
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Popup");
GUILayout.Box("Popup");
var resultIdx = RGUI.PopupOnLastRect(new[] { "Button One", "Button Two", "Button Three" });
if (resultIdx >= 0)
{
Debug.Log($"Popup: Button{resultIdx + 1}");
}
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Popup with so many elements");
GUILayout.Box("A scrollbar appears when the pop-up protrudes from the screen");
RGUI.PopupOnLastRect(Enumerable.Range(0, 100).Select(i => "Element " + i.ToString()).ToArray());
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("SelectionPopup");
selectionPopupIdx = RGUI.SelectionPopup(selectionPopupIdx, new[] { "One", "Two", "Three" });
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("SelectionPopupStr");
selectionPopupStr = RGUI.SelectionPopup(selectionPopupStr, new[] { "One", "Two", "Three" });
}
GUILayout.Space(8f);
GUILayout.Label("FastScrollView (doesn't slow down even if there are many items.)");
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("ItemNum");
if (int.TryParse(GUILayout.TextField(scrollViewItemCount.ToString()), out var count))
{
if (scrollViewItemCount != count)
{
scrollViewItemCount = count;
fastScrollView.SetNeedUpdateLayout();
}
}
}
using (new RGUI.IndentScope())
{
useFastScrollView = GUILayout.Toggle(useFastScrollView, nameof(useFastScrollView));
var items = Enumerable.Range(0, scrollViewItemCount);
using (new GUILayout.VerticalScope(GUILayout.Height(500)))
{
if (useFastScrollView)
{
fastScrollView.DoGUI(items, (item) => GUILayout.Label($"FastScrollView item: {item}"));
}
else
{
using (var sv = new GUILayout.ScrollViewScope(scPos))
{
scPos = sv.scrollPosition;
items.ToList().ForEach(i => GUILayout.Label($"ScrollView item: {i}"));
}
}
}
}
}
}
}