Browse Source

Fixes #4151, #4152. Remove LineView class and replace all usages with Line (#4268)

* Initial plan

* Remove LineView and replace all usages with Line

- Deleted LineViewExample.cs scenario
- Deleted LineViewTests.cs test file
- Replaced LineView with Line in all examples (CollectionNavigatorTester, FileDialogExamples, LineExample, Wizard)
- Replaced LineView with Line in all tests (ViewTests, TileViewTests)
- Changed TileViewLineView to inherit from Line instead of LineView
- Removed LineView.cs file
- Removed LineView category from TileViewNesting scenario

Co-authored-by: tig <[email protected]>

* Remove LineView references from documentation

- Updated Line.cs XML documentation to remove comparison with LineView
- Removed LineView section from views.md documentation

Co-authored-by: tig <[email protected]>

* Fixes Wizard (#4269)

* fixed Wizard

* Made Line use GetAttributeForRole

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tig <[email protected]>
Co-authored-by: Tig <[email protected]>
Copilot 2 months ago
parent
commit
e352dde696

+ 1 - 1
Examples/UICatalog/Scenarios/CollectionNavigatorTester.cs

@@ -129,7 +129,7 @@ public class CollectionNavigatorTester : Scenario
         _items = new (_items.OrderBy (i => i, StringComparer.OrdinalIgnoreCase));
 
         CreateListView ();
-        var vsep = new LineView (Orientation.Vertical) { X = Pos.Right (_listView), Y = 1, Height = Dim.Fill () };
+        var vsep = new Line { Orientation = Orientation.Vertical, X = Pos.Right (_listView), Y = 1, Height = Dim.Fill () };
         top.Add (vsep);
         CreateTreeView ();
 

+ 5 - 5
Examples/UICatalog/Scenarios/FileDialogExamples.cs

@@ -62,7 +62,7 @@ public class FileDialogExamples : Scenario
         x = 24;
 
         win.Add (
-                 new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
+                 new Line { Orientation = Orientation.Vertical, X = x++, Y = 1, Height = 4 }
                 );
         win.Add (new Label { X = x++, Y = y++, Text = "Caption" });
 
@@ -74,7 +74,7 @@ public class FileDialogExamples : Scenario
         x = 34;
 
         win.Add (
-                 new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
+                 new Line { Orientation = Orientation.Vertical, X = x++, Y = 1, Height = 4 }
                 );
         win.Add (new Label { X = x++, Y = y++, Text = "OpenMode" });
 
@@ -86,7 +86,7 @@ public class FileDialogExamples : Scenario
         x = 48;
 
         win.Add (
-                 new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
+                 new Line { Orientation = Orientation.Vertical, X = x++, Y = 1, Height = 4 }
                 );
         win.Add (new Label { X = x++, Y = y++, Text = "Icons" });
 
@@ -101,7 +101,7 @@ public class FileDialogExamples : Scenario
         x = 24;
 
         win.Add (
-                 new LineView (Orientation.Vertical) { X = x++, Y = y + 1, Height = 4 }
+                 new Line { Orientation = Orientation.Vertical, X = x++, Y = y + 1, Height = 4 }
                 );
         win.Add (new Label { X = x++, Y = y++, Text = "Allowed" });
 
@@ -113,7 +113,7 @@ public class FileDialogExamples : Scenario
         x = 45;
 
         win.Add (
-                 new LineView (Orientation.Vertical) { X = x++, Y = y + 1, Height = 4 }
+                 new Line { Orientation = Orientation.Vertical, X = x++, Y = y + 1, Height = 4 }
                 );
         win.Add (new Label { X = x++, Y = y++, Text = "Buttons" });
 

+ 0 - 15
Examples/UICatalog/Scenarios/LineExample.cs

@@ -203,21 +203,6 @@ public class LineExample : Scenario
 
         app.Add (framedView);
 
-        // Section 6: Comparison with LineView
-        var comparisonLabel = new Label
-        {
-            X = 35,
-            Y = 15,
-            Text = "Line vs LineView Comparison:"
-        };
-        app.Add (comparisonLabel);
-
-        app.Add (new Label { X = 35, Y = 16, Text = "Line (uses LineCanvas):" });
-        app.Add (new Line { X = 35, Y = 17, Width = 20, Style = LineStyle.Single });
-
-        app.Add (new Label { X = 35, Y = 18, Text = "LineView (direct render):" });
-        app.Add (new LineView { X = 35, Y = 19, Width = 20 });
-
         // Add help text
         var helpLabel = new Label
         {

+ 0 - 76
Examples/UICatalog/Scenarios/LineViewExample.cs

@@ -1,76 +0,0 @@
-using System.Globalization;
-using System.Text;
-
-namespace UICatalog.Scenarios;
-
-[ScenarioMetadata ("Line View", "Demonstrates drawing lines using the LineView control.")]
-[ScenarioCategory ("Controls")]
-[ScenarioCategory ("LineView")]
-[ScenarioCategory ("Adornments")]
-public class LineViewExample : Scenario
-{
-    public override void Main ()
-    {
-        Application.Init ();
-
-        var appWindow = new Window()
-        {
-            Title = GetQuitKeyAndName (),
-        };
-
-        appWindow.Add (new Label { Y = 1, Text = "Regular Line" });
-
-        // creates a horizontal line
-        var line = new LineView { Y = 2 };
-
-        appWindow.Add (line);
-
-        appWindow.Add (new Label { Y = 3, Text = "Double Width Line" });
-
-        // creates a horizontal line
-        var doubleLine = new LineView { Y = 4, LineRune = (Rune)'\u2550' };
-
-        appWindow.Add (doubleLine);
-
-        appWindow.Add (new Label { Y = 5, Text = "Short Line" });
-
-        // creates a horizontal line
-        var shortLine = new LineView { Y = 5, Width = 10 };
-
-        appWindow.Add (shortLine);
-
-        appWindow.Add (new Label { Y = 7, Text = "Arrow Line" });
-
-        // creates a horizontal line
-        var arrowLine = new LineView
-        {
-            Y = 8, Width = 10, StartingAnchor = Glyphs.LeftTee, EndingAnchor = (Rune)'>'
-        };
-
-        appWindow.Add (arrowLine);
-
-        appWindow.Add (new Label { Y = 10, X = 11, Text = "Vertical Line" });
-
-        // creates a horizontal line
-        var verticalLine = new LineView (Orientation.Vertical) { X = 25 };
-
-        appWindow.Add (verticalLine);
-
-        appWindow.Add (new Label { Y = 12, X = 28, Text = "Vertical Arrow" });
-
-        // creates a horizontal line
-        var verticalArrow = new LineView (Orientation.Vertical)
-        {
-            X = 27, StartingAnchor = Glyphs.TopTee, EndingAnchor = (Rune)'V'
-        };
-
-        appWindow.Add (verticalArrow);
-
-        // Run - Start the application.
-        Application.Run (appWindow);
-        appWindow.Dispose ();
-
-        // Shutdown - Calling Application.Shutdown is required.
-        Application.Shutdown ();
-    }
-}

+ 0 - 1
Examples/UICatalog/Scenarios/TileViewNesting.cs

@@ -4,7 +4,6 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Tile View Nesting", "Demonstrates recursive nesting of TileViews")]
 [ScenarioCategory ("Controls")]
-[ScenarioCategory ("LineView")]
 public class TileViewNesting : Scenario
 {
     private CheckBox _cbBorder;

+ 4 - 4
Terminal.Gui/Views/Line.cs

@@ -8,9 +8,8 @@ namespace Terminal.Gui.Views;
 /// <remarks>
 ///     <para>
 ///         <see cref="Line"/> is a <see cref="View"/> that renders a single horizontal or vertical line
-///         using the <see cref="LineCanvas"/> system. Unlike <see cref="LineView"/>, which directly renders
-///         runes, <see cref="Line"/> integrates with the LineCanvas to enable proper box-drawing character
-///         selection and line intersection handling.
+///         using the <see cref="LineCanvas"/> system. <see cref="Line"/> integrates with the LineCanvas
+///         to enable proper box-drawing character selection and line intersection handling.
 ///     </para>
 ///     <para>
 ///         The line's appearance is controlled by the <see cref="Style"/> property, which supports
@@ -232,7 +231,8 @@ public class Line : View, IOrientation
                             pos,
                             length,
                             Orientation,
-                            Style
+                            Style,
+                            GetAttributeForRole(VisualRole.Normal)
                            );
 
         return true;

+ 0 - 93
Terminal.Gui/Views/LineView.cs

@@ -1,93 +0,0 @@
-
-namespace Terminal.Gui.Views;
-
-/// <summary>A straight line control either horizontal or vertical</summary>
-public class LineView : View
-{
-    /// <summary>Creates a horizontal line</summary>
-    public LineView () : this (Orientation.Horizontal) { }
-
-    /// <summary>Creates a horizontal or vertical line based on <paramref name="orientation"/></summary>
-    public LineView (Orientation orientation)
-    {
-        CanFocus = false;
-
-        switch (orientation)
-        {
-            case Orientation.Horizontal:
-                Height = Dim.Auto (minimumContentDim: 1);
-                Width = Dim.Fill ();
-                LineRune = Glyphs.HLine;
-
-                break;
-            case Orientation.Vertical:
-                Height = Dim.Fill ();
-                Width = Dim.Auto (minimumContentDim: 1);
-                LineRune = Glyphs.VLine;
-
-                break;
-            default:
-                throw new ArgumentException ($"Unknown Orientation {orientation}");
-        }
-
-        Orientation = orientation;
-    }
-
-    /// <summary>
-    ///     The rune to display at the end of the line (right end of horizontal line or bottom end of vertical). If not
-    ///     specified then <see cref="LineRune"/> is used
-    /// </summary>
-    public Rune? EndingAnchor { get; set; }
-
-    /// <summary>The symbol to use for drawing the line</summary>
-    public Rune LineRune { get; set; }
-
-    /// <summary>
-    ///     The direction of the line.  If you change this you will need to manually update the Width/Height of the
-    ///     control to cover a relevant area based on the new direction.
-    /// </summary>
-    public Orientation Orientation { get; set; }
-
-    /// <summary>
-    ///     The rune to display at the start of the line (left end of horizontal line or top end of vertical) If not
-    ///     specified then <see cref="LineRune"/> is used
-    /// </summary>
-    public Rune? StartingAnchor { get; set; }
-
-    /// <summary>Draws the line including any starting/ending anchors</summary>
-    protected override bool OnDrawingContent ()
-    {
-        Move (0, 0);
-        SetAttribute (GetAttributeForRole (VisualRole.Normal));
-
-        int hLineWidth = Math.Max (1, Glyphs.HLine.GetColumns ());
-
-        int dEnd = Orientation == Orientation.Horizontal ? Viewport.Width : Viewport.Height;
-
-        for (var d = 0; d < dEnd; d += hLineWidth)
-        {
-            if (Orientation == Orientation.Horizontal)
-            {
-                Move (d, 0);
-            }
-            else
-            {
-                Move (0, d);
-            }
-
-            Rune rune = LineRune;
-
-            if (d == 0)
-            {
-                rune = StartingAnchor ?? LineRune;
-            }
-            else if (d == dEnd - 1)
-            {
-                rune = EndingAnchor ?? LineRune;
-            }
-
-            Driver?.AddRune (rune);
-        }
-        return true;
-    }
-}

+ 1 - 2
Terminal.Gui/Views/TileView.cs

@@ -780,7 +780,6 @@ public class TileView : View
             line.Height = _orientation == Orientation.Vertical
                               ? Dim.Fill ()
                               : 1;
-            line.LineRune = _orientation == Orientation.Vertical ? Glyphs.VLine : Glyphs.HLine;
 
             if (_orientation == Orientation.Vertical)
             {
@@ -864,7 +863,7 @@ public class TileView : View
         }
     }
 
-    private class TileViewLineView : LineView
+    private class TileViewLineView : Line
     {
         public Point? moveRuneRenderLocation;
 

+ 3 - 3
Terminal.Gui/Views/Wizard/Wizard.cs

@@ -78,8 +78,8 @@ public class Wizard : Dialog
             IsDefault = true
         };
 
-        //// Add a horiz separator
-        var separator = new LineView (Orientation.Horizontal) { Y = Pos.Top (BackButton) - 1 };
+        // Add a horiz separator
+        var separator = new Line { Orientation = Orientation.Horizontal, X = -1, Y = Pos.Top (BackButton) - 1, Length = Dim.Fill (-1) };
 
         base.Add (separator);
         AddButton (BackButton);
@@ -301,7 +301,7 @@ public class Wizard : Dialog
 
         if (previous is { })
         {
-           return GoToStep (previous);
+            return GoToStep (previous);
         }
 
         return false;

+ 1 - 1
Tests/UnitTests/View/ViewTests.cs

@@ -338,7 +338,7 @@ public class ViewTests
 
         top.Add (new Label { Text = "111" });
         v.Add (top);
-        v.Add (new LineView (Orientation.Horizontal) { Y = 1 });
+        v.Add (new Line { Orientation = Orientation.Horizontal, Y = 1 });
         bottom.Add (new Label { Text = "222" });
         v.Add (bottom);
 

+ 0 - 42
Tests/UnitTests/Views/LineViewTests.cs

@@ -1,42 +0,0 @@
-using UnitTests;
-
-namespace Terminal.Gui.ViewsTests;
-
-public class LineViewTests
-{
-    [Fact]
-    [AutoInitShutdown]
-    public void LineView_DefaultConstructor ()
-    {
-        var horizontal = new LineView ();
-
-        Assert.Equal (Orientation.Horizontal, horizontal.Orientation);
-        Assert.Equal (Dim.Fill (), horizontal.Width);
-        horizontal.Layout ();
-        Assert.Equal (1, horizontal.Frame.Height);
-    }
-
-    [Fact]
-    [AutoInitShutdown]
-    public void LineView_Horizontal ()
-    {
-        var horizontal = new LineView (Orientation.Horizontal);
-
-        Assert.Equal (Orientation.Horizontal, horizontal.Orientation);
-        Assert.Equal (Dim.Fill (), horizontal.Width);
-        horizontal.Layout ();
-        Assert.Equal (1, horizontal.Frame.Height);
-    }
-
-    [Fact]
-    [AutoInitShutdown]
-    public void LineView_Vertical ()
-    {
-        var vert = new LineView (Orientation.Vertical);
-
-        Assert.Equal (Orientation.Vertical, vert.Orientation);
-        Assert.Equal (Dim.Fill (), vert.Height);
-        vert.Layout ();
-        Assert.Equal (1, vert.Frame.Width);
-    }
-}

+ 17 - 17
Tests/UnitTests/Views/TileViewTests.cs

@@ -1630,7 +1630,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Horizontal ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.Orientation = Orientation.Horizontal;
         tileView.Layout ();
         tileView.Draw ();
@@ -1654,7 +1654,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Horizontal_Focused ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
 
         tileView.Orientation = Orientation.Horizontal;
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
@@ -1700,7 +1700,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Horizontal_View1MinSize_Absolute ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
 
         tileView.Orientation = Orientation.Horizontal;
@@ -1792,7 +1792,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_InsertPanelAtEnd ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.InsertTile (2);
 
         tileView.Layout ();
@@ -1811,7 +1811,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_InsertPanelAtStart ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.InsertTile (0);
 
         tileView.Layout ();
@@ -1830,7 +1830,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_InsertPanelMiddle ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.InsertTile (1);
 
         tileView.Layout ();
@@ -1849,7 +1849,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
 
         tileView.Layout ();
         tileView.Draw ();
@@ -1872,7 +1872,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_Focused ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
 
         AutoInitShutdownAttribute.RunIteration ();
@@ -1913,7 +1913,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_Focused_50PercentSplit ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.SetSplitterPos (0, Pos.Percent (50));
         Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
@@ -1961,7 +1961,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_Focused_WithBorder ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
         AutoInitShutdownAttribute.RunIteration ();
 
@@ -2001,7 +2001,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_View1MinSize_Absolute ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
         tileView.Tiles.ElementAt (0).MinSize = 6;
 
@@ -2044,7 +2044,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
         tileView.Tiles.ElementAt (0).MinSize = 5;
 
@@ -2087,7 +2087,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_View2MinSize_Absolute ()
     {
-        TileView tileView = Get11By3TileView (out LineView line);
+        TileView tileView = Get11By3TileView (out Line line);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
         tileView.Tiles.ElementAt (1).MinSize = 6;
         AutoInitShutdownAttribute.RunIteration ();
@@ -2132,7 +2132,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
         tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
         tileView.Tiles.ElementAt (1).MinSize = 5;
 
@@ -2177,7 +2177,7 @@ public class TileViewTests (ITestOutputHelper output)
     [AutoInitShutdown]
     public void TestTileView_Vertical_WithBorder ()
     {
-        TileView tileView = Get11By3TileView (out LineView line, true);
+        TileView tileView = Get11By3TileView (out Line line, true);
 
         AutoInitShutdownAttribute.RunIteration ();
 
@@ -2210,7 +2210,7 @@ public class TileViewTests (ITestOutputHelper output)
         Assert.Empty (tv.Tiles.ElementAt (0).Title);
     }
 
-    private TileView Get11By3TileView (out LineView line, bool withBorder = false)
+    private TileView Get11By3TileView (out Line line, bool withBorder = false)
     {
         TileView split = Get11By3TileView (withBorder);
         line = GetLine (split);
@@ -2267,7 +2267,7 @@ public class TileViewTests (ITestOutputHelper output)
         return tv;
     }
 
-    private LineView GetLine (TileView tileView) { return tileView.SubViews.OfType<LineView> ().Single (); }
+    private Line GetLine (TileView tileView) { return tileView.SubViews.OfType<Line> ().Single (); }
 
     /// <summary>Creates a vertical orientation root container with left pane split into two (with horizontal splitter line).</summary>
     /// <param name="withBorder"></param>

+ 0 - 8
docfx/docs/views.md

@@ -307,14 +307,6 @@ Draws a single line using the [LineStyle](~/api/Terminal.Gui.Drawing.LineStyle.y
 ──────────────────────────────────────────────────
 ```
 
-## [LineView](~/api/Terminal.Gui.Views.LineView.yml)
-
-A straight line control either horizontal or vertical
-
-```text
-──────────────────────────────────────────────────
-```
-
 ## [ListView](~/api/Terminal.Gui.Views.ListView.yml)
 
 Provides a scrollable list of data where each item can be activated to perform an action.