using Content.Client.Guidebook.Controls; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; namespace Content.Client.UserInterface.ControlExtensions; public static class ControlExtension { public static List GetControlOfType(this Control parent) where T : Control { return parent.GetControlOfType(typeof(T).Name, false); } public static List GetControlOfType(this Control parent, string childType) where T : Control { return parent.GetControlOfType(childType, false); } public static List GetControlOfType(this Control parent, bool fullTreeSearch) where T : Control { return parent.GetControlOfType(typeof(T).Name, fullTreeSearch); } public static List GetControlOfType(this Control parent, string childType, bool fullTreeSearch) where T : Control { List controlList = new List(); foreach (var child in parent.Children) { var isType = child.GetType().Name == childType; var hasChildren = child.ChildCount > 0; var searchDeeper = hasChildren && !isType; if (isType) { controlList.Add((T) child); } if (fullTreeSearch || searchDeeper) { controlList.AddRange(child.GetControlOfType(childType, fullTreeSearch)); } } return controlList; } public static List GetSearchableControls(this Control parent, bool fullTreeSearch = false) { List controlList = new List(); foreach (var child in parent.Children) { var hasChildren = child.ChildCount > 0; var searchDeeper = hasChildren && child is not ISearchableControl; if (child is ISearchableControl searchableChild) { controlList.Add(searchableChild); } if (fullTreeSearch || searchDeeper) { controlList.AddRange(child.GetSearchableControls(fullTreeSearch)); } } return controlList; } public static bool ChildrenContainText(this Control parent, string search) { var labels = parent.GetControlOfType