HotKeys.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("HotKeys", "Demonstrates how HotKeys work.")]
  4. [ScenarioCategory ("Controls")]
  5. [ScenarioCategory ("Mouse and Keyboard")]
  6. public class HotKeys : Scenario
  7. {
  8. public override void Main ()
  9. {
  10. Application.Init ();
  11. Window app = new ()
  12. {
  13. Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
  14. };
  15. var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 };
  16. app.Add (textViewLabel);
  17. var textField = new TextField { X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 };
  18. app.Add (textField);
  19. var viewLabel = new Label { Text = "_View:", X = 0, Y = Pos.Bottom (textField) + 1 };
  20. app.Add (viewLabel);
  21. var view = new View
  22. {
  23. Title = "View (_focusable)",
  24. Text = "Text renders _Underscore",
  25. CanFocus = true,
  26. X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
  27. BorderStyle = LineStyle.Dashed
  28. };
  29. app.Add (view);
  30. viewLabel = new() { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 };
  31. app.Add (viewLabel);
  32. view = new()
  33. {
  34. Title = "View (n_ot focusable)",
  35. Text = "Text renders _Underscore",
  36. X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
  37. BorderStyle = LineStyle.Dashed
  38. };
  39. app.Add (view);
  40. var labelWithFrameLabel = new Label { Text = "_Label with Frame:", X = 0, Y = Pos.Bottom (view) + 1 };
  41. app.Add (labelWithFrameLabel);
  42. var labelWithFrameFocusable = new Label
  43. {
  44. AutoSize = false,
  45. Title = "Label _with Frame (focusable)",
  46. CanFocus = true,
  47. X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
  48. BorderStyle = LineStyle.Dashed
  49. };
  50. app.Add (labelWithFrameFocusable);
  51. labelWithFrameLabel = new() { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
  52. app.Add (labelWithFrameLabel);
  53. var labelWithFrame = new Label
  54. {
  55. AutoSize = false,
  56. Title = "Label with Frame (_not focusable)",
  57. X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
  58. BorderStyle = LineStyle.Dashed
  59. };
  60. app.Add (labelWithFrame);
  61. var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 };
  62. app.Add (buttonWithFrameLabel);
  63. var buttonWithFrameFocusable = new Button
  64. {
  65. AutoSize = false,
  66. Title = "B_utton with Frame (focusable)",
  67. CanFocus = true,
  68. X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
  69. BorderStyle = LineStyle.Dashed
  70. };
  71. app.Add (buttonWithFrameFocusable);
  72. buttonWithFrameLabel = new() { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
  73. app.Add (buttonWithFrameLabel);
  74. var buttonWithFrame = new Button
  75. {
  76. AutoSize = false,
  77. Title = "Button with Frame (not focusab_le)",
  78. X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
  79. CanFocus = false,
  80. BorderStyle = LineStyle.Dashed
  81. };
  82. app.Add (buttonWithFrame);
  83. var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 };
  84. app.Add (checkboxWithFrameLabel);
  85. var checkboxWithFrameFocusable = new CheckBox
  86. {
  87. AutoSize = false,
  88. Title = "C_heckbox with Frame (focusable)",
  89. CanFocus = true,
  90. X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
  91. BorderStyle = LineStyle.Dashed
  92. };
  93. app.Add (checkboxWithFrameFocusable);
  94. checkboxWithFrameLabel = new() { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
  95. app.Add (checkboxWithFrameLabel);
  96. var checkboxWithFrame = new CheckBox
  97. {
  98. AutoSize = false,
  99. Title = "Checkbox with Frame (not focusable)",
  100. X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
  101. CanFocus = false,
  102. BorderStyle = LineStyle.Dashed
  103. };
  104. app.Add (checkboxWithFrame);
  105. var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), Text = "_Press me!" };
  106. app.Add (button);
  107. Application.Run (app);
  108. app.Dispose ();
  109. }
  110. }