2
0

Unicode.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using Terminal.Gui;
  4. namespace UICatalog.Scenarios {
  5. [ScenarioMetadata (Name: "Unicode", Description: "Tries to test Unicode in all controls (#204)")]
  6. [ScenarioCategory ("Text and Formatting")]
  7. [ScenarioCategory ("Controls")]
  8. public class UnicodeInMenu : Scenario {
  9. public override void Setup ()
  10. {
  11. string unicode = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
  12. string gitString = $"gui.cs 糊 (hú) {ConfigurationManager.Glyphs.IdenticalTo} {ConfigurationManager.Glyphs.DownArrow}18 {ConfigurationManager.Glyphs.UpArrow}10 {ConfigurationManager.Glyphs.VerticalFourDots}1 {ConfigurationManager.Glyphs.HorizontalEllipsis}";
  13. var menu = new MenuBar (new MenuBarItem [] {
  14. new MenuBarItem ("_Файл", new MenuItem [] {
  15. new MenuItem ("_Создать", "Creates new file", null),
  16. new MenuItem ("_Открыть", "", null),
  17. new MenuItem ("Со_хранить", "", null),
  18. new MenuItem ("_Выход", "", () => Application.RequestStop() )
  19. }),
  20. new MenuBarItem ("_Edit", new MenuItem [] {
  21. new MenuItem ("_Copy", "", null),
  22. new MenuItem ("C_ut", "", null),
  23. new MenuItem ("_糊", "hú (Paste)", null)
  24. })
  25. });
  26. Application.Top.Add (menu);
  27. var statusBar = new StatusBar (new StatusItem [] {
  28. new StatusItem(Application.QuitKey, $"{Application.QuitKey} Выход", () => Application.RequestStop()),
  29. new StatusItem (Key.Unknown, "~F2~ Создать", null),
  30. new StatusItem(Key.Unknown, "~F3~ Со_хранить", null),
  31. });
  32. Application.Top.Add (statusBar);
  33. var label = new Label ("Label:") { X = 0, Y = 1 };
  34. Win.Add (label);
  35. var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
  36. Win.Add (testlabel);
  37. label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  38. Win.Add (label);
  39. var sb = new StringBuilder ();
  40. sb.Append ('e');
  41. sb.Append ('\u0301');
  42. sb.Append ('\u0301');
  43. testlabel = new Label ($"Should be [e with two accents, but isn't due to #2616]: [{sb}]") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new Rune ('&') };
  44. Win.Add (testlabel);
  45. label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  46. Win.Add (label);
  47. var button = new Button ("A123456789♥♦♣♠JQK") { X = 20, Y = Pos.Y (label) };
  48. Win.Add (button);
  49. label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  50. Win.Add (label);
  51. var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  52. var checkBoxRight = new CheckBox ($"Align Right - {gitString}") { X = 20, Y = Pos.Bottom (checkBox), Width = Dim.Percent (50), TextAlignment = TextAlignment.Right};
  53. Win.Add (checkBox, checkBoxRight);
  54. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1 };
  55. Win.Add (label);
  56. var comboBox = new ComboBox () {
  57. X = 20,
  58. Y = Pos.Y (label),
  59. Width = Dim.Percent (50)
  60. };
  61. comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
  62. Win.Add (comboBox);
  63. comboBox.Text = gitString;
  64. label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
  65. Win.Add (label);
  66. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
  67. X = 20,
  68. Y = Pos.Y (label),
  69. Width = Dim.Percent (60),
  70. Height = 5
  71. };
  72. Win.Add (hexView);
  73. label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
  74. Win.Add (label);
  75. var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
  76. X = 20,
  77. Y = Pos.Y (label),
  78. Width = Dim.Percent (60),
  79. Height = 3,
  80. };
  81. Win.Add (listView);
  82. label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
  83. Win.Add (label);
  84. var radioGroup = new RadioGroup (new string [] { "item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ" }, selected: 0) {
  85. X = 20,
  86. Y = Pos.Y (label),
  87. Width = Dim.Percent (60),
  88. };
  89. Win.Add (radioGroup);
  90. label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
  91. Win.Add (label);
  92. var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
  93. Win.Add (textField);
  94. label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };
  95. Win.Add (label);
  96. var textView = new TextView () {
  97. X = 20,
  98. Y = Pos.Y (label),
  99. Width = Dim.Percent (60),
  100. Height = 5,
  101. Text = unicode,
  102. };
  103. Win.Add (textView);
  104. }
  105. }
  106. }