Unicode.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #nullable enable
  2. using System.Text;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("Unicode", "Tries to test Unicode in all controls (#204)")]
  5. [ScenarioCategory ("Text and Formatting")]
  6. [ScenarioCategory ("Controls")]
  7. public class UnicodeInMenu : Scenario
  8. {
  9. public override void Main ()
  10. {
  11. var unicode =
  12. "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
  13. var gitString =
  14. $"gui.cs 糊 (hú) {Glyphs.IdenticalTo} {Glyphs.DownArrow}18 {Glyphs.UpArrow}10 {Glyphs.VerticalFourDots}1 {Glyphs.HorizontalEllipsis}";
  15. Application.Init ();
  16. Window appWindow = new ()
  17. {
  18. Title = GetQuitKeyAndName (),
  19. BorderStyle = LineStyle.None
  20. };
  21. // MenuBar
  22. MenuBar menu = new ();
  23. menu.Add (
  24. new MenuBarItem (
  25. "_Файл",
  26. [
  27. new MenuItem
  28. {
  29. Title = "_Создать",
  30. HelpText = "Creates new file"
  31. },
  32. new MenuItem
  33. {
  34. Title = "_Открыть"
  35. },
  36. new MenuItem
  37. {
  38. Title = "Со_хранить"
  39. },
  40. new MenuItem
  41. {
  42. Title = "_Выход",
  43. Action = () => Application.RequestStop ()
  44. }
  45. ]
  46. )
  47. );
  48. menu.Add (
  49. new MenuBarItem (
  50. "_Edit",
  51. [
  52. new MenuItem
  53. {
  54. Title = "_Copy"
  55. },
  56. new MenuItem
  57. {
  58. Title = "C_ut"
  59. },
  60. new MenuItem
  61. {
  62. Title = "_糊",
  63. HelpText = "hú (Paste)"
  64. }
  65. ]
  66. )
  67. );
  68. appWindow.Add (menu);
  69. Label label = new () { X = 0, Y = Pos.Bottom (menu), Text = "Label:" };
  70. appWindow.Add (label);
  71. Label testlabel = new ()
  72. {
  73. X = 20,
  74. Y = Pos.Y (label),
  75. Width = Dim.Percent (50),
  76. Text = gitString
  77. };
  78. appWindow.Add (testlabel);
  79. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Label (CanFocus):" };
  80. appWindow.Add (label);
  81. StringBuilder sb = new ();
  82. sb.Append ('e');
  83. sb.Append ('\u0301');
  84. sb.Append ('\u0301');
  85. testlabel = new ()
  86. {
  87. X = 20,
  88. Y = Pos.Y (label),
  89. Width = Dim.Percent (50),
  90. CanFocus = true,
  91. HotKeySpecifier = new ('&'),
  92. Text = $"Should be [e with two accents, but isn't due to #2616]: [{sb}]"
  93. };
  94. appWindow.Add (testlabel);
  95. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Button:" };
  96. appWindow.Add (label);
  97. Button button = new () { X = 20, Y = Pos.Y (label), Text = "A123456789♥♦♣♠JQK" };
  98. appWindow.Add (button);
  99. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "CheckBox:" };
  100. appWindow.Add (label);
  101. CheckBox checkBox = new ()
  102. {
  103. X = 20,
  104. Y = Pos.Y (label),
  105. Width = Dim.Percent (50),
  106. Height = 1,
  107. Text = gitString
  108. };
  109. appWindow.Add (checkBox);
  110. CheckBox checkBoxRight = new ()
  111. {
  112. X = 20,
  113. Y = Pos.Bottom (checkBox),
  114. Width = Dim.Percent (50),
  115. Height = 1,
  116. TextAlignment = Alignment.End,
  117. Text = $"End - {gitString}"
  118. };
  119. appWindow.Add (checkBoxRight);
  120. label = new () { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 2, Text = "HexView:" };
  121. appWindow.Add (label);
  122. HexView hexView = new (new MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить")))
  123. {
  124. X = 20,
  125. Y = Pos.Y (label),
  126. Width = Dim.Percent (60),
  127. Height = 5
  128. };
  129. appWindow.Add (hexView);
  130. label = new () { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1, Text = "ListView:" };
  131. appWindow.Add (label);
  132. ListView listView = new ()
  133. {
  134. X = 20,
  135. Y = Pos.Y (label),
  136. Width = Dim.Percent (60),
  137. Height = 3,
  138. Source = new ListWrapper<string> (
  139. ["item #1", gitString, "Со_хранить", unicode]
  140. )
  141. };
  142. appWindow.Add (listView);
  143. label = new () { X = Pos.X (label), Y = Pos.Bottom (listView) + 1, Text = "OptionSelector:" };
  144. appWindow.Add (label);
  145. OptionSelector optionSelector = new ()
  146. {
  147. X = 20,
  148. Y = Pos.Y (label),
  149. Width = Dim.Percent (60),
  150. Labels = ["item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ"]
  151. };
  152. appWindow.Add (optionSelector);
  153. label = new () { X = Pos.X (label), Y = Pos.Bottom (optionSelector) + 1, Text = "TextField:" };
  154. appWindow.Add (label);
  155. TextField textField = new ()
  156. {
  157. X = 20,
  158. Y = Pos.Y (label),
  159. Width = Dim.Percent (60),
  160. Text = gitString + " = Со_хранить"
  161. };
  162. appWindow.Add (textField);
  163. label = new () { X = Pos.X (label), Y = Pos.Bottom (textField) + 1, Text = "TextView:" };
  164. appWindow.Add (label);
  165. TextView textView = new ()
  166. {
  167. X = 20,
  168. Y = Pos.Y (label),
  169. Width = Dim.Percent (60),
  170. Height = 5,
  171. Text = unicode
  172. };
  173. appWindow.Add (textView);
  174. // StatusBar
  175. StatusBar statusBar = new (
  176. [
  177. new (
  178. Application.QuitKey,
  179. "Выход",
  180. () => Application.RequestStop ()
  181. ),
  182. new (Key.F2, "Создать", null),
  183. new (Key.F3, "Со_хранить", null)
  184. ]
  185. );
  186. appWindow.Add (statusBar);
  187. Application.Run (appWindow);
  188. appWindow.Dispose ();
  189. Application.Shutdown ();
  190. }
  191. }