forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseControl.cs
More file actions
95 lines (82 loc) · 2.77 KB
/
Copy pathBaseControl.cs
File metadata and controls
95 lines (82 loc) · 2.77 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Collections.Generic;
using UnityEngine.Internal;
namespace UnityEngine.Experimental.UIElements
{
public abstract class BaseControl<T> : VisualElement, INotifyValueChanged<T>
{
public class BaseControlUxmlTraits : VisualElementUxmlTraits
{
public BaseControlUxmlTraits()
{
m_FocusIndex.defaultValue = 0;
}
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
{
get { yield break; }
}
}
public BaseControl()
{
// Controls are focusable by default
focusIndex = 0;
}
public abstract T value { get; set; }
public virtual void OnValueChanged(EventCallback<ChangeEvent<T>> callback)
{
RegisterCallback(callback);
}
public virtual void SetValueAndNotify(T newValue)
{
if (!EqualityComparer<T>.Default.Equals(value, newValue))
{
using (ChangeEvent<T> evt = ChangeEvent<T>.GetPooled(value, newValue))
{
evt.target = this;
value = newValue;
UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel);
}
}
}
}
public abstract class BaseTextControl<T> : BaseTextElement, INotifyValueChanged<T>
{
public class BaseTextControlUxmlTraits : BaseTextElementUxmlTraits
{
public BaseTextControlUxmlTraits()
{
m_FocusIndex.defaultValue = 0;
}
}
public BaseTextControl()
{
// Controls are focusable by default
focusIndex = 0;
}
// Hide text setter for controls, values must be set with the value property
public new virtual string text
{
get { return base.text; }
protected set { base.text = value; }
}
public abstract T value { get; set; }
public virtual void OnValueChanged(EventCallback<ChangeEvent<T>> callback)
{
RegisterCallback(callback);
}
public virtual void SetValueAndNotify(T newValue)
{
if (!EqualityComparer<T>.Default.Equals(value, newValue))
{
using (ChangeEvent<T> evt = ChangeEvent<T>.GetPooled(value, newValue))
{
evt.target = this;
value = newValue;
UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel);
}
}
}
}
}