Adornments.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("Adornments Demo", "Demonstrates Margin, Border, and Padding on Views.")]
  4. [ScenarioCategory ("Layout")]
  5. [ScenarioCategory ("Adornments")]
  6. public class Adornments : Scenario
  7. {
  8. public override void Main ()
  9. {
  10. Application.Init ();
  11. Window app = new ()
  12. {
  13. Title = GetQuitKeyAndName ()
  14. };
  15. var editor = new AdornmentsEditor
  16. {
  17. AutoSelectViewToEdit = true,
  18. // This is for giggles, to show that the editor can be moved around.
  19. Arrangement = ViewArrangement.Movable,
  20. X = Pos.AnchorEnd ()
  21. };
  22. editor.Border.Thickness = new (1, 2, 1, 1);
  23. app.Add (editor);
  24. var window = new Window
  25. {
  26. Title = "The _Window",
  27. Arrangement = ViewArrangement.Movable,
  28. // X = Pos.Center (),
  29. Width = Dim.Percent (60),
  30. Height = Dim.Percent (80)
  31. };
  32. app.Add (window);
  33. var tf1 = new TextField { Width = 10, Text = "TextField" };
  34. var color = new ColorPicker16 { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd () };
  35. color.BorderStyle = LineStyle.RoundedDotted;
  36. color.ColorChanged += (s, e) =>
  37. {
  38. color.SuperView.ColorScheme = new (color.SuperView.ColorScheme)
  39. {
  40. Normal = new (
  41. color.SuperView.ColorScheme.Normal.Foreground,
  42. e.CurrentValue
  43. )
  44. };
  45. };
  46. var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
  47. button.Accept += (s, e) =>
  48. MessageBox.Query (20, 7, "Hi", $"Am I a {window.GetType ().Name}?", "Yes", "No");
  49. var label = new TextView
  50. {
  51. X = Pos.Center (),
  52. Y = Pos.Bottom (button),
  53. Title = "Title",
  54. Text = "I have a 3 row top border.\nMy border inherits from the SuperView.",
  55. Width = 40,
  56. Height = 6 // TODO: Use Dim.Auto
  57. };
  58. label.Border.Thickness = new (1, 3, 1, 1);
  59. var btnButtonInWindow = new Button { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Button" };
  60. var labelAnchorEnd = new Label
  61. {
  62. Y = Pos.AnchorEnd (),
  63. Width = 40,
  64. Height = Dim.Percent (20),
  65. Text = "Label\nY=AnchorEnd(),Height=Dim.Percent(10)",
  66. ColorScheme = Colors.ColorSchemes ["Error"]
  67. };
  68. window.Margin.Data = "Margin";
  69. window.Margin.Thickness = new (3);
  70. window.Border.Data = "Border";
  71. window.Border.Thickness = new (3);
  72. window.Padding.Data = "Padding";
  73. window.Padding.Thickness = new (3);
  74. var longLabel = new Label
  75. {
  76. X = 40, Y = 5, Title = "This is long text (in a label) that should clip."
  77. };
  78. longLabel.TextFormatter.WordWrap = true;
  79. window.Add (tf1, color, button, label, btnButtonInWindow, labelAnchorEnd, longLabel);
  80. editor.Initialized += (s, e) => { editor.ViewToEdit = window; };
  81. window.Initialized += (s, e) =>
  82. {
  83. var labelInPadding = new Label { X = 1, Y = 0, Title = "_Text:" };
  84. window.Padding.Add (labelInPadding);
  85. var textFieldInPadding = new TextField
  86. { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" };
  87. textFieldInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "TextField", textFieldInPadding.Text, "Ok");
  88. window.Padding.Add (textFieldInPadding);
  89. var btnButtonInPadding = new Button { X = Pos.Center (), Y = 0, Text = "_Button in Padding" };
  90. btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
  91. btnButtonInPadding.BorderStyle = LineStyle.Dashed;
  92. btnButtonInPadding.Border.Thickness = new (1, 1, 1, 1);
  93. window.Padding.Add (btnButtonInPadding);
  94. #if SUBVIEW_BASED_BORDER
  95. btnButtonInPadding.Border.CloseButton.Visible = true;
  96. view.Border.CloseButton.Visible = true;
  97. view.Border.CloseButton.Accept += (s, e) =>
  98. {
  99. MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
  100. e.Cancel = true;
  101. };
  102. view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
  103. #endif
  104. };
  105. editor.AutoSelectViewToEdit = true;
  106. editor.AutoSelectSuperView = window;
  107. editor.AutoSelectAdornments = true;
  108. Application.Run (app);
  109. app.Dispose ();
  110. Application.Shutdown ();
  111. }
  112. }