Scrolling.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using Terminal.Gui;
  3. namespace UICatalog {
  4. [ScenarioMetadata (Name: "Scrolling", Description: "Demonstrates ScrollView etc...")]
  5. [ScenarioCategory ("Controls")]
  6. [ScenarioCategory ("Bug Repro")]
  7. class Scrolling : Scenario {
  8. public override void Setup ()
  9. {
  10. var label = new Label ("ScrollView (new Rect (2, 2, 50, 20)) with a 200, 100 ContentSize...") {
  11. X = 0, Y = 0,
  12. ColorScheme = Colors.Dialog
  13. };
  14. Win.Add (label);
  15. // BUGBUG: ScrollView only supports Absolute Positioning (#72)
  16. var scrollView = new ScrollView (new Rect (2, 2, 50, 20));
  17. scrollView.ColorScheme = Colors.TopLevel;
  18. scrollView.ContentSize = new Size (200, 100);
  19. //ContentOffset = new Point (0, 0),
  20. scrollView.ShowVerticalScrollIndicator = true;
  21. scrollView.ShowHorizontalScrollIndicator = true;
  22. const string rule = "|123456789";
  23. var horizontalRuler = new Label ("") {
  24. X = 0,
  25. Y = 0,
  26. Width = Dim.Fill (1), // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does.
  27. ColorScheme = Colors.Error
  28. };
  29. scrollView.Add (horizontalRuler);
  30. const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
  31. var verticalRuler = new Label ("") {
  32. X = 0,
  33. Y = 0,
  34. Width = 1,
  35. Height = Dim.Fill (),
  36. ColorScheme = Colors.Error
  37. };
  38. scrollView.Add (verticalRuler);
  39. Application.Resized += (sender, a) => {
  40. horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
  41. verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
  42. };
  43. scrollView.Add (new Button ("Press me!") {
  44. X = 3,
  45. Y = 3,
  46. Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No")
  47. });
  48. scrollView.Add (new Button ("A very long button. Should be wide enough to demo clipping!") {
  49. X = 3,
  50. Y = 4,
  51. Width = 50,
  52. Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No")
  53. });
  54. scrollView.Add (new TextField ("This is a test of...") {
  55. X = 3,
  56. Y = 5,
  57. Width = 50,
  58. ColorScheme = Colors.Dialog
  59. });
  60. scrollView.Add (new TextField ("... the emergency broadcast sytem.") {
  61. X = 3,
  62. Y = 10,
  63. Width = 50,
  64. ColorScheme = Colors.Dialog
  65. });
  66. scrollView.Add (new TextField ("Last line") {
  67. X = 3,
  68. Y = 99,
  69. Width = 50,
  70. ColorScheme = Colors.Dialog
  71. });
  72. // Demonstrate AnchorEnd - Button is anchored to bottom/right
  73. var anchorButton = new Button ("Bottom Right") {
  74. Y = Pos.AnchorEnd () - 1,
  75. };
  76. // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
  77. anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
  78. anchorButton.Clicked = () => {
  79. // Ths demonstrates how to have a dynamically sized button
  80. // Each time the button is clicked the button's text gets longer
  81. // The call to Win.LayoutSubviews causes the Computed layout to
  82. // get updated.
  83. anchorButton.Text += "!";
  84. Win.LayoutSubviews ();
  85. };
  86. scrollView.Add (anchorButton);
  87. Win.Add (scrollView);
  88. }
  89. }
  90. }