Game.UI.Widgets.ContainerExtensions
Assembly: Assembly-CSharp (common for game code / mods)
Namespace: Game.UI.Widgets
Type: static class
Base: None
Summary:
Extension helpers for container-like widgets. Provides methods to locate child widgets by a PathSegment and to ensure default path values and default localized display names for children when missing. These methods are designed to operate on widget collections exposed by container widgets (typically visibleChildren) and to simplify initialization of child entries in lists/panels.
Fields
- This type declares no fields.
{{ The class is a static utilities/extensions container and does not hold instance state. }}
Properties
- This type declares no properties.
{{ Methods are provided as static extension helpers; there are no stored properties on this utility type. }}
Constructors
- This static class has no public constructors.
{{ Since this is a static class it cannot be instantiated and only contains static extension methods. }}
Methods
-
[CanBeNull] public static IWidget FindChild(this IWidget widget, PathSegment path)
{{ Finds a direct visible child of the given widget whose PathSegment equals the provided path. Equivalent to calling the generic FindChild overload on widget.visibleChildren. Returns null if the widget has no visible children, the path is PathSegment.Empty, or no matching child is found. Typical usage is to quickly locate a child by its path within a container widget. }} -
public static T FindChild<T>(IEnumerable<T> children, PathSegment path) where T : IWidget
{{ Generic iterator-based lookup: iterates the provided children collection and returns the first child whose path equals the given PathSegment. If path == PathSegment.Empty or children is null, the method returns default(T). If no matching child is found it also returns default(T). Useful when you already have the children enumerable (for example, visibleChildren) and want a typed result. }} -
public static void SetDefaults<T>(IList<T> children) where T : IWidget
{{ Ensures each child has a valid PathSegment and a default localized display name when applicable: - Iterates children by index i.
- If a child's path has a null key (path.m_Key == null), assigns a new PathSegment constructed from the index (new PathSegment(i)).
- If the child implements INamed and its displayName is empty (pattern matched via displayName.isEmpty), sets displayName to a localized value of the form "" (LocalizedString.Value($"<{i}>")). This is typically used to initialize list items so they have stable paths and readable default names when none were provided by data. }}
Usage Example
// Example: initializing a container's visible children on creation/refresh.
protected void InitializeContainer(IWidget container)
{
// Set path defaults and default names for visible children
ContainerExtensions.SetDefaults(container.visibleChildren);
// Find a specific child by path
PathSegment myPath = new PathSegment(2);
IWidget child = container.FindChild(myPath);
if (child != null)
{
// operate on the child
}
}
{{ Tips: - Use SetDefaults when dynamically constructing child collections so UI elements get stable PathSegment keys and readable names. - The FindChild extensions only search one level among the supplied children (they do not perform a recursive search). - The PathSegment.Empty check prevents accidental matches when path was not intended to be queried. }}