diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8c7a98..fb389ef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@ Fixes
- Fixed UiControls allowing for non-selectable or non-mouseable elements to be marked as selected or moused
- Fixed buttons and checkboxes changing their CanBeSelected and CanBePressed values when being disabled
- Fixed children of Panel scroll bars also being scrolled
+- Fixed RootElement.CanSelectContent returning incorrect results when CanBeSelected changes in children
Removals
- Marked StyleProp equality members as obsolete
diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs
index 697e7ac..69cd112 100644
--- a/MLEM.Ui/UiControls.cs
+++ b/MLEM.Ui/UiControls.cs
@@ -156,7 +156,7 @@ namespace MLEM.Ui {
public virtual void Update() {
if (this.IsInputOurs)
this.Input.Update();
- this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
+ this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => !root.Element.IsHidden && root.CanSelectContent);
// MOUSE INPUT
if (this.HandleMouse) {
@@ -274,7 +274,7 @@ namespace MLEM.Ui {
/// The element to select, or null to deselect the selected element.
/// Whether automatic navigation should be forced on
public void SelectElement(RootElement root, Element element, bool? autoNav = null) {
- if (root == null || !root.CanSelectContent)
+ if (root == null)
return;
if (element != null && !element.CanBeSelected)
return;
@@ -337,7 +337,7 @@ namespace MLEM.Ui {
/// The root element whose selected element to return
/// The given root's selected element, or null if the root doesn't exist, or if there is no selected element for that root.
public Element GetSelectedElement(RootElement root) {
- if (root == null || !root.CanSelectContent)
+ if (root == null)
return null;
this.selectedElements.TryGetValue(root.Name, out var element);
if (element != null && !element.CanBeSelected)
diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs
index 302f2da..d494dac 100644
--- a/MLEM.Ui/UiSystem.cs
+++ b/MLEM.Ui/UiSystem.cs
@@ -535,7 +535,7 @@ namespace MLEM.Ui {
/// Determines whether this root element contains any children that .
/// This value is automatically calculated.
///
- public bool CanSelectContent { get; private set; }
+ public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any();
///
/// Event that is invoked when a is added to this root element or any of its children.
@@ -558,21 +558,6 @@ namespace MLEM.Ui {
this.Name = name;
this.Element = element;
this.System = system;
-
- this.OnElementAdded += e => {
- if (e.CanBeSelected)
- this.CanSelectContent = true;
- };
- this.OnElementRemoved += e => {
- if (e.CanBeSelected) {
- // check if removing this element removed all other selectable elements
- foreach (var c in this.Element.GetChildren(regardGrandchildren: true)) {
- if (c.CanBeSelected)
- return;
- }
- this.CanSelectContent = false;
- }
- };
}
///