LineViewExample.cs 2.2 KB

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