1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 01:09:23 +01:00

Added Element.AutoNavGroup which allows forming groups for auto-navigation

This commit is contained in:
Ell 2022-04-14 17:54:25 +02:00
parent ad29b46df3
commit 45afd9ac79
3 changed files with 13 additions and 4 deletions

View file

@ -14,6 +14,9 @@ Additions
- Added consuming variants of IsPressed methods to InputHandler
### MLEM.Ui
Additions
- Added Element.AutoNavGroup which allows forming groups for auto-navigation
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

View file

@ -249,6 +249,12 @@ namespace MLEM.Ui.Elements {
/// Returns whether this element's <see cref="SetAreaDirty"/> method has been recently called and its area has not been updated since then using <see cref="UpdateAreaIfDirty"/> or <see cref="ForceUpdateArea"/>.
/// </summary>
public bool AreaDirty { get; private set; }
/// <summary>
/// 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.
/// </summary>
public virtual string AutoNavGroup { get; set; }
/// <summary>
/// This Element's current <see cref="UiStyle"/>.

View file

@ -353,15 +353,15 @@ namespace MLEM.Ui {
protected virtual Element GetTabNextElement(bool backward) {
if (this.ActiveRoot == null)
return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element);
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
// 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(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected);
return backward ? children.LastOrDefault() : children.FirstOrDefault();
} else {
var foundCurr = false;
Element lastFound = null;
foreach (var child in children) {
if (!child.CanBeSelected)
continue;
if (child == this.SelectedElement) {
// when going backwards, return the last element found before the current one
if (backward)