LineExample.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. namespace UICatalog.Scenarios;
  2. [ScenarioMetadata ("Line", "Demonstrates the Line view with LineCanvas integration.")]
  3. [ScenarioCategory ("Controls")]
  4. [ScenarioCategory ("Drawing")]
  5. [ScenarioCategory ("Adornments")]
  6. public class LineExample : Scenario
  7. {
  8. public override void Main ()
  9. {
  10. Application.Init ();
  11. var app = new Window
  12. {
  13. Title = GetQuitKeyAndName ()
  14. };
  15. // Section 1: Basic Lines
  16. var basicLabel = new Label
  17. {
  18. X = 0,
  19. Y = 0,
  20. Text = "Basic Lines:"
  21. };
  22. app.Add (basicLabel);
  23. // Horizontal line
  24. var hLine = new Line
  25. {
  26. X = 0,
  27. Y = 1,
  28. Width = 30
  29. };
  30. app.Add (hLine);
  31. // Vertical line
  32. var vLine = new Line
  33. {
  34. X = 32,
  35. Y = 0,
  36. Height = 10,
  37. Orientation = Orientation.Vertical
  38. };
  39. app.Add (vLine);
  40. // Section 2: Different Line Styles
  41. var stylesLabel = new Label
  42. {
  43. X = 0,
  44. Y = 3,
  45. Text = "Line Styles:"
  46. };
  47. app.Add (stylesLabel);
  48. (LineStyle, string) [] styles = new []
  49. {
  50. (LineStyle.Single, "Single"),
  51. (LineStyle.Double, "Double"),
  52. (LineStyle.Heavy, "Heavy"),
  53. (LineStyle.Rounded, "Rounded"),
  54. (LineStyle.Dashed, "Dashed"),
  55. (LineStyle.Dotted, "Dotted")
  56. };
  57. var yPos = 4;
  58. foreach ((LineStyle style, string name) in styles)
  59. {
  60. app.Add (new Label { X = 0, Y = yPos, Width = 15, Text = name + ":" });
  61. app.Add (new Line { X = 16, Y = yPos, Width = 14, Style = style });
  62. yPos++;
  63. }
  64. // Section 3: Line Intersections
  65. var intersectionLabel = new Label
  66. {
  67. X = 35,
  68. Y = 3,
  69. Text = "Line Intersections:"
  70. };
  71. app.Add (intersectionLabel);
  72. // Create a grid of intersecting lines
  73. var gridX = 35;
  74. var gridY = 5;
  75. // Horizontal lines in the grid
  76. for (var i = 0; i < 5; i++)
  77. {
  78. app.Add (
  79. new Line
  80. {
  81. X = gridX,
  82. Y = gridY + i * 2,
  83. Width = 21,
  84. Style = LineStyle.Single
  85. });
  86. }
  87. // Vertical lines in the grid
  88. for (var i = 0; i < 5; i++)
  89. {
  90. app.Add (
  91. new Line
  92. {
  93. X = gridX + i * 5,
  94. Y = gridY,
  95. Height = 9,
  96. Orientation = Orientation.Vertical,
  97. Style = LineStyle.Single
  98. });
  99. }
  100. // Section 4: Mixed Styles (shows how LineCanvas handles different line styles)
  101. var mixedLabel = new Label
  102. {
  103. X = 60,
  104. Y = 3,
  105. Text = "Mixed Style Intersections:"
  106. };
  107. app.Add (mixedLabel);
  108. // Double horizontal
  109. app.Add (
  110. new Line
  111. {
  112. X = 60,
  113. Y = 5,
  114. Width = 20,
  115. Style = LineStyle.Double
  116. });
  117. // Single vertical through double horizontal
  118. app.Add (
  119. new Line
  120. {
  121. X = 70,
  122. Y = 4,
  123. Height = 3,
  124. Orientation = Orientation.Vertical,
  125. Style = LineStyle.Single
  126. });
  127. // Heavy horizontal
  128. app.Add (
  129. new Line
  130. {
  131. X = 60,
  132. Y = 8,
  133. Width = 20,
  134. Style = LineStyle.Heavy
  135. });
  136. // Single vertical through heavy horizontal
  137. app.Add (
  138. new Line
  139. {
  140. X = 70,
  141. Y = 7,
  142. Height = 3,
  143. Orientation = Orientation.Vertical,
  144. Style = LineStyle.Single
  145. });
  146. // Section 5: Box Example (showing borders and lines working together)
  147. var boxLabel = new Label
  148. {
  149. X = 0,
  150. Y = 12,
  151. Text = "Lines with Borders:"
  152. };
  153. app.Add (boxLabel);
  154. var framedView = new FrameView
  155. {
  156. Title = "Frame",
  157. X = 0,
  158. Y = 13,
  159. Width = 30,
  160. Height = 8,
  161. BorderStyle = LineStyle.Single
  162. };
  163. // Add a cross inside the frame
  164. framedView.Add (
  165. new Line
  166. {
  167. X = 0,
  168. Y = 3,
  169. Width = Dim.Fill (),
  170. Style = LineStyle.Single
  171. });
  172. framedView.Add (
  173. new Line
  174. {
  175. X = 14,
  176. Y = 0,
  177. Height = Dim.Fill (),
  178. Orientation = Orientation.Vertical,
  179. Style = LineStyle.Single
  180. });
  181. app.Add (framedView);
  182. // Add help text
  183. var helpLabel = new Label
  184. {
  185. X = Pos.Center (),
  186. Y = Pos.AnchorEnd (1),
  187. Text = "Line integrates with LineCanvas for automatic intersection handling"
  188. };
  189. app.Add (helpLabel);
  190. Application.Run (app);
  191. app.Dispose ();
  192. Application.Shutdown ();
  193. }
  194. }