LineViewExample.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Main ()
  11. {
  12. Application.Init ();
  13. // Setup - Create a top-level application window and configure it.
  14. Toplevel appWindow = new ();
  15. var menu = new MenuBar
  16. {
  17. Menus =
  18. [
  19. new ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
  20. ]
  21. };
  22. appWindow.Add (menu);
  23. appWindow.Add (new Label { Y = 1, Text = "Regular Line" });
  24. // creates a horizontal line
  25. var line = new LineView { Y = 2 };
  26. appWindow.Add (line);
  27. appWindow.Add (new Label { Y = 3, Text = "Double Width Line" });
  28. // creates a horizontal line
  29. var doubleLine = new LineView { Y = 4, LineRune = (Rune)'\u2550' };
  30. appWindow.Add (doubleLine);
  31. appWindow.Add (new Label { Y = 5, Text = "Short Line" });
  32. // creates a horizontal line
  33. var shortLine = new LineView { Y = 5, Width = 10 };
  34. appWindow.Add (shortLine);
  35. appWindow.Add (new Label { Y = 7, Text = "Arrow Line" });
  36. // creates a horizontal line
  37. var arrowLine = new LineView
  38. {
  39. Y = 8, Width = 10, StartingAnchor = CM.Glyphs.LeftTee, EndingAnchor = (Rune)'>'
  40. };
  41. appWindow.Add (arrowLine);
  42. appWindow.Add (new Label { Y = 10, X = 11, Text = "Vertical Line" });
  43. // creates a horizontal line
  44. var verticalLine = new LineView (Orientation.Vertical) { X = 25 };
  45. appWindow.Add (verticalLine);
  46. appWindow.Add (new Label { Y = 12, 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. appWindow.Add (verticalArrow);
  53. var statusBar = new StatusBar (
  54. new Shortcut []
  55. {
  56. new (Application.QuitKey, "Quit", Quit)
  57. }
  58. );
  59. appWindow.Add (statusBar);
  60. // Run - Start the application.
  61. Application.Run (appWindow);
  62. appWindow.Dispose ();
  63. // Shutdown - Calling Application.Shutdown is required.
  64. Application.Shutdown ();
  65. }
  66. private void Quit () { Application.RequestStop (); }
  67. }