Unicode.cs 7.2 KB

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