-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using NUnit.Framework; | ||
|
||
namespace UIComponents.Tests | ||
{ | ||
[TestFixture] | ||
public class RootClassAttributeTests | ||
{ | ||
[RootClass("test-class")] | ||
private class ComponentWithRootClass : UIComponent {} | ||
|
||
[Test] | ||
public void Adds_Class_To_Component() | ||
{ | ||
var component = new ComponentWithRootClass(); | ||
Assert.That(component.ClassListContains("test-class"), Is.True); | ||
} | ||
|
||
[RootClass("other-test-class")] | ||
[RootClass("final-test-class")] | ||
private class ChildComponentWithRootClass : ComponentWithRootClass {} | ||
|
||
[Test] | ||
public void Adds_Class_To_Component_And_Child_Component() | ||
{ | ||
var component = new ChildComponentWithRootClass(); | ||
Assert.That(component.ClassListContains("test-class"), Is.True); | ||
Assert.That(component.ClassListContains("other-test-class"), Is.True); | ||
Assert.That(component.ClassListContains("final-test-class"), Is.True); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
Assets/UIComponents.Tests/UIComponentEffectAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace UIComponents.Tests | ||
{ | ||
[TestFixture] | ||
public class UIComponentEffectAttributeTests | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
private class TestEffectAttribute : UIComponentEffectAttribute | ||
{ | ||
public override void Apply(UIComponent component) {} | ||
} | ||
|
||
[TestEffect] | ||
[TestEffect(Priority = -2)] | ||
[TestEffect(Priority = 5)] | ||
private class UIComponentWithEffects : UIComponent {} | ||
|
||
[Test] | ||
public void Effects_Are_Sorted_By_Priority() | ||
{ | ||
var component = new UIComponentWithEffects(); | ||
|
||
Assert.That(UIComponent.TryGetCache<UIComponentWithEffects>(out var cache), Is.True); | ||
|
||
Assert.That(cache.EffectAttributes.Count, Is.EqualTo(3)); | ||
Assert.That(cache.EffectAttributes[0].Priority, Is.EqualTo(5)); | ||
Assert.That(cache.EffectAttributes[1].Priority, Is.EqualTo(0)); | ||
Assert.That(cache.EffectAttributes[2].Priority, Is.EqualTo(-2)); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/UIComponents.Tests/UIComponentEffectAttributeTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace UIComponents | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
public class RootClassAttribute : UIComponentEffectAttribute | ||
{ | ||
private readonly string _className; | ||
|
||
public RootClassAttribute(string className) | ||
{ | ||
_className = className; | ||
} | ||
|
||
public override void Apply(UIComponent component) | ||
{ | ||
component.AddToClassList(_className); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace UIComponents | ||
{ | ||
/// <summary> | ||
/// An attribute used to apply effects to a <see cref="UIComponent"/>. | ||
/// They are applied after the layout and assets have been loaded. | ||
/// Attributes with higher priority are applied first. | ||
/// </summary> | ||
[BaseTypeRequired(typeof(UIComponent))] | ||
public abstract class UIComponentEffectAttribute : Attribute, IComparable<UIComponentEffectAttribute> | ||
{ | ||
public int Priority { get; set; } = 0; | ||
|
||
public abstract void Apply(UIComponent component); | ||
|
||
public int CompareTo(UIComponentEffectAttribute other) | ||
{ | ||
return Priority.CompareTo(other.Priority); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters