Buttons.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Terminal.Gui;
  2. namespace UICatalog {
  3. [ScenarioMetadata (Name: "Buttons", Description: "Demonstrates all sorts of Buttons")]
  4. [ScenarioCategory ("Controls")]
  5. [ScenarioCategory ("Layout")]
  6. class Buttons : Scenario {
  7. public override void Setup ()
  8. {
  9. // Add a label & text field so we can demo IsDefault
  10. var editLabel = new Label ("TextField (to demo IsDefault):") {
  11. X = 0,
  12. Y = 0,
  13. };
  14. Win.Add (editLabel);
  15. var edit = new TextField ("") {
  16. X = Pos.Right (editLabel) + 1,
  17. Y = Pos.Top (editLabel),
  18. Width = Dim.Fill (2),
  19. };
  20. Win.Add (edit);
  21. // This is the default button (IsDefault = true); if user presses ENTER in the TextField
  22. // the scenario will quit
  23. var defaultButton = new Button ("Quit") {
  24. X = Pos.Center (),
  25. //TODO: Change to use Pos.AnchorEnd()
  26. Y= Pos.Bottom(Win) - 3,
  27. IsDefault = true,
  28. Clicked = () => Application.RequestStop (),
  29. };
  30. Win.Add (defaultButton);
  31. var y = 2;
  32. var button = new Button (10, y, "Base Color") {
  33. ColorScheme = Colors.Base,
  34. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  35. };
  36. Win.Add (button);
  37. y += 2;
  38. Win.Add (new Button (10, y, "Error Color") {
  39. ColorScheme = Colors.Error,
  40. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  41. });
  42. y += 2;
  43. Win.Add (new Button (10, y, "Dialog Color") {
  44. ColorScheme = Colors.Dialog,
  45. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  46. });
  47. y += 2;
  48. Win.Add (new Button (10, y, "Menu Color") {
  49. ColorScheme = Colors.Menu,
  50. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  51. });
  52. y += 2;
  53. Win.Add (new Button (10, y, "TopLevel Color") {
  54. ColorScheme = Colors.TopLevel,
  55. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  56. });
  57. y += 2;
  58. Win.Add (new Button (10, y, "A super long button that will probably expose a bug in clipping or wrapping of text. Will it?") {
  59. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  60. });
  61. y += 2;
  62. // Note the 'N' in 'Newline' will be the hotkey
  63. Win.Add (new Button (10, y, "a Newline\nin the button") {
  64. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  65. });
  66. y += 2;
  67. // BUGBUG: Buttons don't support specifying hotkeys with _?!?
  68. Win.Add (button = new Button ("Te_xt Changer") {
  69. X = 10,
  70. Y = y
  71. });
  72. button.Clicked = () => button.Text += $"{y++}";
  73. Win.Add (new Button ("Lets see if this will move as \"Text Changer\" grows") {
  74. X = Pos.Right(button) + 10,
  75. Y = y,
  76. });
  77. y += 2;
  78. Win.Add (new Button (10, y, "Delete") {
  79. ColorScheme = Colors.Error,
  80. Clicked = () => Win.Remove (button)
  81. });
  82. y += 2;
  83. Win.Add (new Button (10, y, "Change Default") {
  84. Clicked = () => {
  85. defaultButton.IsDefault = !defaultButton.IsDefault;
  86. button.IsDefault = !button.IsDefault;
  87. },
  88. });
  89. }
  90. }
  91. }