Skip to content

Commit 5e65fc1

Browse files
committed
DataBinding -> ThemeBinding
1 parent a211402 commit 5e65fc1

4 files changed

Lines changed: 19 additions & 31 deletions

File tree

org.mixedrealitytoolkit.theming/Binders/StateVisualizerEffectColorBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace MixedReality.Toolkit.Theming
1212
/// </summary>
1313
/// <remarks>
1414
/// Add one of these binders per state (or per state+effect combination) to a
15-
/// <see cref="DataBinding"/> component. Each binder reads a <c>Color</c> from the
15+
/// <see cref="ThemeBinding"/> component. Each binder reads a <c>Color</c> from the
1616
/// active theme and routes it to the matching tint effect via
1717
/// <see cref="StateVisualizer.TrySetStateTintColor(string, UnityEngine.Object, Color)"/>.
1818
/// <para/>

org.mixedrealitytoolkit.theming/Theming/DataBinding.cs renamed to org.mixedrealitytoolkit.theming/Theming/ThemeBinding.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace MixedReality.Toolkit.Theming
77
{
8-
public class DataBinding : MonoBehaviour
8+
public class ThemeBinding : MonoBehaviour
99
{
1010
[SerializeField]
1111
[Tooltip("The theme data source manager.")]
@@ -19,21 +19,21 @@ protected void OnEnable()
1919
{
2020
if (themeDataSource == null)
2121
{
22-
Debug.LogWarning($"{nameof(DataBinding)} on '{gameObject.name}' has no {nameof(ThemeDataSource)} assigned.", this);
22+
Debug.LogWarning($"{nameof(ThemeBinding)} on '{gameObject.name}' has no {nameof(ThemeDataSource)} assigned.", this);
2323
return;
2424
}
2525

2626
foreach (IBinder binder in binders)
2727
{
2828
if (binder == null)
2929
{
30-
Debug.LogWarning($"{nameof(DataBinding)} on '{gameObject.name}' has a null binder entry.", this);
30+
Debug.LogWarning($"{nameof(ThemeBinding)} on '{gameObject.name}' has a null binder entry.", this);
3131
continue;
3232
}
3333

3434
if (string.IsNullOrWhiteSpace(binder.ThemeDefinitionItemName))
3535
{
36-
Debug.LogWarning($"{nameof(DataBinding)} on '{gameObject.name}' has a {binder.GetType().Name} with no theme item assigned.", this);
36+
Debug.LogWarning($"{nameof(ThemeBinding)} on '{gameObject.name}' has a {binder.GetType().Name} with no theme item assigned.", this);
3737
}
3838

3939
binder.Subscribe(themeDataSource);

org.mixedrealitytoolkit.theming/Theming/DataBinding.cs.meta renamed to org.mixedrealitytoolkit.theming/Theming/ThemeBinding.cs.meta

File renamed without changes.

org.mixedrealitytoolkit.theming/Theming/ThemeDataSource.cs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace MixedReality.Toolkit.Theming
99
{
1010
[CreateAssetMenu(fileName = "Theme Data Source", menuName = "MRTK/Theming/Theme Data Source", order = 0)]
11-
public class ThemeDataSource : ScriptableObject, IBindable, INotifyValueChanged<Theme>, IEventHandler
11+
public class ThemeDataSource : ScriptableObject, INotifyValueChanged<Theme>
1212
{
1313
[SerializeField]
1414
private Theme activeTheme;
@@ -19,15 +19,9 @@ public class ThemeDataSource : ScriptableObject, IBindable, INotifyValueChanged<
1919
[SerializeField]
2020
private ThemeDefinition themeDefinition;
2121

22-
#region IBindable
23-
24-
IBinding IBindable.binding { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
25-
string IBindable.bindingPath { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
26-
27-
#endregion IBindable
28-
2922
#region INotifyValueChanged<Theme>
3023

24+
/// <inheritdoc/>
3125
public Theme value
3226
{
3327
get => activeTheme;
@@ -40,47 +34,41 @@ public Theme value
4034

4135
using (ChangeEvent<Theme> changeEvent = ChangeEvent<Theme>.GetPooled(activeTheme, value))
4236
{
43-
changeEvent.target = this;
37+
// target is intentionally unset, as ThemeDataSource is not a UIElements visual
38+
// element, but ChangeEvent<T> is used for its newValue/previousValue semantics
39+
// and object pooling
4440
SetValueWithoutNotify(value);
4541
SendEvent(changeEvent);
4642
}
4743
}
4844
}
4945

46+
/// <inheritdoc/>
5047
public void SetValueWithoutNotify(Theme newValue)
5148
{
5249
activeTheme = newValue;
5350
}
5451

5552
#endregion INotifyValueChanged<Theme>
5653

57-
#region IEventHandler
58-
59-
public void SendEvent(EventBase e)
60-
{
61-
if (e is ChangeEvent<Theme> changeEvent)
62-
{
63-
onThemeChanged.Invoke(changeEvent);
64-
}
65-
}
66-
67-
void IEventHandler.HandleEvent(EventBase evt) { }
68-
bool IEventHandler.HasTrickleDownHandlers() => false;
69-
bool IEventHandler.HasBubbleUpHandlers() => false;
70-
71-
#endregion IEventHandler
72-
7354
public void AddListener(UnityAction<ChangeEvent<Theme>> action)
7455
{
7556
onThemeChanged.AddListener(action);
7657
using ChangeEvent<Theme> changeEvent = ChangeEvent<Theme>.GetPooled(null, activeTheme);
77-
changeEvent.target = this;
7858
SendEvent(changeEvent);
7959
}
8060

8161
public void RemoveListener(UnityAction<ChangeEvent<Theme>> action)
8262
{
8363
onThemeChanged.RemoveListener(action);
8464
}
65+
66+
private void SendEvent(EventBase e)
67+
{
68+
if (e is ChangeEvent<Theme> changeEvent)
69+
{
70+
onThemeChanged.Invoke(changeEvent);
71+
}
72+
}
8573
}
8674
}

0 commit comments

Comments
 (0)