Buttons.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // BUGBUG: Throws an exception
  26. //Y= Pos.Bottom(Win),
  27. Y = 20,
  28. IsDefault = true,
  29. Clicked = () => Application.RequestStop (),
  30. };
  31. Win.Add (defaultButton);
  32. var y = 2;
  33. var button = new Button (10, y, "Base Color") {
  34. ColorScheme = Colors.Base,
  35. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  36. };
  37. Win.Add (button);
  38. y += 2;
  39. Win.Add (new Button (10, y, "Error Color") {
  40. ColorScheme = Colors.Error,
  41. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  42. });
  43. y += 2;
  44. Win.Add (new Button (10, y, "Dialog Color") {
  45. ColorScheme = Colors.Dialog,
  46. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  47. });
  48. y += 2;
  49. Win.Add (new Button (10, y, "Menu Color") {
  50. ColorScheme = Colors.Menu,
  51. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  52. });
  53. y += 2;
  54. Win.Add (new Button (10, y, "TopLevel Color") {
  55. ColorScheme = Colors.TopLevel,
  56. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  57. });
  58. y += 2;
  59. Win.Add (new Button (10, y, "A super long button that will probably expose a bug in clipping or wrapping of text. Will it?") {
  60. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  61. });
  62. y += 2;
  63. // Note the 'N' in 'Newline' will be the hotkey
  64. Win.Add (new Button (10, y, "a Newline\nin the button") {
  65. Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
  66. });
  67. y += 2;
  68. // BUGBUG: Buttons don't support specifying hotkeys with _?!?
  69. Win.Add (button = new Button (10, y, "Te_xt Changer") {
  70. });
  71. button.Clicked = () => button.Text += $"{y++}";
  72. Win.Add (new Button ("Lets see if this will move as \"Text Changer\" grows") {
  73. X = Pos.Right(button) + 10,
  74. Y = y,
  75. });
  76. y += 2;
  77. Win.Add (new Button (10, y, "Delete") {
  78. ColorScheme = Colors.Error,
  79. Clicked = () => Win.Remove (button)
  80. });
  81. y += 2;
  82. Win.Add (new Button (10, y, "Change Default") {
  83. Clicked = () => {
  84. defaultButton.IsDefault = !defaultButton.IsDefault;
  85. button.IsDefault = !button.IsDefault;
  86. },
  87. });
  88. }
  89. }
  90. }