diff --git a/.vs/MLEM/FileContentIndex/2186cc36-8647-4fe1-8bf6-39eff9be3f51.vsidx b/.vs/MLEM/FileContentIndex/2186cc36-8647-4fe1-8bf6-39eff9be3f51.vsidx new file mode 100644 index 0000000..a170885 Binary files /dev/null and b/.vs/MLEM/FileContentIndex/2186cc36-8647-4fe1-8bf6-39eff9be3f51.vsidx differ diff --git a/.vs/MLEM/FileContentIndex/5c4473ad-46e5-45a6-9b64-48418cb0d292.vsidx b/.vs/MLEM/FileContentIndex/5c4473ad-46e5-45a6-9b64-48418cb0d292.vsidx new file mode 100644 index 0000000..c31d15d Binary files /dev/null and b/.vs/MLEM/FileContentIndex/5c4473ad-46e5-45a6-9b64-48418cb0d292.vsidx differ diff --git a/.vs/MLEM/FileContentIndex/605585c7-a7ce-4bee-927d-4fdb07cfd34d.vsidx b/.vs/MLEM/FileContentIndex/605585c7-a7ce-4bee-927d-4fdb07cfd34d.vsidx new file mode 100644 index 0000000..d76fba0 Binary files /dev/null and b/.vs/MLEM/FileContentIndex/605585c7-a7ce-4bee-927d-4fdb07cfd34d.vsidx differ diff --git a/.vs/MLEM/FileContentIndex/f70a5f03-4fad-4b6f-bd44-128b17493fd1.vsidx b/.vs/MLEM/FileContentIndex/f70a5f03-4fad-4b6f-bd44-128b17493fd1.vsidx new file mode 100644 index 0000000..49ba1ec Binary files /dev/null and b/.vs/MLEM/FileContentIndex/f70a5f03-4fad-4b6f-bd44-128b17493fd1.vsidx differ diff --git a/.vs/MLEM/v17/.suo b/.vs/MLEM/v17/.suo new file mode 100644 index 0000000..83586e4 Binary files /dev/null and b/.vs/MLEM/v17/.suo differ diff --git a/.vs/MLEM/v17/.wsuo b/.vs/MLEM/v17/.wsuo new file mode 100644 index 0000000..89946c7 Binary files /dev/null and b/.vs/MLEM/v17/.wsuo differ diff --git a/MLEM.Ui/Elements/RadioGroupButton.cs b/MLEM.Ui/Elements/RadioGroupButton.cs new file mode 100644 index 0000000..0a419e6 --- /dev/null +++ b/MLEM.Ui/Elements/RadioGroupButton.cs @@ -0,0 +1,66 @@ +using Microsoft.Xna.Framework; +using MLEM.Ui.Style; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MLEM.Ui.Elements { + /// + /// A radio button element to use inside of a . + /// A radio button is a variation of a that causes all other radio buttons in the same to be deselected upon selection. + /// + public class RadioGroupButton:Checkbox { + + /// + /// The group that this radio button has. + /// All other radio buttons in the same that have the same group will be deselected when this radio button is selected. + /// + public RadioGroup Group; + + /// + /// Creates a new radio button with the given settings + /// + /// The radio button's anchor + /// The radio button's size + /// The label to display next to the radio button + /// If the radio button should be checked by default + /// The group that the radio button has + public RadioGroupButton(Anchor anchor, Vector2 size, string label, bool defaultChecked = false, RadioGroup? group = null) : + 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; + this.Root.Element.AndChildren(e => { + group.Selection = this; + }); + }; + } + + /// + protected override void InitStyle(UiStyle style) { + base.InitStyle(style); + this.Texture = this.Texture.OrStyle(style.RadioTexture); + this.HoveredTexture = this.HoveredTexture.OrStyle(style.RadioHoveredTexture); + this.HoveredColor = this.HoveredColor.OrStyle(style.RadioHoveredColor); + this.Checkmark = this.Checkmark.OrStyle(style.RadioCheckmark); + } + } + /// + /// A group of radio group buttons + /// + public class RadioGroup { + private RadioGroupButton? selection; + public RadioGroupButton? Selection{ get => selection; set { + if (selection != null) this.selection.Checked = false; + selection = value; + if(selection != null) { + this.selection.Group = this; + this.selection.Checked = true; + } + }} + } +}