LineViewExample.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // Setup - Create a top-level application window and configure it.
  13. Toplevel appWindow = new ()
  14. {
  15. };
  16. var menu = new MenuBar
  17. {
  18. Menus =
  19. [
  20. new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
  21. ]
  22. };
  23. appWindow.Add (menu);
  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. appWindow.Add (statusBar);
  61. // Run - Start the application.
  62. Application.Run (appWindow);
  63. appWindow.Dispose ();
  64. // Shutdown - Calling Application.Shutdown is required.
  65. Application.Shutdown ();
  66. }
  67. private void Quit () { Application.RequestStop (); }
  68. }