-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(QueryAttribute): combine QueryAttribute and QueryClassAttribute
- Loading branch information
Showing
12 changed files
with
123 additions
and
125 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
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
4 changes: 2 additions & 2 deletions
4
Assets/UIComponents.Tests/Resources/UIComponentTests/LayoutAttributeTests.uxml
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:Label name="hello-world-label" text="Hello world!" /> | ||
<ui:Label name="hello-world-label" text="Hello world!" class="text" /> | ||
<ui:Foldout name="test-foldout"> | ||
<ui:Label name="foldout-content" text="Foldout content" /> | ||
<ui:Label name="foldout-content" text="Foldout content" class="text" /> | ||
</ui:Foldout> | ||
</UXML> |
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 |
---|---|---|
@@ -1,29 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Experimental | ||
{ | ||
/// <summary> | ||
/// An attribute for specifying the name of a VisualElement, which is then | ||
/// automatically queried and populated in the UIComponent constructor. | ||
/// If the field type is an array or List, the queried element will be | ||
/// placed into it. | ||
/// An attribute for specifying a single query for a field. | ||
/// A name and class can be specified for each query. | ||
/// Queries are made in the UIComponent constructor. | ||
/// </summary> | ||
/// <seealso cref="QueryClassAttribute"/> | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public class QueryAttribute : QueryAttributeBase | ||
/// <example> | ||
/// [Layout("MyLayout")] | ||
/// public class ComponentWithQueries : UIComponent | ||
/// { | ||
/// [Query(Name = "hello-world-label")] | ||
/// private readonly Label HelloWorldLabel; | ||
/// | ||
/// [Query(Class = "red")] | ||
/// private readonly Label[] RedLabels; | ||
/// | ||
/// [Query] | ||
/// private readonly Label FirstLabel; | ||
/// | ||
/// [Query] | ||
/// public readonly Label[] AllLabels; | ||
/// } | ||
/// </example> | ||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] | ||
public class QueryAttribute : Attribute | ||
{ | ||
private readonly string _name; | ||
public string Name { get; set; } | ||
|
||
public string Class { get; set; } | ||
|
||
public QueryAttribute(string name) | ||
{ | ||
_name = name; | ||
Name = name; | ||
} | ||
|
||
public QueryAttribute() {} | ||
|
||
public override void Query(VisualElement root, List<VisualElement> results) | ||
public void Query(VisualElement root, List<VisualElement> results) | ||
{ | ||
root.Query(_name).ToList(results); | ||
root.Query(Name, Class).ToList(results); | ||
} | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
Assets/UIComponents/Core/Experimental/QueryAttributeBase.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
Assets/UIComponents/Core/Experimental/QueryAttributeBase.cs.meta
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
Assets/UIComponents/Core/Experimental/QueryClassAttribute.cs
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Assets/UIComponents/Core/Experimental/QueryClassAttribute.cs.meta
This file was deleted.
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