Skip to content

Commit

Permalink
Open ConsoleUI hamburger menu on menu key press
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 21, 2021
1 parent ef4ee26 commit 8a10141
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions ConsoleUI/Toolkit/ConsolePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public bool Run(ConsoleTheme theme, int right, int top)
break;
case ConsoleKey.F10:
case ConsoleKey.Escape:
case ConsoleKey.Applications:
done = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/Toolkit/ConsoleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected ConsoleScreen()
"F10", MenuTip(),
() => mainMenu != null
);
AddBinding(Keys.F10, (object sender, ConsoleTheme theme) => {
AddBinding(new ConsoleKeyInfo[] {Keys.F10, Keys.Apps}, (object sender, ConsoleTheme theme) => {
bool val = true;
if (mainMenu != null) {
DrawSelectedHamburger(theme);
Expand Down
7 changes: 7 additions & 0 deletions ConsoleUI/Toolkit/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public static class Keys {
(System.Char)0, ConsoleKey.F10, false, false, false
);

/// <summary>
/// Representation of Apps for key bindings
/// </summary>
public static readonly ConsoleKeyInfo Apps = new ConsoleKeyInfo(
(System.Char)0, ConsoleKey.Applications, false, false, false
);

/// <summary>
/// Representation of down arrow for key bindings
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion ConsoleUI/Toolkit/ScreenContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public void AddBinding(ConsoleKeyInfo k, KeyAction a)
}
}

/// <summary>
/// Add custom key bindings
/// </summary>
/// <param name="keys">Keys to bind</param>
/// <param name="a">Action to bind to key</param>
public void AddBinding(IEnumerable<ConsoleKeyInfo> keys, KeyAction a)
{
foreach (ConsoleKeyInfo k in keys) {
AddBinding(k, a);
}
}

/// <summary>
/// Add a screen tip to show in the FooterBg
/// </summary>
Expand Down Expand Up @@ -247,7 +259,7 @@ private void Blur(ScreenObject source, bool forward)
} while (!objects[focusIndex].Focusable());
}
}

private bool done = false;

private List<ScreenObject> objects = new List<ScreenObject>();
Expand Down

0 comments on commit 8a10141

Please sign in to comment.