Unicode.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using NStack;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Terminal.Gui;
  5. namespace UICatalog {
  6. [ScenarioMetadata (Name: "Unicode", Description: "Tries to test Unicode in all controls (#204)")]
  7. [ScenarioCategory ("Text")]
  8. [ScenarioCategory ("Controls")]
  9. class UnicodeInMenu : Scenario {
  10. public override void Setup ()
  11. {
  12. const string IdenticalSign = "\u2261";
  13. const string ArrowUpSign = "\u2191";
  14. const string ArrowDownSign = "\u2193";
  15. const string EllipsesSign = "\u2026";
  16. const string StashSign = "\u205E";
  17. //string text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line.";
  18. string unicode = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
  19. string gitString = $"gui.cs master {IdenticalSign} {ArrowDownSign}18 {ArrowUpSign}10 {StashSign}1 {EllipsesSign}";
  20. var menu = new MenuBar (new MenuBarItem [] {
  21. new MenuBarItem ("_Файл", new MenuItem [] {
  22. new MenuItem ("_Создать", "Creates new file", null),
  23. new MenuItem ("_Открыть", "", null),
  24. new MenuItem ("Со_хранить", "", null),
  25. new MenuItem ("_Выход", "", () => Application.RequestStop() )
  26. }),
  27. new MenuBarItem ("_Edit", new MenuItem [] {
  28. new MenuItem ("_Copy", "", null),
  29. new MenuItem ("C_ut", "", null),
  30. new MenuItem ("_Paste", "", null)
  31. })
  32. });
  33. Top.Add (menu);
  34. var label = new Label ("Label:") { X = 0, Y = 1 };
  35. Win.Add (label);
  36. var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
  37. Win.Add (testlabel);
  38. label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  39. Win.Add (label);
  40. testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new System.Rune('&') };
  41. Win.Add (testlabel);
  42. label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  43. Win.Add (label);
  44. var button = new Button ("A123456789♥♦♣♠JQK") { X = 20, Y = Pos.Y (label) };
  45. Win.Add (button);
  46. label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  47. Win.Add (label);
  48. var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  49. Win.Add (checkBox);
  50. // BUGBUG: Combobox does not deal with unicode properly.
  51. #if false
  52. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  53. Win.Add (label);
  54. var comboBox = new ComboBox () {
  55. X = 20,
  56. Y = Pos.Y (label),
  57. Width = Dim.Percent (50),
  58. };
  59. comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
  60. Win.Add (comboBox);
  61. comboBox.Text = gitString;
  62. #endif
  63. label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
  64. Win.Add (label);
  65. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
  66. X = 20,
  67. Y = Pos.Y (label),
  68. Width = Dim.Percent (60),
  69. Height = 5
  70. };
  71. Win.Add (hexView);
  72. label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
  73. Win.Add (label);
  74. var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
  75. X = 20,
  76. Y = Pos.Y (label),
  77. Width = Dim.Percent (60),
  78. Height = 3,
  79. };
  80. Win.Add (listView);
  81. label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
  82. Win.Add (label);
  83. var radioGroup = new RadioGroup (new ustring [] { "item #1", gitString, "Со_хранить" }, selected: 0) {
  84. X = 20,
  85. Y = Pos.Y (label),
  86. Width = Dim.Percent (60),
  87. };
  88. Win.Add (radioGroup);
  89. label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
  90. Win.Add (label);
  91. var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
  92. Win.Add (textField);
  93. label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };
  94. Win.Add (label);
  95. var textView = new TextView () {
  96. X = 20,
  97. Y = Pos.Y (label),
  98. Width = Dim.Percent (60),
  99. Height = 5,
  100. Text = unicode,
  101. };
  102. Win.Add (textView);
  103. }
  104. }
  105. }