Game.UI.Widgets.ExpandableBindings
Assembly:
Assembly-CSharp (game/mod assembly containing UI widgets and bindings)
Namespace:
Game.UI.Widgets
Type:
public class
Base:
IWidgetBindingFactory
Summary:
A simple binding factory that provides a single trigger binding named "setExpanded". The binding accepts a boolean value and, when invoked, will set the expanded state of the target widget if it implements IExpandable. If the resolved widget is null or does not implement IExpandable, an error is logged to UnityEngine.Debug. The factory itself does not store state and only yields the one TriggerBinding; the provided ValueChangedCallback parameter is not used by this implementation.
Fields
- This class defines no instance or static fields.
ExpandableBindings is stateless and only implements the binding factory interface.
Properties
- This class exposes no public properties.
Constructors
public ExpandableBindings()
The class has the default parameterless constructor (implicit). No initialization is required.
Methods
-
public IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
Creates and returns the bindings provided by this factory. -
Parameters:
group
— The binding group name used when constructing the TriggerBinding.pathResolver
— An IReaderused by the TriggerBinding to resolve widget paths at runtime. onValueChanged
— A callback type accepted by the factory interface; this implementation does not use it.
- Behavior:
- Yields a single
TriggerBinding<IWidget, bool>
with the key"setExpanded"
. - The binding's action checks if the resolved widget implements
IExpandable
. If so, it setsexpandable.expanded = expanded
. If the widget is null, it logs "Invalid widget path". If the widget does not implementIExpandable
, it logs "Widget does not implement IExpandable".
- Yields a single
- Returns:
- A sequence containing one IBinding (the "setExpanded" trigger binding).
Notes: - The method relies on Colossal.UI.Binding.TriggerBinding and UnityEngine.Debug for error output. - Since the class yields the binding via yield return, callers can iterate the returned IEnumerable to register or attach each binding to the UI system.
Usage Example
// Example: creating and enumerating the bindings produced by this factory.
// 'pathResolver' and 'onValueChanged' would come from the UI binding system context.
var factory = new Game.UI.Widgets.ExpandableBindings();
foreach (var binding in factory.CreateBindings("myGroup", pathResolver, onValueChanged))
{
// Register the returned binding with whatever binding container/system your mod uses.
// (Registration API depends on the UI binding framework in use.)
}
// Example of what the produced TriggerBinding does (conceptual):
// When the binding "setExpanded" is triggered with `true`/`false`, the binding will:
// - Resolve the target widget via pathResolver.
// - If the widget implements IExpandable, set widget.expanded = true/false.
// - Otherwise, log an error via UnityEngine.Debug.LogError.
{{ Additional information: - Typical use case: allow data-driven control (or other systems) to expand/collapse widgets via the "setExpanded" trigger. - Error handling: logs errors instead of throwing, to avoid breaking UI flow. - Threading: intended for main-thread UI usage; UnityEngine.Debug and widget manipulation must occur on the main thread. - Dependencies: Colossal.UI.Binding (TriggerBinding, IBinding), the IExpandable interface (provides expanded property), and UnityEngine for logging. - Extensibility: If you need more bindings for expandable widgets (e.g., toggle, expand/collapse events), implement additional bindings in this factory or create a new factory. }}