LineViewExample.cs 2.7 KB

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