Menuv2.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Reflection;
  3. namespace Terminal.Gui;
  4. /// <summary>
  5. /// </summary>
  6. public class Menuv2 : Bar
  7. {
  8. /// <inheritdoc/>
  9. public Menuv2 () : this ([]) { }
  10. /// <inheritdoc/>
  11. public Menuv2 (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
  12. {
  13. Orientation = Orientation.Vertical;
  14. Width = Dim.Auto ();
  15. Height = Dim.Auto (DimAutoStyle.Content, 1);
  16. ColorScheme = Colors.ColorSchemes ["Menu"];
  17. Initialized += Menuv2_Initialized;
  18. }
  19. private void Menuv2_Initialized (object sender, EventArgs e)
  20. {
  21. Border.Thickness = new Thickness (1, 1, 1, 1);
  22. }
  23. // Menuv2 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. internal override void OnLayoutStarted (LayoutEventArgs args)
  27. {
  28. for (int index = 0; index < Subviews.Count; index++)
  29. {
  30. View barItem = Subviews [index];
  31. if (!barItem.Visible)
  32. {
  33. continue;
  34. }
  35. }
  36. base.OnLayoutStarted (args);
  37. }
  38. /// <inheritdoc/>
  39. public override View Add (View view)
  40. {
  41. base.Add (view);
  42. if (view is Shortcut shortcut)
  43. {
  44. shortcut.CanFocus = true;
  45. shortcut.KeyBindingScope = KeyBindingScope.Application;
  46. shortcut.Orientation = Orientation.Vertical;
  47. // TODO: not happy about using AlignmentModes for this. Too implied.
  48. // TODO: instead, add a property (a style enum?) to Shortcut to control this
  49. //shortcut.AlignmentModes = AlignmentModes.EndToStart;
  50. }
  51. return view;
  52. }
  53. }