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

Close other dropdowns when opening a dropdown

This commit is contained in:
Ell 2022-07-29 22:24:37 +02:00
parent 8044cb59cb
commit 5aaba0c583
2 changed files with 11 additions and 1 deletions

View file

@ -20,6 +20,7 @@ Additions
Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly
- Close other dropdowns when opening a dropdown
## 6.0.0
### MLEM

View file

@ -42,7 +42,16 @@ namespace MLEM.Ui.Elements {
});
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
this.OnPressed += e => this.IsOpen = !this.IsOpen;
this.OnPressed += e => {
this.IsOpen = !this.IsOpen;
// close other dropdowns in the same root when we open
if (this.IsOpen) {
this.Root.Element.AndChildren(o => {
if (o != this && o is Dropdown d && d.IsOpen)
d.IsOpen = false;
});
}
};
this.GetGamepadNextElement = (dir, usualNext) => {
// Force navigate down to our first child if we're open
if (this.IsOpen && dir == Direction2.Down)