Text.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Text;
  3. using Terminal.Gui;
  4. namespace UICatalog {
  5. [ScenarioMetadata (Name: "Text Input Controls", Description: "Tests all text input controls")]
  6. [ScenarioCategory ("Controls")]
  7. [ScenarioCategory ("Bug Repro")]
  8. class Text : Scenario {
  9. public override void Setup ()
  10. {
  11. var s = "TAB to jump between text fields.";
  12. var textField = new TextField (s) {
  13. X = 1,
  14. Y = 1,
  15. Width = Dim.Percent (50),
  16. //ColorScheme = Colors.Dialog
  17. };
  18. Win.Add (textField);
  19. var labelMirroringTextField = new Label (textField.Text) {
  20. X = Pos.Right (textField) + 1,
  21. Y = Pos.Top (textField),
  22. Width = Dim.Fill (1)
  23. };
  24. Win.Add (labelMirroringTextField);
  25. textField.TextChanged += (prev) => {
  26. labelMirroringTextField.Text = textField.Text;
  27. };
  28. var textView = new TextView () {
  29. X = 1,
  30. Y = 3,
  31. Width = Dim.Percent (50),
  32. Height = Dim.Percent (30),
  33. ColorScheme = Colors.Dialog
  34. };
  35. textView.Text = s;
  36. Win.Add (textView);
  37. var labelMirroringTextView = new Label (textView.Text) {
  38. X = Pos.Right (textView) + 1,
  39. Y = Pos.Top (textView),
  40. Width = Dim.Fill (1),
  41. Height = Dim.Height (textView),
  42. };
  43. Win.Add (labelMirroringTextView);
  44. textView.TextChanged += () => {
  45. labelMirroringTextView.Text = textView.Text;
  46. };
  47. // BUGBUG: 531 - TAB doesn't go to next control from HexView
  48. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (s))) {
  49. X = 1,
  50. Y = Pos.Bottom (textView) + 1,
  51. Width = Dim.Fill (1),
  52. Height = Dim.Percent (30),
  53. //ColorScheme = Colors.Dialog
  54. };
  55. Win.Add (hexView);
  56. var dateField = new DateField (System.DateTime.Now) {
  57. X = 1,
  58. Y = Pos.Bottom (hexView) + 1,
  59. Width = 20,
  60. //ColorScheme = Colors.Dialog,
  61. IsShortFormat = false
  62. };
  63. Win.Add (dateField);
  64. var labelMirroringDateField = new Label (dateField.Text) {
  65. X = Pos.Right (dateField) + 1,
  66. Y = Pos.Top (dateField),
  67. Width = Dim.Width (dateField),
  68. Height = Dim.Height (dateField),
  69. };
  70. Win.Add (labelMirroringDateField);
  71. dateField.TextChanged += (prev) => {
  72. labelMirroringDateField.Text = dateField.Text;
  73. };
  74. _timeField = new TimeField (DateTime.Now.TimeOfDay) {
  75. X = Pos.Right (labelMirroringDateField) + 5,
  76. Y = Pos.Bottom (hexView) + 1,
  77. Width = 20,
  78. //ColorScheme = Colors.Dialog,
  79. IsShortFormat = false
  80. };
  81. Win.Add (_timeField);
  82. _labelMirroringTimeField = new Label (_timeField.Text) {
  83. X = Pos.Right (_timeField) + 1,
  84. Y = Pos.Top (_timeField),
  85. Width = Dim.Width (_timeField),
  86. Height = Dim.Height (_timeField),
  87. };
  88. Win.Add (_labelMirroringTimeField);
  89. _timeField.TimeChanged += TimeChanged;
  90. }
  91. TimeField _timeField;
  92. Label _labelMirroringTimeField;
  93. private void TimeChanged (DateTimeEventArgs<TimeSpan> e)
  94. {
  95. _labelMirroringTimeField.Text = _timeField.Text;
  96. }
  97. }
  98. }