LineViewExample.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Text;
  2. using Terminal.Gui;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("Line View", "Demonstrates drawing lines using the LineView control.")]
  5. [ScenarioCategory ("Controls")]
  6. [ScenarioCategory ("LineView")]
  7. [ScenarioCategory ("Borders")]
  8. public class LineViewExample : Scenario
  9. {
  10. public override void Setup ()
  11. {
  12. Win.Title = GetName ();
  13. Win.Y = 1; // menu
  14. Win.Height = Dim.Fill (1); // status bar
  15. var menu = new MenuBar
  16. {
  17. Menus =
  18. [
  19. new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
  20. ]
  21. };
  22. Top.Add (menu);
  23. Win.Add (new Label { Y = 0, Text = "Regular Line" });
  24. // creates a horizontal line
  25. var line = new LineView { Y = 1 };
  26. Win.Add (line);
  27. Win.Add (new Label { Y = 2, Text = "Double Width Line" });
  28. // creates a horizontal line
  29. var doubleLine = new LineView { Y = 3, LineRune = (Rune)'\u2550' };
  30. Win.Add (doubleLine);
  31. Win.Add (new Label { Y = 4, Text = "Short Line" });
  32. // creates a horizontal line
  33. var shortLine = new LineView { Y = 5, Width = 10 };
  34. Win.Add (shortLine);
  35. Win.Add (new Label { Y = 6, Text = "Arrow Line" });
  36. // creates a horizontal line
  37. var arrowLine = new LineView
  38. {
  39. Y = 7, Width = 10, StartingAnchor = CM.Glyphs.LeftTee, EndingAnchor = (Rune)'>'
  40. };
  41. Win.Add (arrowLine);
  42. Win.Add (new Label { Y = 9, X = 11, Text = "Vertical Line" });
  43. // creates a horizontal line
  44. var verticalLine = new LineView (Orientation.Vertical) { X = 25 };
  45. Win.Add (verticalLine);
  46. Win.Add (new Label { Y = 11, X = 28, Text = "Vertical Arrow" });
  47. // creates a horizontal line
  48. var verticalArrow = new LineView (Orientation.Vertical)
  49. {
  50. X = 27, StartingAnchor = CM.Glyphs.TopTee, EndingAnchor = (Rune)'V'
  51. };
  52. Win.Add (verticalArrow);
  53. var statusBar = new StatusBar (
  54. new StatusItem []
  55. {
  56. new (
  57. Application.QuitKey,
  58. $"{Application.QuitKey} to Quit",
  59. () => Quit ()
  60. )
  61. }
  62. );
  63. Top.Add (statusBar);
  64. }
  65. private void Quit () { Application.RequestStop (); }
  66. }