mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Fixed radio buttons not unchecking all other radio buttons with the same root element
This commit is contained in:
parent
f445f59078
commit
ad29b46df3
2 changed files with 7 additions and 6 deletions
|
@ -16,6 +16,7 @@ Additions
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
- 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
|
## 5.3.0
|
||||||
### MLEM
|
### MLEM
|
||||||
|
|
|
@ -4,7 +4,7 @@ using MLEM.Ui.Style;
|
||||||
namespace MLEM.Ui.Elements {
|
namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A radio button element to use inside of a <see cref="UiSystem"/>.
|
/// 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>
|
/// </summary>
|
||||||
public class RadioButton : Checkbox {
|
public class RadioButton : Checkbox {
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ namespace MLEM.Ui.Elements {
|
||||||
base(anchor, size, label, defaultChecked) {
|
base(anchor, size, label, defaultChecked) {
|
||||||
this.Group = group;
|
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.OnPressed = element => {
|
||||||
this.Checked = true;
|
this.Checked = true;
|
||||||
foreach (var sib in this.GetSiblings()) {
|
this.Root.Element.AndChildren(e => {
|
||||||
if (sib is RadioButton radio && radio.Group == this.Group)
|
if (e != this && e is RadioButton r && r.Group == this.Group)
|
||||||
radio.Checked = false;
|
r.Checked = false;
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue