-
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.
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 @@ | ||
:root { | ||
margin: 2px 8px; | ||
} | ||
|
||
#example-header { | ||
margin-bottom: 10px; | ||
} | ||
|
||
#example-header Label { | ||
white-space: normal; | ||
} | ||
|
||
.example-container { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
padding: 6px 16px; | ||
margin-bottom: 4px; | ||
border-color: aliceblue; | ||
border-radius: 4px; | ||
border-width: 2px; | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<UXML xmlns:ui="UnityEngine.UIElements" xmlns:sample="UIComponents.Samples.UxmlTraits"> | ||
<ui:VisualElement name="example-header"> | ||
<ui:Label text="The UxmlTrait and UxmlName attributes generate UxmlFactory and UxmlTraits implementations for you." /> | ||
<ui:Label text="Three components are instantiated in UXML below. They use UXML traits for customization." /> | ||
</ui:VisualElement> | ||
<ui:VisualElement class="example-container"> | ||
<ui:Label text="Bare component" /> | ||
<sample:UxmlTraitsExample /> | ||
</ui:VisualElement> | ||
<ui:VisualElement class="example-container"> | ||
<ui:Label text="Overridden description" /> | ||
<sample:UxmlTraitsExample description-text="This is my custom description." /> | ||
</ui:VisualElement> | ||
<ui:VisualElement class="example-container"> | ||
<ui:Label text="Overridden button color" /> | ||
<sample:UxmlTraitsExample button-color="#49006F" /> | ||
</ui:VisualElement> | ||
</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,18 @@ | ||
{ | ||
"name": "UIComponents.Samples.UxmlTraits.Editor", | ||
"rootNamespace": "UIComponents.Samples", | ||
"references": [ | ||
"UIComponents.Samples.UxmlTraits" | ||
], | ||
"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,28 @@ | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Samples.UxmlTraits.Editor | ||
{ | ||
public class UxmlTraitsExampleWindow : UnityEditor.EditorWindow | ||
{ | ||
[UnityEditor.MenuItem("UIComponents Examples/UxmlTraits and UxmlName")] | ||
private static void ShowWindow() | ||
{ | ||
var window = GetWindow<UxmlTraitsExampleWindow>(); | ||
window.titleContent = new GUIContent("UxmlTraits and UxmlName"); | ||
window.minSize = new Vector2(470, 250); | ||
window.Show(); | ||
} | ||
|
||
private void CreateGUI() | ||
{ | ||
var layout = Resources.Load<VisualTreeAsset>("UxmlTraitsExampleWindow"); | ||
|
||
layout.CloneTree(rootVisualElement); | ||
|
||
var styles = Resources.Load<StyleSheet>("UxmlTraitsExampleWindow.style"); | ||
|
||
rootVisualElement.styleSheets.Add(styles); | ||
} | ||
} | ||
} |
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,12 @@ | ||
#uxml-traits-container { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
#uxml-traits-container Label { | ||
-unity-font-style: bold; | ||
} | ||
|
||
#uxml-traits-description-label { | ||
-unity-font-style: italic; | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:VisualElement name="uxml-traits-container"> | ||
<ui:Label text="UxmlTraitsExampleComponent" /> | ||
<ui:Button name="uxml-traits-button" text="Button" /> | ||
</ui:VisualElement> | ||
<ui:Label name="uxml-traits-description-label" text="No description set." /> | ||
</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.UxmlTraits", | ||
"rootNamespace": "UIComponents.Samples", | ||
"references": [ | ||
"UIComponents" | ||
], | ||
"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,46 @@ | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Samples.UxmlTraits | ||
{ | ||
/// <summary> | ||
/// An example component which uses UxmlName and UxmlTrait. | ||
/// The component is instantiated with the name "UxmlTraitsExample" in UXML, | ||
/// and the UxmlTrait attributes generate the necessary code for | ||
/// customizing this component in UXML. | ||
/// </summary> | ||
[UxmlName("UxmlTraitsExample")] | ||
[Layout("UxmlTraitsExampleComponent")] | ||
[Stylesheet("UxmlTraitsExampleComponent.style")] | ||
public partial class UxmlTraitsExampleComponent : UIComponent | ||
{ | ||
[UxmlTrait] | ||
public string DescriptionText | ||
{ | ||
set | ||
{ | ||
_descriptionText = value; | ||
if (_descriptionLabel != null) | ||
_descriptionLabel.text = value; | ||
} | ||
} | ||
private string _descriptionText; | ||
|
||
[UxmlTrait] | ||
private Color _buttonColor; | ||
|
||
[Query("uxml-traits-button")] | ||
private Button _button; | ||
|
||
[Query("uxml-traits-description-label")] | ||
private Label _descriptionLabel; | ||
|
||
public override void OnInit() | ||
{ | ||
if (!string.IsNullOrEmpty(_descriptionText)) | ||
_descriptionLabel.text = _descriptionText; | ||
|
||
_button.style.backgroundColor = _buttonColor; | ||
} | ||
} | ||
} |
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:editor="UnityEditor.UIElements" xmlns:engine="UnityEngine.UIElements" xmlns="UnityEditor.PackageManager.UI" elementFormDefault="qualified" targetNamespace="UIComponents.Samples.UxmlTraits" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:import schemaLocation="UnityEngine.UIElements.xsd" namespace="UnityEngine.UIElements" /> | ||
<xs:complexType name="UxmlTraitsExampleType"> | ||
<xs:complexContent mixed="false"> | ||
<xs:restriction base="engine:VisualElementType"> | ||
<xs:sequence minOccurs="0" maxOccurs="unbounded"> | ||
<xs:element ref="engine:VisualElement" /> | ||
</xs:sequence> | ||
<xs:attribute default="" name="name" type="xs:string" use="optional" /> | ||
<xs:attribute default="" name="view-data-key" type="xs:string" use="optional" /> | ||
<xs:attribute default="Position" name="picking-mode" type="engine:VisualElement_picking-mode_Type" use="optional" /> | ||
<xs:attribute default="" name="tooltip" type="xs:string" use="optional" /> | ||
<xs:attribute default="None" name="usage-hints" type="engine:VisualElement_usage-hints_Type" use="optional" /> | ||
<xs:attribute default="0" name="tabindex" type="xs:int" use="optional" /> | ||
<xs:attribute default="false" name="focusable" type="xs:boolean" use="optional" /> | ||
<xs:attribute default="" name="class" type="xs:string" use="optional" /> | ||
<xs:attribute default="" name="content-container" type="xs:string" use="optional" /> | ||
<xs:attribute default="" name="style" type="xs:string" use="optional" /> | ||
<xs:attribute default="RGBA(0.000, 0.000, 0.000, 1.000)" name="button-color" type="xs:string" use="optional" /> | ||
<xs:attribute default="" name="description-text" type="xs:string" use="optional" /> | ||
<xs:anyAttribute processContents="lax" /> | ||
</xs:restriction> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
<xs:element name="UxmlTraitsExample" substitutionGroup="engine:VisualElement" xmlns:q1="UIComponents.Samples.UxmlTraits" type="q1:UxmlTraitsExampleType" /> | ||
</xs:schema> |