broken
This commit is contained in:
3
Runtime/Engine/Code/UI/Builders.meta
Normal file
3
Runtime/Engine/Code/UI/Builders.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01849df87c1948778a9155b635cb0a8f
|
||||
timeCreated: 1743252918
|
||||
9
Runtime/Engine/Code/UI/IView.cs
Normal file
9
Runtime/Engine/Code/UI/IView.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace RebootKit.Engine.UI {
|
||||
public interface IView {
|
||||
UniTask Show(CancellationToken cancellationToken);
|
||||
UniTask Hide(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
3
Runtime/Engine/Code/UI/IView.cs.meta
Normal file
3
Runtime/Engine/Code/UI/IView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc4667c349ed4966bb7e16b7a790346e
|
||||
timeCreated: 1743249178
|
||||
90
Runtime/Engine/Code/UI/IVisualElementBuilder.cs
Normal file
90
Runtime/Engine/Code/UI/IVisualElementBuilder.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RebootKit.Engine.UI {
|
||||
public static class Classes {
|
||||
public const string k_Base = "rr__base";
|
||||
public const string k_Label = "rr__label";
|
||||
public const string k_Button = "rr__button";
|
||||
}
|
||||
|
||||
public interface IVisualElementBuilder {
|
||||
VisualElement Build();
|
||||
}
|
||||
|
||||
public class VisualElementBuilder : IVisualElementBuilder {
|
||||
readonly List<string> m_ClassNames = new();
|
||||
|
||||
Color? m_BackgroundColor;
|
||||
float2? m_Size;
|
||||
|
||||
VisualElementBuilder() {
|
||||
}
|
||||
|
||||
public VisualElementBuilder Class(string className) {
|
||||
m_ClassNames.Add(className);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VisualElementBuilder Class(params string[] classNames) {
|
||||
foreach (string className in classNames) {
|
||||
m_ClassNames.Add(className);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public VisualElementBuilder BackgroundColor(Color color) {
|
||||
m_BackgroundColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VisualElementBuilder Size(float2 size) {
|
||||
m_Size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
VisualElement element = new();
|
||||
element.AddToClassList(Classes.k_Base);
|
||||
|
||||
foreach (string className in m_ClassNames) {
|
||||
element.AddToClassList(className);
|
||||
}
|
||||
|
||||
if (m_BackgroundColor.HasValue) {
|
||||
element.style.backgroundColor = m_BackgroundColor.Value;
|
||||
}
|
||||
|
||||
if (m_Size.HasValue) {
|
||||
element.style.width = m_Size.Value.x;
|
||||
element.style.height = m_Size.Value.y;
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public static VisualElementBuilder New() {
|
||||
return new VisualElementBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct LabelBuilder : IVisualElementBuilder {
|
||||
readonly string m_Text;
|
||||
|
||||
LabelBuilder(string text) {
|
||||
m_Text = text;
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
Label label = new(m_Text);
|
||||
label.AddToClassList(Classes.k_Base);
|
||||
label.AddToClassList(Classes.k_Label);
|
||||
return label;
|
||||
}
|
||||
|
||||
public static LabelBuilder New(string text) => new(text);
|
||||
}
|
||||
}
|
||||
3
Runtime/Engine/Code/UI/IVisualElementBuilder.cs.meta
Normal file
3
Runtime/Engine/Code/UI/IVisualElementBuilder.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17dda39a215248bba526d52f4d0886f3
|
||||
timeCreated: 1743252930
|
||||
38
Runtime/Engine/Code/UI/UIDocumentView.cs
Normal file
38
Runtime/Engine/Code/UI/UIDocumentView.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.UIElements;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootKit.Engine.UI {
|
||||
public abstract class UIDocumentView : MonoBehaviour, IView, IVisualElementBuilder {
|
||||
static readonly Logger s_logger = new(nameof(UIDocumentView));
|
||||
|
||||
[SerializeField] UIDocument m_Document;
|
||||
|
||||
void OnEnable() {
|
||||
s_logger.Debug("START");
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
public async UniTask Show(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
public async UniTask Hide(CancellationToken cancellationToken) {
|
||||
await UniTask.Yield(cancellationToken);
|
||||
}
|
||||
|
||||
protected void Rebuild() {
|
||||
Profiler.BeginSample("UI Tree Build");
|
||||
VisualElement child = Build();
|
||||
Profiler.EndSample();
|
||||
|
||||
m_Document.rootVisualElement.Q<VisualElement>("root__container").Clear();
|
||||
m_Document.rootVisualElement.Q<VisualElement>("root__container").Add(child);
|
||||
}
|
||||
|
||||
public abstract VisualElement Build();
|
||||
}
|
||||
}
|
||||
3
Runtime/Engine/Code/UI/UIDocumentView.cs.meta
Normal file
3
Runtime/Engine/Code/UI/UIDocumentView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5034480a2141411b96f6baffb6f7294c
|
||||
timeCreated: 1743253410
|
||||
Reference in New Issue
Block a user