1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Fixed radio buttons not unchecking all other radio buttons with the same root element

This commit is contained in:
Ell 2022-04-14 17:45:01 +02:00
parent f445f59078
commit ad29b46df3
2 changed files with 7 additions and 6 deletions

View file

@ -16,6 +16,7 @@ Additions
### MLEM.Ui
Fixes
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
- Fixed radio buttons not unchecking all other radio buttons with the same root element
## 5.3.0
### MLEM

View file

@ -4,7 +4,7 @@ using MLEM.Ui.Style;
namespace MLEM.Ui.Elements {
/// <summary>
/// A radio button element to use inside of a <see cref="UiSystem"/>.
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="Group"/> to be deselected upon selection.
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="RootElement"/> to be deselected upon selection.
/// </summary>
public class RadioButton : Checkbox {
@ -26,13 +26,13 @@ namespace MLEM.Ui.Elements {
base(anchor, size, label, defaultChecked) {
this.Group = group;
// don't += because we want to override the checking + unchecking behavior of Checkbox
// 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;
}
this.Root.Element.AndChildren(e => {
if (e != this && e is RadioButton r && r.Group == this.Group)
r.Checked = false;
});
};
}