-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
…GeometryChanged
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using UnityEditor; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Tests.Editor.Interfaces | ||
{ | ||
public class InterfacesTestEditorWindow : EditorWindow | ||
{ | ||
private void CreateGUI() | ||
{ | ||
rootVisualElement.Add(new Label("Hello world")); | ||
} | ||
|
||
public void AddTestComponent(UIComponent component) | ||
{ | ||
rootVisualElement.Add(component); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using NUnit.Framework; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Tests.Editor.Interfaces | ||
{ | ||
[TestFixture] | ||
public class UIComponentInterfaceTests | ||
{ | ||
private class BaseTestComponent : UIComponent | ||
{ | ||
public bool Fired { get; protected set; } | ||
} | ||
|
||
private static void Assert_Registers_Event_Callback<TComponent, TEvent>() | ||
where TComponent : BaseTestComponent, new() | ||
where TEvent : EventBase<TEvent>, new() | ||
{ | ||
var window = EditorWindow.GetWindow<InterfacesTestEditorWindow>(); | ||
var component = new TComponent(); | ||
Assert.That(component.Fired, Is.False); | ||
window.AddTestComponent(component); | ||
|
||
using (var evt = new TEvent() { target = component }) | ||
component.SendEvent(evt); | ||
|
||
Assert.That(component.Fired, Is.True); | ||
window.Close(); | ||
} | ||
|
||
private class UIComponentWithOnGeometryChanged : BaseTestComponent, IOnGeometryChanged | ||
{ | ||
public void OnGeometryChanged(GeometryChangedEvent evt) => Fired = true; | ||
} | ||
|
||
[Test] | ||
public void IOnGeometryChanged_Registers_GeometryChangedEvent_Callback() | ||
{ | ||
Assert_Registers_Event_Callback<UIComponentWithOnGeometryChanged, GeometryChangedEvent>(); | ||
} | ||
|
||
private class UIComponentWithOnAttachToPanel : BaseTestComponent, IOnAttachToPanel | ||
{ | ||
public void OnAttachToPanel(AttachToPanelEvent evt) => Fired = true; | ||
} | ||
|
||
[Test] | ||
public void IOnAttachToPanel_Registers_AttachToPanelEvent_Callback() | ||
{ | ||
Assert_Registers_Event_Callback<UIComponentWithOnAttachToPanel, AttachToPanelEvent>(); | ||
} | ||
|
||
private class UIComponentWithOnDetachFromPanel : BaseTestComponent, IOnDetachFromPanel | ||
{ | ||
public void OnDetachFromPanel(DetachFromPanelEvent evt) => Fired = true; | ||
} | ||
|
||
[Test] | ||
public void IOnDetachFromPanel_Registers_DetachFromPanelEvent_Callback() | ||
{ | ||
Assert_Registers_Event_Callback<UIComponentWithOnDetachFromPanel, DetachFromPanelEvent>(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using JetBrains.Annotations; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents | ||
{ | ||
/// <summary> | ||
/// When implemented by a <see cref="UIComponent"/>, | ||
/// a callback for <see cref="AttachToPanelEvent"/> is | ||
/// automatically registered in the UIComponent constructor. | ||
/// </summary> | ||
public interface IOnAttachToPanel | ||
{ | ||
void OnAttachToPanel([NotNull] AttachToPanelEvent evt); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using JetBrains.Annotations; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents | ||
{ | ||
/// <summary> | ||
/// When implemented by a <see cref="UIComponent"/>, | ||
/// a callback for <see cref="DetachFromPanelEvent"/> is | ||
/// automatically registered in the UIComponent constructor. | ||
/// </summary> | ||
public interface IOnDetachFromPanel | ||
{ | ||
void OnDetachFromPanel([NotNull] DetachFromPanelEvent evt); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using JetBrains.Annotations; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents | ||
{ | ||
/// <summary> | ||
/// When implemented by a <see cref="UIComponent"/>, | ||
/// a callback for <see cref="GeometryChangedEvent"/> is | ||
/// automatically registered in the UIComponent constructor. | ||
/// </summary> | ||
public interface IOnGeometryChanged | ||
{ | ||
void OnGeometryChanged([NotNull] GeometryChangedEvent evt); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.