Add ButtonHelpers and the SetButtonDisabledRecursive helper.

Fixes the mess from the other day.
This commit is contained in:
Vera Aguilera Puerto
2021-07-29 12:55:22 +02:00
parent 3501bcbea6
commit 8ed1a9e19c
4 changed files with 37 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.UserInterface
{
public static class ButtonHelpers
{
/// <summary>
/// This searches recursively through all the children of "parent"
/// and sets the Disabled value of any buttons found to "val"
/// </summary>
/// <param name="parent">The control which childrens get searched</param>
/// <param name="val">The value to which disabled gets set</param>
public static void SetButtonDisabledRecursive(Control parent, bool val)
{
foreach (var child in parent.Children)
{
if (child is Button but)
{
but.Disabled = val;
continue;
}
if (child.ChildCount > 0)
{
SetButtonDisabledRecursive(child, val);
}
}
}
}
}