Game.UI.Widgets.ExpandableGroup
Assembly: Game
Namespace: Game.UI.Widgets
Type: class
Base: NamedWidgetWithTooltip, IExpandable, IContainerWidget
Summary:
ExpandableGroup is a UI container widget that can be expanded or collapsed. Its expanded state is backed by an ITypedValueAccessor
Fields
-
private ITypedValueAccessor<bool> m_ExpandedAccessor
Accessor used to read/write the expanded state. Allows binding the expanded state to external data (e.g., a settings store or view model). -
private bool m_Expanded
Local cached value of the expanded state used to detect changes between updates. -
private IList<IWidget> m_Children = Array.Empty<IWidget>()
The full list of child widgets owned by this group. Defaults to an empty, immutable array until set.
Properties
-
public virtual bool expanded { get; private set }
Public property exposing the expanded state. The getter reads the current value from m_ExpandedAccessor. The setter writes through m_ExpandedAccessor.SetTypedValue(value), so changes go through the bound accessor (and may be rejected if the accessor is read-only). -
public IList<IWidget> children { get; set }
The list of child widgets. When assigning a new list, ContainerExtensions.SetDefaults(value) is called to apply default settings to children. If the list changes and the group is currently expanded, SetChildrenChanged() is triggered so the UI can update. -
public override IList<IWidget> visibleChildren { get; }
Returns the children that should be considered visible by the UI. If expanded is false, returns an empty array; otherwise returns children.
Constructors
-
public ExpandableGroup(ITypedValueAccessor<bool> expandedAccessor)
Constructs an ExpandableGroup that uses the provided accessor to get and set the expanded state. Initializes m_Expanded with the accessor's current value. -
public ExpandableGroup(bool expanded = false)
Constructs an ExpandableGroup backed by an internal ObjectAccessor. Pass true to start expanded. The internal ObjectAccessor is writable.
Methods
-
protected override WidgetChanges Update()
Calls base.Update(), then reads the current boolean from m_ExpandedAccessor. If the value differs from the cached m_Expanded, the method sets the returned WidgetChanges flags to include Properties and Children and updates the cached m_Expanded. This ensures the UI reacts to external changes in the accessor (for example, when bound to a settings value or a view model). -
protected override void WriteProperties(IJsonWriter writer)
Writes widget properties to a JSON writer for serialization. Calls base.WriteProperties(writer) and then writes an "expanded" property with the current expanded value.
Usage Example
// Using the simple ctor with an internal accessor
var group = new ExpandableGroup(expanded: true);
// Set children (assumes MyWidget implements IWidget)
group.children = new List<IWidget> {
new MyWidget("Child 1"),
new MyWidget("Child 2")
};
// Toggle expanded
group.expanded = false; // writes through the group's accessor
// Using an external accessor (bindable)
var accessor = new ObjectAccessor<bool>(false, readOnly: false);
var boundGroup = new ExpandableGroup(accessor);
accessor.SetTypedValue(true); // changing accessor will be picked up in Update()
Notes: - If you pass an accessor that is read-only, attempting to set expanded will depend on the accessor implementation (it may throw or ignore the write). Prefer writable accessors when you need to modify expanded from code. - children setter calls ContainerExtensions.SetDefaults on the new list — ensure new child widgets are configured as needed afterwards. - visibleChildren returns an empty list when collapsed, so rendering or layout logic should use visibleChildren rather than children directly if you want collapse behavior respected.