Unicode.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new Rune ('&') };
  40. Win.Add (testlabel);
  41. label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  42. Win.Add (label);
  43. var button = new Button ("A123456789♥♦♣♠JQK") { X = 20, Y = Pos.Y (label) };
  44. Win.Add (button);
  45. label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  46. Win.Add (label);
  47. var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  48. var checkBoxRight = new CheckBox ($"Align Right - {gitString}") { X = 20, Y = Pos.Bottom (checkBox), Width = Dim.Percent (50), TextAlignment = TextAlignment.Right};
  49. Win.Add (checkBox, checkBoxRight);
  50. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 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 string [] { "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. }
  101. }
  102. }