Unicode.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  51. Win.Add (label);
  52. var comboBox = new ComboBox () {
  53. X = 20,
  54. Y = Pos.Y (label),
  55. Width = Dim.Percent (50),
  56. };
  57. comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
  58. Win.Add (comboBox);
  59. comboBox.Text = gitString;
  60. label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
  61. Win.Add (label);
  62. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
  63. X = 20,
  64. Y = Pos.Y (label),
  65. Width = Dim.Percent (60),
  66. Height = 5
  67. };
  68. Win.Add (hexView);
  69. label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
  70. Win.Add (label);
  71. var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
  72. X = 20,
  73. Y = Pos.Y (label),
  74. Width = Dim.Percent (60),
  75. Height = 3,
  76. };
  77. Win.Add (listView);
  78. label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
  79. Win.Add (label);
  80. var radioGroup = new RadioGroup (new ustring [] { "item #1", gitString, "Со_хранить" }, selected: 0) {
  81. X = 20,
  82. Y = Pos.Y (label),
  83. Width = Dim.Percent (60),
  84. };
  85. Win.Add (radioGroup);
  86. label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
  87. Win.Add (label);
  88. var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
  89. Win.Add (textField);
  90. label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };
  91. Win.Add (label);
  92. var textView = new TextView () {
  93. X = 20,
  94. Y = Pos.Y (label),
  95. Width = Dim.Percent (60),
  96. Height = 5,
  97. Text = unicode,
  98. };
  99. Win.Add (textView);
  100. // Move Win down to row 1, below menu
  101. Win.Y = 1;
  102. Top.LayoutSubviews ();
  103. }
  104. }
  105. }