Unicode.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.Collections.ObjectModel;
  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. #if V2_STATUSBAR
  62. new StatusItem []
  63. {
  64. new (
  65. Application.QuitKey,
  66. $"{Application.QuitKey} Выход",
  67. () => Application.RequestStop ()
  68. ),
  69. new (KeyCode.Null, "~F2~ Создать", null),
  70. new (KeyCode.Null, "~F3~ Со_хранить", null)
  71. }
  72. #endif
  73. );
  74. Top.Add (statusBar);
  75. var label = new Label { X = 0, Y = 1, Text = "Label:" };
  76. Win.Add (label);
  77. var testlabel = new Label
  78. {
  79. X = 20,
  80. Y = Pos.Y (label),
  81. Width = Dim.Percent (50),
  82. Text = gitString
  83. };
  84. Win.Add (testlabel);
  85. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Label (CanFocus):" };
  86. Win.Add (label);
  87. var sb = new StringBuilder ();
  88. sb.Append ('e');
  89. sb.Append ('\u0301');
  90. sb.Append ('\u0301');
  91. testlabel = new()
  92. {
  93. X = 20,
  94. Y = Pos.Y (label),
  95. Width = Dim.Percent (50),
  96. CanFocus = true,
  97. HotKeySpecifier = new ('&'),
  98. Text = $"Should be [e with two accents, but isn't due to #2616]: [{sb}]"
  99. };
  100. Win.Add (testlabel);
  101. label = new() { 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() { 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. Width = Dim.Percent (50),
  112. Height = 1,
  113. Text = gitString
  114. };
  115. var checkBoxRight = new CheckBox
  116. {
  117. X = 20,
  118. Y = Pos.Bottom (checkBox),
  119. Width = Dim.Percent (50),
  120. Height = 1,
  121. TextAlignment = Alignment.End,
  122. Text = $"End - {gitString}"
  123. };
  124. Win.Add (checkBox, checkBoxRight);
  125. label = new() { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1, Text = "ComboBox:" };
  126. Win.Add (label);
  127. var comboBox = new ComboBox { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  128. comboBox.SetSource (new ObservableCollection<string> { gitString, "Со_хранить" });
  129. Win.Add (comboBox);
  130. comboBox.Text = gitString;
  131. label = new() { X = Pos.X (label), Y = Pos.Bottom (label) + 2, Text = "HexView:" };
  132. Win.Add (label);
  133. var hexView = new HexView (new MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить")))
  134. {
  135. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Height = 5
  136. };
  137. Win.Add (hexView);
  138. label = new() { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1, Text = "ListView:" };
  139. Win.Add (label);
  140. var listView = new ListView
  141. {
  142. X = 20,
  143. Y = Pos.Y (label),
  144. Width = Dim.Percent (60),
  145. Height = 3,
  146. Source = new ListWrapper<string> (
  147. ["item #1", gitString, "Со_хранить", unicode]
  148. )
  149. };
  150. Win.Add (listView);
  151. label = new() { X = Pos.X (label), Y = Pos.Bottom (listView) + 1, Text = "RadioGroup:" };
  152. Win.Add (label);
  153. var radioGroup = new RadioGroup
  154. {
  155. X = 20,
  156. Y = Pos.Y (label),
  157. Width = Dim.Percent (60),
  158. RadioLabels = new [] { "item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ" }
  159. };
  160. Win.Add (radioGroup);
  161. label = new() { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1, Text = "TextField:" };
  162. Win.Add (label);
  163. var textField = new TextField
  164. {
  165. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Text = gitString + " = Со_хранить"
  166. };
  167. Win.Add (textField);
  168. label = new() { X = Pos.X (label), Y = Pos.Bottom (textField) + 1, Text = "TextView:" };
  169. Win.Add (label);
  170. var textView = new TextView
  171. {
  172. X = 20,
  173. Y = Pos.Y (label),
  174. Width = Dim.Percent (60),
  175. Height = 5,
  176. Text = unicode
  177. };
  178. Win.Add (textView);
  179. }
  180. }