-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTab.cs
More file actions
85 lines (72 loc) · 2.3 KB
/
Tab.cs
File metadata and controls
85 lines (72 loc) · 2.3 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
using System;
using System.Collections.Generic;
using System.Text;
using Unity.VisualScripting;
using UnityEngine;
namespace SimpleModMenu
{
internal abstract class Tab
{
public string title;
public Vector2 size;
public Vector2 position;
private GUIStyle _centeredLabel;
public Tab(string title)
{
this.title = title;
this.size = Ui.GetMenuRect().size;
this.position = new Vector2(0, 0);
}
public virtual void DrawTab()
{
InitCenteredLabel();
}
private void InitCenteredLabel()
{
if (_centeredLabel == null)
{
_centeredLabel = new GUIStyle(GUI.skin.label);
_centeredLabel.alignment = TextAnchor.MiddleCenter;
}
}
public void DrawSlider(string label, ref float value, float min, float max)
{
// Draw label
GUILayout.BeginHorizontal();
GUILayout.Space(20);
GUILayout.Label(label);
GUILayout.EndHorizontal();
// Draw slider
GUILayout.BeginHorizontal();
GUILayout.Space(20);
value = GUILayout.HorizontalSlider(value, min, max, GUILayout.ExpandWidth(true));
GUILayout.Label(value.ToString("F2"), _centeredLabel, GUILayout.Width(100));
GUILayout.EndHorizontal();
}
public void DrawToggle(string label, ref bool value)
{
GUILayout.BeginHorizontal();
GUILayout.Label(label);
value = GUILayout.Toggle(value, "");
GUILayout.EndHorizontal();
}
public void DrawButton(string label, Action action)
{
if (GUILayout.Button(label))
{
action?.Invoke();
}
}
public void DrawButton(string label, float width, Action action)
{
float clampedWidth = Mathf.Clamp01(width); // Prevent values outside 0..1
float pixelWidth = Ui.GetMenuRect().width * clampedWidth;
GUILayout.BeginHorizontal();
if (GUILayout.Button(label, GUILayout.Width(pixelWidth)))
{
action?.Invoke();
}
GUILayout.EndHorizontal();
}
}
}