mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Improve dropdown opening gamepad navigation (in relation to cb8fed87e5
)
This commit is contained in:
parent
a14a37cb91
commit
7c18aad8f7
1 changed files with 8 additions and 7 deletions
|
@ -22,13 +22,6 @@ namespace MLEM.Ui.Elements {
|
||||||
set {
|
set {
|
||||||
this.Panel.IsHidden = !value;
|
this.Panel.IsHidden = !value;
|
||||||
this.OnOpenedOrClosed?.Invoke(this);
|
this.OnOpenedOrClosed?.Invoke(this);
|
||||||
|
|
||||||
// select the first dropdown element in auto nav mode
|
|
||||||
if (value && this.Controls.IsAutoNavMode) {
|
|
||||||
var firstChild = this.Panel.GetChildren().FirstOrDefault(c => c.CanBeSelected);
|
|
||||||
if (firstChild != null)
|
|
||||||
this.Root.SelectElement(firstChild, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -50,6 +43,12 @@ namespace MLEM.Ui.Elements {
|
||||||
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
|
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
|
||||||
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
|
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
|
||||||
this.OnPressed += e => this.IsOpen = !this.IsOpen;
|
this.OnPressed += e => this.IsOpen = !this.IsOpen;
|
||||||
|
this.GetGamepadNextElement = (dir, usualNext) => {
|
||||||
|
// Force navigate down to our first child if we're open
|
||||||
|
if (this.IsOpen && dir == Direction2.Down)
|
||||||
|
return this.Panel.GetChildren().FirstOrDefault(c => c.CanBeSelected) ?? usualNext;
|
||||||
|
return usualNext;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -61,6 +60,8 @@ namespace MLEM.Ui.Elements {
|
||||||
// Since the dropdown causes elements to be over each other,
|
// Since the dropdown causes elements to be over each other,
|
||||||
// usual gamepad code doesn't apply
|
// usual gamepad code doesn't apply
|
||||||
element.GetGamepadNextElement = (dir, usualNext) => {
|
element.GetGamepadNextElement = (dir, usualNext) => {
|
||||||
|
if (dir == Direction2.Left || dir == Direction2.Right)
|
||||||
|
return null;
|
||||||
if (dir == Direction2.Up) {
|
if (dir == Direction2.Up) {
|
||||||
var prev = element.GetOlderSibling();
|
var prev = element.GetOlderSibling();
|
||||||
return prev ?? this;
|
return prev ?? this;
|
||||||
|
|
Loading…
Reference in a new issue