Unicode.cs 7.3 KB

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