using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; namespace Content.Client.UserInterface.Controls; /// /// A simple control that displays a toggleable on/off button. /// [GenerateTypedNameReferences] public sealed partial class OnOffButton : Control { /// /// Whether the control is currently in the "on" state. /// public bool IsOn { get => OnButton.Pressed; set { if (value) OnButton.Pressed = true; else OffButton.Pressed = true; } } /// /// Raised when the user changes the state of the control. /// /// /// This does not get raised if state is changed with . /// public event Action? StateChanged; public OnOffButton() { RobustXamlLoader.Load(this); var group = new ButtonGroup(isNoneSetAllowed: false); OffButton.Group = group; OnButton.Group = group; OffButton.OnPressed += _ => StateChanged?.Invoke(false); OnButton.OnPressed += _ => StateChanged?.Invoke(true); } }