Unicode.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 statusBar = new StatusBar (new StatusItem [] {
  35. new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Выход", () => Application.RequestStop()),
  36. new StatusItem (Key.Unknown, "~F2~ Создать", null),
  37. new StatusItem(Key.Unknown, "~F3~ Со_хранить", null),
  38. });
  39. Top.Add (statusBar);
  40. var label = new Label ("Label:") { X = 0, Y = 1 };
  41. Win.Add (label);
  42. var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
  43. Win.Add (testlabel);
  44. label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  45. Win.Add (label);
  46. testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new System.Rune('&') };
  47. Win.Add (testlabel);
  48. label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  49. Win.Add (label);
  50. var button = new Button ("A123456789♥♦♣♠JQK") { X = 20, Y = Pos.Y (label) };
  51. Win.Add (button);
  52. label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  53. Win.Add (label);
  54. var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  55. Win.Add (checkBox);
  56. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  57. Win.Add (label);
  58. var comboBox = new ComboBox () {
  59. X = 20,
  60. Y = Pos.Y (label),
  61. Width = Dim.Percent (50)
  62. };
  63. comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
  64. Win.Add (comboBox);
  65. comboBox.Text = gitString;
  66. label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
  67. Win.Add (label);
  68. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
  69. X = 20,
  70. Y = Pos.Y (label),
  71. Width = Dim.Percent (60),
  72. Height = 5
  73. };
  74. Win.Add (hexView);
  75. label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
  76. Win.Add (label);
  77. var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
  78. X = 20,
  79. Y = Pos.Y (label),
  80. Width = Dim.Percent (60),
  81. Height = 3,
  82. };
  83. Win.Add (listView);
  84. label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
  85. Win.Add (label);
  86. var radioGroup = new RadioGroup (new ustring [] { "item #1", gitString, "Со_хранить" }, selected: 0) {
  87. X = 20,
  88. Y = Pos.Y (label),
  89. Width = Dim.Percent (60),
  90. };
  91. Win.Add (radioGroup);
  92. label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
  93. Win.Add (label);
  94. var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
  95. Win.Add (textField);
  96. label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };
  97. Win.Add (label);
  98. var textView = new TextView () {
  99. X = 20,
  100. Y = Pos.Y (label),
  101. Width = Dim.Percent (60),
  102. Height = 5,
  103. Text = unicode,
  104. };
  105. Win.Add (textView);
  106. }
  107. }
  108. }