LineViewExample.cs 2.7 KB

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