Adornments.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  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 appWindow = new ()
  12. {
  13. Title = GetQuitKeyAndName (),
  14. BorderStyle = LineStyle.None
  15. };
  16. var editor = new AdornmentsEditor
  17. {
  18. AutoSelectViewToEdit = true,
  19. // This is for giggles, to show that the editor can be moved around.
  20. Arrangement = ViewArrangement.Movable,
  21. X = Pos.AnchorEnd ()
  22. };
  23. editor.Border!.Thickness = new (1, 2, 1, 1);
  24. appWindow.Add (editor);
  25. var window = new Window
  26. {
  27. Title = "The _Window",
  28. Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable,
  29. Width = Dim.Fill (Dim.Func (_ => editor.Frame.Width)),
  30. Height = Dim.Fill ()
  31. };
  32. appWindow.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!.SetScheme (
  39. new (color.SuperView.GetScheme ())
  40. {
  41. Normal = new (
  42. color.SuperView.GetAttributeForRole (VisualRole.Normal).Foreground,
  43. e.Result,
  44. color.SuperView.GetAttributeForRole (VisualRole.Normal).Style
  45. )
  46. });
  47. };
  48. var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
  49. button.Accepting += (s, e) =>
  50. MessageBox.Query (appWindow.App, 20, 7, "Hi", $"Am I a {window.GetType ().Name}?", "Yes", "No");
  51. var label = new TextView
  52. {
  53. X = Pos.Center (),
  54. Y = Pos.Bottom (button),
  55. Title = "Title",
  56. Text = "I have a 3 row top border.\nMy border inherits from the SuperView.",
  57. Width = 40,
  58. Height = 6 // TODO: Use Dim.Auto
  59. };
  60. label.Border!.Thickness = new (1, 3, 1, 1);
  61. var btnButtonInWindow = new Button { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Button" };
  62. var labelAnchorEnd = new Label
  63. {
  64. Y = Pos.AnchorEnd (),
  65. Width = 40,
  66. Height = Dim.Percent (20),
  67. Text = "Label\nY=AnchorEnd(),Height=Dim.Percent(10)",
  68. SchemeName = "Dialog"
  69. };
  70. window.Margin!.Data = "Margin";
  71. window.Margin!.Text = "Margin Text";
  72. window.Margin!.Thickness = new (0);
  73. window.Border!.Data = "Border";
  74. window.Border!.Text = "Border Text";
  75. window.Border!.Thickness = new (0);
  76. window.Padding.Data = "Padding";
  77. window.Padding.Text = "Padding Text line 1\nPadding Text line 3\nPadding Text line 3\nPadding Text line 4\nPadding Text line 5";
  78. window.Padding.Thickness = new (3);
  79. window.Padding.SchemeName = "Error";
  80. window.Padding.CanFocus = true;
  81. var longLabel = new Label
  82. {
  83. X = 40, Y = 5, Title = "This is long text (in a label) that should clip."
  84. };
  85. longLabel.TextFormatter.WordWrap = true;
  86. window.Add (tf1, color, button, label, btnButtonInWindow, labelAnchorEnd, longLabel);
  87. window.Initialized += (s, e) =>
  88. {
  89. editor.ViewToEdit = window;
  90. editor.ShowViewIdentifier = true;
  91. var labelInPadding = new Label { X = 0, Y = 1, Title = "_Text:" };
  92. window.Padding.Add (labelInPadding);
  93. var textFieldInPadding = new TextField
  94. {
  95. X = Pos.Right (labelInPadding) + 1,
  96. Y = Pos.Top (labelInPadding), Width = 10,
  97. Text = "text (Y = 1)",
  98. CanFocus = true
  99. };
  100. textFieldInPadding.Accepting += (s, e) => MessageBox.Query (appWindow.App, 20, 7, "TextField", textFieldInPadding.Text, "Ok");
  101. window.Padding.Add (textFieldInPadding);
  102. var btnButtonInPadding = new Button
  103. {
  104. X = Pos.Center (),
  105. Y = 1,
  106. Text = "_Button in Padding Y = 1",
  107. CanFocus = true,
  108. HighlightStates = MouseState.None,
  109. };
  110. btnButtonInPadding.Accepting += (s, e) => MessageBox.Query (appWindow.App, 20, 7, "Hi", "Button in Padding Pressed!", "Ok");
  111. btnButtonInPadding.BorderStyle = LineStyle.Dashed;
  112. btnButtonInPadding.Border!.Thickness = new (1, 1, 1, 1);
  113. window.Padding.Add (btnButtonInPadding);
  114. #if SUBVIEW_BASED_BORDER
  115. btnButtonInPadding.Border!.CloseButton.Visible = true;
  116. view.Border!.CloseButton.Visible = true;
  117. view.Border!.CloseButton.Accept += (s, e) =>
  118. {
  119. MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
  120. e.Handled = true;
  121. };
  122. view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
  123. #endif
  124. };
  125. editor.AutoSelectViewToEdit = true;
  126. editor.AutoSelectSuperView = window;
  127. editor.AutoSelectAdornments = true;
  128. Application.Run (appWindow);
  129. appWindow.Dispose ();
  130. Application.Shutdown ();
  131. }
  132. }