-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- 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.
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,23 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UIComponents.Samples.Query.Editor | ||
{ | ||
public class QueryExampleComponentWindow : EditorWindow | ||
{ | ||
[MenuItem("UIComponents Examples/Experimental/QueryAttribute")] | ||
private static void ShowWindow() | ||
{ | ||
var window = GetWindow<QueryExampleComponentWindow>(); | ||
window.titleContent = new GUIContent("QueryAttribute"); | ||
window.Show(); | ||
} | ||
|
||
private void CreateGUI() | ||
{ | ||
rootVisualElement.style.minWidth = 190; | ||
rootVisualElement.style.minHeight = 40; | ||
rootVisualElement.Add(new QueryExampleComponent()); | ||
} | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"name": "UIComponents.Samples.Query.Editor", | ||
"rootNamespace": "UIComponents.Samples", | ||
"references": [ | ||
"GUID:d593635333b4cae48bac5b5f0b596e90", | ||
"GUID:d180e9959e2b4d2580f328c2e6aa239d" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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,22 @@ | ||
using UIComponents.Experimental; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Samples.Query | ||
{ | ||
[Layout("QueryExampleComponent")] | ||
[Stylesheet("QueryExampleComponent.styles")] | ||
public class QueryExampleComponent : UIComponent | ||
{ | ||
[Query("my-label")] | ||
public readonly Label MyLabel; | ||
|
||
[Query("my-foldout")] | ||
public readonly Foldout MyFoldout; | ||
|
||
public QueryExampleComponent() | ||
{ | ||
MyLabel.text = "This text was set in the component constructor."; | ||
MyFoldout.Add(new Label("This label was added in the component constructor.")); | ||
} | ||
} | ||
} |
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,3 @@ | ||
Label { | ||
white-space: normal; | ||
} |
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,8 @@ | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:Label text="This is a component for demonstrating QueryAttribute, an experimental feature in UIComponents." /> | ||
<ui:Label text="QueryAttribute allows for populating UIComponent fields automatically." /> | ||
<ui:Label name="my-label" text="" /> | ||
<ui:Foldout name="my-foldout" text="Foldout..."> | ||
<ui:Label text="Foldout content" /> | ||
</ui:Foldout> | ||
</UXML> |
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,16 @@ | ||
{ | ||
"name": "UIComponents.Samples.Query", | ||
"rootNamespace": "UIComponents.Samples", | ||
"references": [ | ||
"GUID:d593635333b4cae48bac5b5f0b596e90" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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,31 @@ | ||
using NUnit.Framework; | ||
using UIComponents.Experimental; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Tests | ||
{ | ||
[TestFixture] | ||
public class QueryAttributeTests | ||
{ | ||
[Layout("UIComponentTests/LayoutAttributeTests")] | ||
private class ComponentWithQueryAttribute : UIComponent | ||
{ | ||
[Query("hello-world-label")] | ||
public readonly Label HelloWorldLabel; | ||
|
||
[Query("test-foldout")] | ||
public readonly Foldout TestFoldout; | ||
} | ||
|
||
[Test] | ||
public void Should_Populate_Fields() | ||
{ | ||
var component = new ComponentWithQueryAttribute(); | ||
|
||
Assert.That(component.HelloWorldLabel, Is.InstanceOf<Label>()); | ||
Assert.That(component.HelloWorldLabel.text, Is.EqualTo("Hello world!")); | ||
|
||
Assert.That(component.TestFoldout, Is.InstanceOf<Foldout>()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:Label text="Hello world!" /> | ||
<ui:Label name="hello-world-label" text="Hello world!" /> | ||
<ui:Foldout name="test-foldout"> | ||
<ui:Label text="Foldout content" /> | ||
</ui:Foldout> | ||
</UXML> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UIComponents.Experimental; | ||
|
||
namespace UIComponents.Cache | ||
{ | ||
public readonly struct FieldCache | ||
{ | ||
public readonly Dictionary<FieldInfo, QueryAttribute> QueryAttributes; | ||
|
||
public FieldCache(Type type) | ||
{ | ||
var fieldInfos = type.GetFields( | ||
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | ||
|
||
QueryAttributes = new Dictionary<FieldInfo, QueryAttribute>(); | ||
|
||
for (var i = 0; i < fieldInfos.Length; i++) | ||
{ | ||
var queryAttribute = fieldInfos[i].GetCustomAttribute<QueryAttribute>(); | ||
if (queryAttribute != null) | ||
QueryAttributes[fieldInfos[i]] = queryAttribute; | ||
} | ||
} | ||
} | ||
} |
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 System; | ||
|
||
namespace UIComponents.Experimental | ||
{ | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public class QueryAttribute : Attribute | ||
{ | ||
public readonly string Name; | ||
|
||
public QueryAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.