RuneWidthGreaterThanOne.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #nullable enable
  2. using System;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("RuneWidthGreaterThanOne", "Test rune width greater than one")]
  5. [ScenarioCategory ("Controls")]
  6. [ScenarioCategory ("Text and Formatting")]
  7. [ScenarioCategory ("Tests")]
  8. public class RuneWidthGreaterThanOne : Scenario
  9. {
  10. private Button? _button;
  11. private Label? _label;
  12. private Label? _labelR;
  13. private Label? _labelV;
  14. private string? _lastRunesUsed;
  15. private TextField? _text;
  16. private Window? _win;
  17. public override void Main ()
  18. {
  19. Application.Init ();
  20. // Window (top-level)
  21. Window win = new ()
  22. {
  23. X = 5,
  24. Y = 5,
  25. Width = Dim.Fill (22),
  26. Height = Dim.Fill (5),
  27. Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable
  28. };
  29. _win = win;
  30. // MenuBar
  31. MenuBar menu = new ();
  32. // Controls
  33. _label = new ()
  34. {
  35. X = Pos.Center (),
  36. Y = 1
  37. };
  38. _text = new ()
  39. {
  40. X = Pos.Center (),
  41. Y = 3,
  42. Width = 20
  43. };
  44. _button = new ()
  45. {
  46. X = Pos.Center (),
  47. Y = 5
  48. };
  49. _labelR = new ()
  50. {
  51. X = Pos.AnchorEnd (30),
  52. Y = 18
  53. };
  54. _labelV = new ()
  55. {
  56. TextDirection = TextDirection.TopBottom_LeftRight,
  57. X = Pos.AnchorEnd (30),
  58. Y = Pos.Bottom (_labelR)
  59. };
  60. menu.Add (
  61. new MenuBarItem (
  62. "Padding",
  63. [
  64. new MenuItem
  65. {
  66. Title = "With Padding",
  67. Action = () =>
  68. {
  69. if (_win is { })
  70. {
  71. _win.Padding!.Thickness = new (1);
  72. }
  73. }
  74. },
  75. new MenuItem
  76. {
  77. Title = "Without Padding",
  78. Action = () =>
  79. {
  80. if (_win is { })
  81. {
  82. _win.Padding!.Thickness = new (0);
  83. }
  84. }
  85. }
  86. ]
  87. )
  88. );
  89. menu.Add (
  90. new MenuBarItem (
  91. "BorderStyle",
  92. [
  93. new MenuItem
  94. {
  95. Title = "Single",
  96. Action = () =>
  97. {
  98. if (_win is { })
  99. {
  100. _win.BorderStyle = LineStyle.Single;
  101. }
  102. }
  103. },
  104. new MenuItem
  105. {
  106. Title = "None",
  107. Action = () =>
  108. {
  109. if (_win is { })
  110. {
  111. _win.BorderStyle = LineStyle.None;
  112. }
  113. }
  114. }
  115. ]
  116. )
  117. );
  118. menu.Add (
  119. new MenuBarItem (
  120. "Runes length",
  121. [
  122. new MenuItem
  123. {
  124. Title = "Wide",
  125. Action = WideRunes
  126. },
  127. new MenuItem
  128. {
  129. Title = "Narrow",
  130. Action = NarrowRunes
  131. },
  132. new MenuItem
  133. {
  134. Title = "Mixed",
  135. Action = MixedRunes
  136. }
  137. ]
  138. )
  139. );
  140. // Add views in order of visual appearance
  141. win.Add (menu, _label, _text, _button, _labelR, _labelV);
  142. WideRunes ();
  143. Application.Run (win);
  144. win.Dispose ();
  145. Application.Shutdown ();
  146. }
  147. private void MixedMessage (object? sender, EventArgs e)
  148. {
  149. if (_text is { })
  150. {
  151. MessageBox.Query (Application.Instance, "Say Hello 你", $"Hello {_text.Text}", "Ok");
  152. }
  153. }
  154. private void MixedRunes ()
  155. {
  156. if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
  157. {
  158. return;
  159. }
  160. UnsetClickedEvent ();
  161. _label.Text = "Enter your name 你:";
  162. _text.Text = "gui.cs 你:";
  163. _button.Text = "Say Hello 你";
  164. _button.Accepting += MixedMessage;
  165. _labelR.X = Pos.AnchorEnd (21);
  166. _labelR.Y = 18;
  167. _labelR.Text = "This is a test text 你";
  168. _labelV.X = Pos.AnchorEnd (21);
  169. _labelV.Y = Pos.Bottom (_labelR);
  170. _labelV.Text = "This is a test text 你";
  171. _win.Title = "HACC Demo 你";
  172. _lastRunesUsed = "Mixed";
  173. Application.LayoutAndDraw ();
  174. }
  175. private void NarrowMessage (object? sender, EventArgs e)
  176. {
  177. if (_text is { })
  178. {
  179. MessageBox.Query (Application.Instance, "Say Hello", $"Hello {_text.Text}", "Ok");
  180. }
  181. }
  182. private void NarrowRunes ()
  183. {
  184. if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
  185. {
  186. return;
  187. }
  188. UnsetClickedEvent ();
  189. _label.Text = "Enter your name:";
  190. _text.Text = "gui.cs";
  191. _button.Text = "Say Hello";
  192. _button.Accepting += NarrowMessage;
  193. _labelR.X = Pos.AnchorEnd (19);
  194. _labelR.Y = 18;
  195. _labelR.Text = "This is a test text";
  196. _labelV.X = Pos.AnchorEnd (19);
  197. _labelV.Y = Pos.Bottom (_labelR);
  198. _labelV.Text = "This is a test text";
  199. _win.Title = "HACC Demo";
  200. _lastRunesUsed = "Narrow";
  201. Application.LayoutAndDraw ();
  202. }
  203. private void UnsetClickedEvent ()
  204. {
  205. if (_button is null)
  206. {
  207. return;
  208. }
  209. switch (_lastRunesUsed)
  210. {
  211. case "Narrow":
  212. _button.Accepting -= NarrowMessage;
  213. break;
  214. case "Mixed":
  215. _button.Accepting -= MixedMessage;
  216. break;
  217. case "Wide":
  218. _button.Accepting -= WideMessage;
  219. break;
  220. }
  221. }
  222. private void WideMessage (object? sender, EventArgs e)
  223. {
  224. if (_text is { })
  225. {
  226. MessageBox.Query (Application.Instance, "こんにちはと言う", $"こんにちは {_text.Text}", "Ok");
  227. }
  228. }
  229. private void WideRunes ()
  230. {
  231. if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
  232. {
  233. return;
  234. }
  235. UnsetClickedEvent ();
  236. _label.Text = "あなたの名前を入力してください:";
  237. _text.Text = "ティラミス";
  238. _button.Text = "こんにちはと言う";
  239. _button.Accepting += WideMessage;
  240. _labelR.X = Pos.AnchorEnd (29);
  241. _labelR.Y = 18;
  242. _labelR.Text = "あなたの名前を入力してください";
  243. _labelV.X = Pos.AnchorEnd (29);
  244. _labelV.Y = Pos.Bottom (_labelR);
  245. _labelV.Text = "あなたの名前を入力してください";
  246. _win.Title = "デモエムポンズ";
  247. _lastRunesUsed = "Wide";
  248. Application.LayoutAndDraw ();
  249. }
  250. }