forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIContent.cs
More file actions
177 lines (153 loc) · 5.36 KB
/
GUIContent.cs
File metadata and controls
177 lines (153 loc) · 5.36 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
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Runtime.InteropServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
namespace UnityEngine
{
// The contents of a GUI element.
[StructLayout(LayoutKind.Sequential)]
[Serializable]
[NativeHeader("Modules/IMGUI/GUIContent.h")]
[RequiredByNativeCode(Optional = true, GenerateProxy = true)]
public class GUIContent
{
// MUST MATCH MEMORY LAYOUT IN GUICONTENT.CPP
[SerializeField]
string m_Text = string.Empty;
[SerializeField]
Texture m_Image;
[SerializeField]
string m_Tooltip = string.Empty;
private static readonly GUIContent s_Text = new GUIContent();
private static readonly GUIContent s_Image = new GUIContent();
private static readonly GUIContent s_TextImage = new GUIContent();
// The text contained.
public string text
{
get { return m_Text; }
set { m_Text = value; }
}
// The icon image contained.
public Texture image
{
get { return m_Image; }
set { m_Image = value; }
}
// The tooltip of this element.
public string tooltip
{
get { return m_Tooltip; }
set { m_Tooltip = value; }
}
// Constructor for GUIContent in all shapes and sizes
public GUIContent() {}
// Build a GUIContent object containing only text.
public GUIContent(string text) :
this(text, null, string.Empty)
{}
// Build a GUIContent object containing only an image.
public GUIContent(Texture image) :
this(string.Empty, image, string.Empty)
{}
// Build a GUIContent object containing both /text/ and an image.
public GUIContent(string text, Texture image) :
this(text, image, string.Empty)
{}
// Build a GUIContent containing some /text/. When the user hovers the mouse over it, the global GUI::ref::tooltip is set to the /tooltip/.
public GUIContent(string text, string tooltip) :
this(text, null, tooltip)
{}
// Build a GUIContent containing an image. When the user hovers the mouse over it, the global GUI::ref::tooltip is set to the /tooltip/.
public GUIContent(Texture image, string tooltip) :
this(string.Empty, image, tooltip)
{}
// Build a GUIContent that contains both /text/, an /image/ and has a /tooltip/ defined. When the user hovers the mouse over it, the global GUI::ref::tooltip is set to the /tooltip/.
public GUIContent(string text, Texture image, string tooltip)
{
this.text = text;
this.image = image;
this.tooltip = tooltip;
}
// Build a GUIContent as a copy of another GUIContent.
public GUIContent(GUIContent src)
{
text = src.m_Text;
image = src.m_Image;
tooltip = src.m_Tooltip;
}
// Shorthand for empty content.
public static GUIContent none = new GUIContent("");
// *undocumented*
internal int hash
{
get
{
int h = 0;
if (!string.IsNullOrEmpty(m_Text))
h = m_Text.GetHashCode() * 37;
return h;
}
}
internal static GUIContent Temp(string t)
{
s_Text.m_Text = t;
s_Text.m_Tooltip = string.Empty;
return s_Text;
}
internal static GUIContent Temp(string t, string tooltip)
{
s_Text.m_Text = t;
s_Text.m_Tooltip = tooltip;
return s_Text;
}
internal static GUIContent Temp(Texture i)
{
s_Image.m_Image = i;
s_Image.m_Tooltip = string.Empty;
return s_Image;
}
internal static GUIContent Temp(Texture i, string tooltip)
{
s_Image.m_Image = i;
s_Image.m_Tooltip = tooltip;
return s_Image;
}
internal static GUIContent Temp(string t, Texture i)
{
s_TextImage.m_Text = t;
s_TextImage.m_Image = i;
return s_TextImage;
}
[VisibleToOtherModules("UnityEngine.UIElementsModule")]
internal static void ClearStaticCache()
{
s_Text.m_Text = null;
s_Text.m_Tooltip = string.Empty;
s_Image.m_Image = null;
s_Image.m_Tooltip = string.Empty;
s_TextImage.m_Text = null;
s_TextImage.m_Image = null;
}
internal static GUIContent[] Temp(string[] texts)
{
GUIContent[] retval = new GUIContent[texts.Length];
for (int i = 0; i < texts.Length; i++)
{
retval[i] = new GUIContent(texts[i]);
}
return retval;
}
internal static GUIContent[] Temp(Texture[] images)
{
GUIContent[] retval = new GUIContent[images.Length];
for (int i = 0; i < images.Length; i++)
{
retval[i] = new GUIContent(images[i]);
}
return retval;
}
}
}