Przeglądaj źródła

Added ContentSize property and first unit test

Tig 1 rok temu
rodzic
commit
6f664c9c6a

+ 4 - 0
Terminal.Gui/View/Adornment/Adornment.cs

@@ -203,6 +203,10 @@ public class Adornment : View
     /// <returns><see langword="true"/> if the specified Parent's SuperView-relative coordinates are within the Adornment's Thickness. </returns>
     public override bool Contains (int x, int y)
     {
+        if (Parent is null)
+        {
+            return false;
+        }
         Rectangle frame = Frame;
         frame.Offset (Parent.Frame.Location);
 

+ 8 - 0
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -389,6 +389,14 @@ public partial class View
     /// </summary>
     public Point GetViewportOffset () { return Padding is null ? Point.Empty : Padding.Thickness.GetInside (Padding.Frame).Location; }
 
+    /// <summary>
+    /// Gets or sets the size of the View's content. If the value is <c>Size.Empty</c> the size of the content is
+    /// the same as the size of the <see cref="Viewport"/>, and <c>Viewport.Location</c> will always be <c>0, 0</c>.
+    /// If a positive size is provided, <see cref="Viewport"/> describes the portion of the content currently visible
+    /// to the view. This enables virtual scrolling.
+    /// </summary>
+    public Size ContentSize { get; set; }
+
     #endregion Viewport
 
     #region AutoSize

+ 15 - 4
UnitTests/View/Layout/ViewportTests.cs

@@ -24,16 +24,16 @@ public class ViewportTests (ITestOutputHelper output)
 
         var view = new View ();
         view.Frame = frame;
-        view.BeginInit();
-        view.EndInit();
+        view.BeginInit ();
+        view.EndInit ();
 
         // Act
         var bounds = view.Viewport;
 
         // Assert
-        Assert.Equal(expectedW, bounds.Width);
+        Assert.Equal (expectedW, bounds.Width);
     }
-    
+
     [Theory]
     [InlineData (0, 0, 10)]
     [InlineData (1, 0, 9)]
@@ -149,4 +149,15 @@ public class ViewportTests (ITestOutputHelper output)
         // Assert
         Assert.Equal (expectedW, bounds.Width);
     }
+
+    [Fact]
+    public void ContentSize_Empty_ByDefault ()
+    {
+        View view = new ()
+        {
+            Width = 1,
+            Height = 1
+        };
+        Assert.Equal(Size.Empty, view.ContentSize);
+    }
 }