Unicode.cs 6.8 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 (
  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 (
  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. Width = Dim.Percent (50),
  80. Text = gitString
  81. };
  82. Win.Add (testlabel);
  83. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Label (CanFocus):" };
  84. Win.Add (label);
  85. var sb = new StringBuilder ();
  86. sb.Append ('e');
  87. sb.Append ('\u0301');
  88. sb.Append ('\u0301');
  89. testlabel = new()
  90. {
  91. X = 20,
  92. Y = Pos.Y (label),
  93. Width = Dim.Percent (50),
  94. CanFocus = true,
  95. HotKeySpecifier = new ('&'),
  96. Text = $"Should be [e with two accents, but isn't due to #2616]: [{sb}]"
  97. };
  98. Win.Add (testlabel);
  99. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Button:" };
  100. Win.Add (label);
  101. var button = new Button { X = 20, Y = Pos.Y (label), Text = "A123456789♥♦♣♠JQK" };
  102. Win.Add (button);
  103. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "CheckBox:" };
  104. Win.Add (label);
  105. var checkBox = new CheckBox
  106. {
  107. X = 20,
  108. Y = Pos.Y (label),
  109. Width = Dim.Percent (50),
  110. Height = 1,
  111. Text = gitString
  112. };
  113. var checkBoxRight = new CheckBox
  114. {
  115. X = 20,
  116. Y = Pos.Bottom (checkBox),
  117. Width = Dim.Percent (50),
  118. Height = 1,
  119. TextAlignment = Alignment.End,
  120. Text = $"End - {gitString}"
  121. };
  122. Win.Add (checkBox, checkBoxRight);
  123. label = new() { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1, Text = "ComboBox:" };
  124. Win.Add (label);
  125. var comboBox = new ComboBox { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  126. comboBox.SetSource (new List<string> { gitString, "Со_хранить" });
  127. Win.Add (comboBox);
  128. comboBox.Text = gitString;
  129. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 2, Text = "HexView:" };
  130. Win.Add (label);
  131. var hexView = new HexView (new MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить")))
  132. {
  133. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Height = 5
  134. };
  135. Win.Add (hexView);
  136. label = new() { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1, Text = "ListView:" };
  137. Win.Add (label);
  138. var listView = new ListView
  139. {
  140. X = 20,
  141. Y = Pos.Y (label),
  142. Width = Dim.Percent (60),
  143. Height = 3,
  144. Source = new ListWrapper (
  145. new List<string> { "item #1", gitString, "Со_хранить", unicode }
  146. )
  147. };
  148. Win.Add (listView);
  149. label = new() { X = Pos.X (label), Y = Pos.Bottom (listView) + 1, Text = "RadioGroup:" };
  150. Win.Add (label);
  151. var radioGroup = new RadioGroup
  152. {
  153. X = 20,
  154. Y = Pos.Y (label),
  155. Width = Dim.Percent (60),
  156. RadioLabels = new [] { "item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ" }
  157. };
  158. Win.Add (radioGroup);
  159. label = new() { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1, Text = "TextField:" };
  160. Win.Add (label);
  161. var textField = new TextField
  162. {
  163. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Text = gitString + " = Со_хранить"
  164. };
  165. Win.Add (textField);
  166. label = new() { X = Pos.X (label), Y = Pos.Bottom (textField) + 1, Text = "TextView:" };
  167. Win.Add (label);
  168. var textView = new TextView
  169. {
  170. X = 20,
  171. Y = Pos.Y (label),
  172. Width = Dim.Percent (60),
  173. Height = 5,
  174. Text = unicode
  175. };
  176. Win.Add (textView);
  177. }
  178. }