diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 91141e5..803a622 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -253,7 +253,7 @@ namespace MLEM.Ui.Elements { /// /// An optional string that represents a group of elements for automatic (keyboard and gamepad) navigation. /// All elements that share the same auto-nav group will be able to be navigated between, and all other elements will not be reachable from elements of other groups. - /// Note that, if no element is previously selected and auto-navigation is invoked, this element can always be navigated to if it is the first one chosen by auto-navigation. + /// Note that, if no element is previously selected and auto-navigation is invoked, this element cannot be chosen as the first element to navigate to if its auto-nav group is non-null. /// public virtual string AutoNavGroup { get; set; } diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index c099c3a..ad05fae 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -373,7 +373,9 @@ namespace MLEM.Ui { // we can't add these checks to GetChildren because it ignores false grandchildren .Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup); if (this.SelectedElement?.Root != this.ActiveRoot) { - return backward ? children.LastOrDefault() : children.FirstOrDefault(); + // if we don't have an element selected in this root, navigate to the first one without a group + var allowed = children.Where(c => c.AutoNavGroup == null); + return backward ? allowed.LastOrDefault() : allowed.FirstOrDefault(); } else { var foundCurr = false; Element lastFound = null; @@ -406,7 +408,8 @@ namespace MLEM.Ui { // we can't add these checks to GetChildren because it ignores false grandchildren .Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup); if (this.SelectedElement?.Root != this.ActiveRoot) { - return children.FirstOrDefault(); + // if we don't have an element selected in this root, navigate to the first one without a group + return children.FirstOrDefault(c => c.AutoNavGroup == null); } else { Element closest = null; float closestPriority = 0;