BordersOnContainers.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using Terminal.Gui;
  5. namespace UICatalog.Scenarios {
  6. public class BordersOnContainers : Window {
  7. public BordersOnContainers (NStack.ustring title, string typeName, View smartView)
  8. {
  9. var borderStyle = LineStyle.Double;
  10. var borderThickness = new Thickness (1, 2, 3, 4);
  11. var borderBrush = Colors.Base.HotFocus.Foreground;
  12. var padding = new Thickness (1, 2, 3, 4);
  13. var background = Colors.Base.HotNormal.Foreground;
  14. smartView.X = Pos.Center ();
  15. smartView.Y = 0;
  16. smartView.Width = 40;
  17. smartView.Height = 20;
  18. smartView.BorderStyle = borderStyle;
  19. smartView.ColorScheme = Colors.TopLevel;
  20. var tf1 = new TextField ("1234567890") { Width = 10 };
  21. var button = new Button ("Press me!") {
  22. X = Pos.Center (),
  23. Y = Pos.Center (),
  24. };
  25. button.Clicked += (s, e) => MessageBox.Query (20, 7, "Hi", $"I'm a {typeName}?", "Yes", "No");
  26. var label = new Label ($"I'm a {typeName}") {
  27. X = Pos.Center (),
  28. Y = Pos.Center () - 1,
  29. };
  30. var tf2 = new TextField ("1234567890") {
  31. X = Pos.AnchorEnd (10),
  32. Y = Pos.AnchorEnd (1),
  33. Width = 10
  34. };
  35. var tv = new TextView () {
  36. Y = Pos.AnchorEnd (2),
  37. Width = 10,
  38. Height = Dim.Fill (),
  39. Text = "1234567890"
  40. };
  41. smartView.Add (tf1, button, label, tf2, tv);
  42. Add (new Label ("Padding:") {
  43. X = Pos.Center () - 23,
  44. });
  45. var paddingTopEdit = new TextField ("") {
  46. X = Pos.Center () - 22,
  47. Y = 1,
  48. Width = 5
  49. };
  50. paddingTopEdit.TextChanging += (s, e) => {
  51. try {
  52. smartView.Padding.Thickness = new Thickness (smartView.Padding.Thickness.Left,
  53. int.Parse (e.NewText.ToString ()), smartView.Padding.Thickness.Right,
  54. smartView.Padding.Thickness.Bottom);
  55. } catch {
  56. if (!e.NewText.IsEmpty) {
  57. e.Cancel = true;
  58. }
  59. }
  60. };
  61. paddingTopEdit.Text = $"{smartView.Padding.Thickness.Top}";
  62. Add (paddingTopEdit);
  63. var paddingLeftEdit = new TextField ("") {
  64. X = Pos.Center () - 30,
  65. Y = 2,
  66. Width = 5
  67. };
  68. paddingLeftEdit.TextChanging += (s, e) => {
  69. try {
  70. smartView.Padding.Thickness = new Thickness (int.Parse (e.NewText.ToString ()),
  71. smartView.Padding.Thickness.Top, smartView.Padding.Thickness.Right,
  72. smartView.Padding.Thickness.Bottom);
  73. } catch {
  74. if (!e.NewText.IsEmpty) {
  75. e.Cancel = true;
  76. }
  77. }
  78. };
  79. paddingLeftEdit.Text = $"{smartView.Padding.Thickness.Left}";
  80. Add (paddingLeftEdit);
  81. var paddingRightEdit = new TextField ("") {
  82. X = Pos.Center () - 15,
  83. Y = 2,
  84. Width = 5
  85. };
  86. paddingRightEdit.TextChanging += (s, e) => {
  87. try {
  88. smartView.Padding.Thickness = new Thickness (smartView.Padding.Thickness.Left,
  89. smartView.Padding.Thickness.Top, int.Parse (e.NewText.ToString ()),
  90. smartView.Padding.Thickness.Bottom);
  91. } catch {
  92. if (!e.NewText.IsEmpty) {
  93. e.Cancel = true;
  94. }
  95. }
  96. };
  97. paddingRightEdit.Text = $"{smartView.Padding.Thickness.Right}";
  98. Add (paddingRightEdit);
  99. var paddingBottomEdit = new TextField ("") {
  100. X = Pos.Center () - 22,
  101. Y = 3,
  102. Width = 5
  103. };
  104. paddingBottomEdit.TextChanging += (s, e) => {
  105. try {
  106. smartView.Padding.Thickness = new Thickness (smartView.Padding.Thickness.Left,
  107. smartView.Padding.Thickness.Top, smartView.Padding.Thickness.Right,
  108. int.Parse (e.NewText.ToString ()));
  109. } catch {
  110. if (!e.NewText.IsEmpty) {
  111. e.Cancel = true;
  112. }
  113. }
  114. };
  115. paddingBottomEdit.Text = $"{smartView.Padding.Thickness.Bottom}";
  116. Add (paddingBottomEdit);
  117. var replacePadding = new Button ("Replace all based on top") {
  118. X = Pos.Left (paddingLeftEdit),
  119. Y = 5
  120. };
  121. replacePadding.Clicked += (s, e) => {
  122. smartView.Padding.Thickness = new Thickness (smartView.Padding.Thickness.Top);
  123. if (paddingTopEdit.Text.IsEmpty) {
  124. paddingTopEdit.Text = "0";
  125. }
  126. paddingBottomEdit.Text = paddingLeftEdit.Text = paddingRightEdit.Text = paddingTopEdit.Text;
  127. };
  128. Add (replacePadding);
  129. Add (new Label ("Border:") {
  130. X = Pos.Center () + 11,
  131. });
  132. var borderTopEdit = new TextField ("") {
  133. X = Pos.Center () + 12,
  134. Y = 1,
  135. Width = 5
  136. };
  137. borderTopEdit.TextChanging += (s, e) => {
  138. try {
  139. smartView.Border.Thickness = new Thickness (smartView.Border.Thickness.Left,
  140. int.Parse (e.NewText.ToString ()), smartView.Border.Thickness.Right,
  141. smartView.Border.Thickness.Bottom);
  142. } catch {
  143. if (!e.NewText.IsEmpty) {
  144. e.Cancel = true;
  145. }
  146. }
  147. };
  148. borderTopEdit.Text = $"{smartView.Border.Thickness.Top}";
  149. Add (borderTopEdit);
  150. var borderLeftEdit = new TextField ("") {
  151. X = Pos.Center () + 5,
  152. Y = 2,
  153. Width = 5
  154. };
  155. borderLeftEdit.TextChanging += (s, e) => {
  156. try {
  157. smartView.Border.Thickness = new Thickness (int.Parse (e.NewText.ToString ()),
  158. smartView.Border.Thickness.Top, smartView.Border.Thickness.Right,
  159. smartView.Border.Thickness.Bottom);
  160. } catch {
  161. if (!e.NewText.IsEmpty) {
  162. e.Cancel = true;
  163. }
  164. }
  165. };
  166. borderLeftEdit.Text = $"{smartView.Border.Thickness.Left}";
  167. Add (borderLeftEdit);
  168. var borderRightEdit = new TextField ("") {
  169. X = Pos.Center () + 19,
  170. Y = 2,
  171. Width = 5
  172. };
  173. borderRightEdit.TextChanging += (s, e) => {
  174. try {
  175. smartView.Border.Thickness = new Thickness (smartView.Border.Thickness.Left,
  176. smartView.Border.Thickness.Top, int.Parse (e.NewText.ToString ()),
  177. smartView.Border.Thickness.Bottom);
  178. } catch {
  179. if (!e.NewText.IsEmpty) {
  180. e.Cancel = true;
  181. }
  182. }
  183. };
  184. borderRightEdit.Text = $"{smartView.Border.Thickness.Right}";
  185. Add (borderRightEdit);
  186. var borderBottomEdit = new TextField ("") {
  187. X = Pos.Center () + 12,
  188. Y = 3,
  189. Width = 5
  190. };
  191. borderBottomEdit.TextChanging += (s, e) => {
  192. try {
  193. smartView.Border.Thickness = new Thickness (smartView.Border.Thickness.Left,
  194. smartView.Border.Thickness.Top, smartView.Border.Thickness.Right,
  195. int.Parse (e.NewText.ToString ()));
  196. } catch {
  197. if (!e.NewText.IsEmpty) {
  198. e.Cancel = true;
  199. }
  200. }
  201. };
  202. borderBottomEdit.Text = $"{smartView.Border.Thickness.Bottom}";
  203. Add (borderBottomEdit);
  204. var replaceBorder = new Button ("Replace all based on top") {
  205. X = Pos.Left (borderLeftEdit),
  206. Y = 5
  207. };
  208. replaceBorder.Clicked += (s, e) => {
  209. smartView.Border.Thickness = new Thickness (smartView.Border.Thickness.Top);
  210. if (borderTopEdit.Text.IsEmpty) {
  211. borderTopEdit.Text = "0";
  212. }
  213. borderBottomEdit.Text = borderLeftEdit.Text = borderRightEdit.Text = borderTopEdit.Text;
  214. };
  215. Add (replaceBorder);
  216. smartView.Y = Pos.Center () + 4;
  217. Add (new Label ("BorderStyle:"));
  218. var borderStyleEnum = Enum.GetValues (typeof (LineStyle)).Cast<LineStyle> ().ToList ();
  219. var rbBorderStyle = new RadioGroup (borderStyleEnum.Select (
  220. e => NStack.ustring.Make (e.ToString ())).ToArray ()) {
  221. X = 2,
  222. Y = 1,
  223. SelectedItem = (int)smartView.BorderStyle
  224. };
  225. Add (rbBorderStyle);
  226. rbBorderStyle.SelectedItemChanged += (s, e) => {
  227. smartView.BorderStyle = (LineStyle)e.SelectedItem;
  228. smartView.SetNeedsDisplay ();
  229. };
  230. Add (new Label ("Background:") {
  231. Y = 12
  232. });
  233. var colorEnum = Enum.GetValues (typeof (Color)).Cast<Color> ().ToList ();
  234. var rbBackground = new RadioGroup (colorEnum.Select (
  235. e => NStack.ustring.Make (e.ToString ())).ToArray ()) {
  236. X = 2,
  237. Y = 13,
  238. //SelectedItem = (int)smartView.BorderFrame.BackgroundColor
  239. };
  240. rbBackground.SelectedItemChanged += (s, e) => {
  241. // smartView.Border.BackgroundColor = (Color)e.SelectedItem;
  242. smartView.Border.ColorScheme = new ColorScheme() {
  243. Normal = new Terminal.Gui.Attribute(Color.Red, Color.White),
  244. HotNormal = new Terminal.Gui.Attribute (Color.Magenta, Color.White),
  245. Disabled = new Terminal.Gui.Attribute (Color.Gray, Color.White),
  246. Focus = new Terminal.Gui.Attribute (Color.Blue, Color.White),
  247. HotFocus = new Terminal.Gui.Attribute (Color.BrightBlue, Color.White),
  248. };
  249. };
  250. Add (rbBackground);
  251. Add (new Label ("BorderBrush:") {
  252. X = Pos.AnchorEnd (20),
  253. Y = 5
  254. });
  255. var rbBorderBrush = new RadioGroup (colorEnum.Select (
  256. e => NStack.ustring.Make (e.ToString ())).ToArray ()) {
  257. X = Pos.AnchorEnd (18),
  258. Y = 6,
  259. //SelectedItem = (int)smartView.Border.ForgroundColor
  260. };
  261. rbBorderBrush.SelectedItemChanged += (s, e) => {
  262. //smartView.Border.ForgroundColor = (Color)e.SelectedItem;
  263. };
  264. Add (rbBorderBrush);
  265. Add (smartView);
  266. Title = title;
  267. }
  268. }
  269. }