1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-29 15:58:33 +01:00
MLEM/MLEM.Ui/Elements/RadioButton.cs
2019-10-14 21:28:12 +02:00

33 lines
No EOL
1.1 KiB
C#

using Microsoft.Xna.Framework;
using MLEM.Input;
using MLEM.Ui.Style;
namespace MLEM.Ui.Elements {
public class RadioButton : Checkbox {
public string Group;
public RadioButton(Anchor anchor, Vector2 size, string label, bool defaultChecked = false, string group = "") :
base(anchor, size, label, defaultChecked) {
this.Group = group;
// don't += because we want to override the checking + unchecking behavior of Checkbox
this.OnPressed = element => {
this.Checked = true;
foreach (var sib in this.GetSiblings()) {
if (sib is RadioButton radio && radio.Group == this.Group)
radio.Checked = false;
}
};
}
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Texture.SetFromStyle(style.RadioTexture);
this.HoveredTexture.SetFromStyle(style.RadioHoveredTexture);
this.HoveredColor.SetFromStyle(style.RadioHoveredColor);
this.Checkmark.SetFromStyle(style.RadioCheckmark);
}
}
}