HotKeys.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 = GetQuitKeyAndName ()
  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. Title = "Label _with Frame (focusable)",
  45. CanFocus = true,
  46. X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
  47. BorderStyle = LineStyle.Dashed
  48. };
  49. app.Add (labelWithFrameFocusable);
  50. labelWithFrameLabel = new () { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
  51. app.Add (labelWithFrameLabel);
  52. var labelWithFrame = new Label
  53. {
  54. Title = "Label with Frame (_not focusable)",
  55. X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
  56. BorderStyle = LineStyle.Dashed
  57. };
  58. app.Add (labelWithFrame);
  59. var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 };
  60. app.Add (buttonWithFrameLabel);
  61. var buttonWithFrameFocusable = new Button
  62. {
  63. Title = "B_utton with Frame (focusable)",
  64. CanFocus = true,
  65. X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40,
  66. BorderStyle = LineStyle.Dashed
  67. };
  68. app.Add (buttonWithFrameFocusable);
  69. buttonWithFrameLabel = new () { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
  70. app.Add (buttonWithFrameLabel);
  71. var buttonWithFrame = new Button
  72. {
  73. Title = "Button with Frame (not focusab_le)",
  74. X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40,
  75. CanFocus = false,
  76. BorderStyle = LineStyle.Dashed
  77. };
  78. app.Add (buttonWithFrame);
  79. var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 };
  80. app.Add (checkboxWithFrameLabel);
  81. var checkboxWithFrameFocusable = new CheckBox
  82. {
  83. Title = "C_heckbox with Frame (focusable)",
  84. CanFocus = true,
  85. X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
  86. BorderStyle = LineStyle.Dashed
  87. };
  88. app.Add (checkboxWithFrameFocusable);
  89. checkboxWithFrameLabel = new () { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
  90. app.Add (checkboxWithFrameLabel);
  91. var checkboxWithFrame = new CheckBox
  92. {
  93. Title = "Checkbox with Frame (not focusable)",
  94. X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
  95. CanFocus = false,
  96. BorderStyle = LineStyle.Dashed
  97. };
  98. app.Add (checkboxWithFrame);
  99. var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), Text = "_Press me!" };
  100. app.Add (button);
  101. Application.Run (app);
  102. app.Dispose ();
  103. Application.Shutdown ();
  104. }
  105. }