namespace UnityEngine.Rendering { public partial class DebugUI { /// /// Base class for "container" type widgets, although it can be used on its own (if a display name is set then it'll behave as a group with a header) /// public class Container : Widget, IContainer { /// /// List of children. /// public ObservableList children { get; private set; } /// /// Panel the container is attached to. /// public override Panel panel { get { return m_Panel; } internal set { m_Panel = value; // Bubble down foreach (var child in children) child.panel = value; } } /// /// Constructor /// public Container() { displayName = ""; children = new ObservableList(); children.ItemAdded += OnItemAdded; children.ItemRemoved += OnItemRemoved; } /// /// Constructor. /// /// Display name of the container. /// List of attached children. public Container(string displayName, ObservableList children) { this.displayName = displayName; this.children = children; children.ItemAdded += OnItemAdded; children.ItemRemoved += OnItemRemoved; } internal override void GenerateQueryPath() { base.GenerateQueryPath(); foreach (var child in children) child.GenerateQueryPath(); } /// /// Method called when a children is added. /// /// Sender widget. /// List of added children. protected virtual void OnItemAdded(ObservableList sender, ListChangedEventArgs e) { if (e.item != null) { e.item.panel = m_Panel; e.item.parent = this; } if (m_Panel != null) m_Panel.SetDirty(); } /// /// Method called when a children is removed. /// /// Sender widget. /// List of removed children. protected virtual void OnItemRemoved(ObservableList sender, ListChangedEventArgs e) { if (e.item != null) { e.item.panel = null; e.item.parent = null; } if (m_Panel != null) m_Panel.SetDirty(); } /// /// Returns the hash code of the widget. /// /// Hash code of the widget. public override int GetHashCode() { int hash = 17; hash = hash * 23 + queryPath.GetHashCode(); foreach (var child in children) hash = hash * 23 + child.GetHashCode(); return hash; } } /// /// Unity-like foldout that can be collapsed. /// public class Foldout : Container, IValueField { /// /// Always false. /// public bool isReadOnly { get { return false; } } /// /// Opened state of the foldout. /// public bool opened; /// /// List of columns labels. /// public string[] columnLabels { get; set; } = null; /// /// Constructor. /// public Foldout() : base() { } /// /// Constructor. /// /// Display name of the foldout. /// List of attached children. /// Optional list of column names. public Foldout(string displayName, ObservableList children, string[] columnLabels = null) : base(displayName, children) { this.columnLabels = columnLabels; } /// /// Get the opened state of the foldout. /// /// True if the foldout is opened. public bool GetValue() => opened; /// /// Get the opened state of the foldout. /// /// True if the foldout is opened. object IValueField.GetValue() => GetValue(); /// /// Set the opened state of the foldout. /// /// True to open the foldout, false to close it. public void SetValue(object value) => SetValue((bool)value); /// /// Validates the value of the widget before setting it. /// /// Input value. /// The validated value. public object ValidateValue(object value) => value; /// /// Set the value of the widget. /// /// Input value. public void SetValue(bool value) => opened = value; } /// /// Horizontal Layout Container. /// public class HBox : Container { /// /// Constructor. /// public HBox() { displayName = "HBox"; } } /// /// Vertical Layout Container. /// public class VBox : Container { /// /// Constructor. /// public VBox() { displayName = "VBox"; } } } }