MenuBarv2.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Reflection;
  3. namespace Terminal.Gui;
  4. /// <summary>
  5. /// A menu bar is a <see cref="View"/> that snaps to the top of a <see cref="Toplevel"/> displaying set of
  6. /// <see cref="Shortcut"/>s.
  7. /// </summary>
  8. public class MenuBarv2 : Bar
  9. {
  10. /// <inheritdoc/>
  11. public MenuBarv2 () : this ([]) { }
  12. /// <inheritdoc/>
  13. public MenuBarv2 (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
  14. {
  15. Y = 0;
  16. Width = Dim.Fill ();
  17. Height = Dim.Auto (DimAutoStyle.Content, 1);
  18. BorderStyle = LineStyle.Dashed;
  19. ColorScheme = Colors.ColorSchemes ["Menu"];
  20. Orientation = Orientation.Horizontal;
  21. SubviewLayout += MenuBarv2_LayoutStarted;
  22. }
  23. // MenuBarv2 arranges the items horizontally.
  24. // The first item has no left border, the last item has no right border.
  25. // The Shortcuts are configured with the command, help, and key views aligned in reverse order (EndToStart).
  26. private void MenuBarv2_LayoutStarted (object sender, LayoutEventArgs e)
  27. {
  28. }
  29. /// <inheritdoc/>
  30. public override View Add (View view)
  31. {
  32. // Call base first, because otherwise it resets CanFocus to true
  33. base.Add (view);
  34. view.CanFocus = true;
  35. if (view is Shortcut shortcut)
  36. {
  37. // TODO: not happy about using AlignmentModes for this. Too implied.
  38. // TODO: instead, add a property (a style enum?) to Shortcut to control this
  39. //shortcut.AlignmentModes = AlignmentModes.EndToStart;
  40. shortcut.KeyView.Visible = false;
  41. shortcut.HelpView.Visible = false;
  42. }
  43. return view;
  44. }
  45. }