Tig il y a 9 mois
Parent
commit
5a11a390ba

+ 14 - 0
Terminal.Gui/View/View.Drawing.cs

@@ -779,12 +779,26 @@ public partial class View // Drawing APIs
 
     #region NeedsDisplay
 
+    // TODO: Make _needsDisplayRect nullable instead of relying on Empty
+    // TODO: If null, it means ?
+    // TODO: If Empty, it means no need to redraw
+    // TODO: If not Empty, it means the region that needs to be redrawn
     // The viewport-relative region that needs to be redrawn. Marked internal for unit tests.
     internal Rectangle _needsDisplayRect = Rectangle.Empty;
 
     /// <summary>Gets or sets whether the view needs to be redrawn.</summary>
+    /// <remarks>
+    ///     <para>
+    ///         Will be <see langword="true"/> if the <see cref="NeedsLayout"/> property is <see langword="true"/> or if 
+    ///         any part of the view's <see cref="Viewport"/> needs to be redrawn.
+    ///     </para>
+    ///     <para>
+    ///         Setting has no effect on <see cref="NeedsLayout"/>.
+    ///     </para>
+    /// </remarks>
     public bool NeedsDisplay
     {
+        // TODO: Figure out if we can decouple NeedsDisplay from NeedsLayout. This is a temporary fix.
         get => _needsDisplayRect != Rectangle.Empty || NeedsLayout;
         set
         {

+ 4 - 2
UnitTests/View/Draw/NeedsDisplayTests.cs

@@ -10,7 +10,7 @@ public class NeedsDisplayTests ()
         View view = new () { Width = 0, Height = 0 };
         view.BeginInit ();
         view.EndInit ();
-        Assert.False (view.NeedsDisplay);
+        Assert.True (view.NeedsDisplay);
         //Assert.False (view.SubViewNeedsDisplay);
     }
 
@@ -31,6 +31,8 @@ public class NeedsDisplayTests ()
         Assert.True (view1.NeedsDisplay);
         Assert.True (view2.NeedsDisplay);
 
+        superView.Layout ();    // NeedsDisplay is always false if Layout is needed
+
         superView.Draw ();
 
         Assert.False (superView.NeedsDisplay);
@@ -91,7 +93,7 @@ public class NeedsDisplayTests ()
         view.BeginInit ();
         view.NeedsDisplay = false;
         view.EndInit ();
-        Assert.False (view.NeedsDisplay);
+        Assert.True (view.NeedsDisplay);
     }
 
 

+ 1 - 1
UnitTests/View/Layout/FrameTests.cs

@@ -22,7 +22,7 @@ public class FrameTests (ITestOutputHelper output)
     {
         Rectangle frame = new (1, 2, 3, 4);
         View view = new ();
-        Assert.False (view.NeedsLayout);
+        Assert.True (view.NeedsLayout);
         Assert.Equal (Rectangle.Empty, view.Frame);
 
         view.Frame = frame;

+ 8 - 24
UnitTests/View/Layout/SetLayoutTests.cs

@@ -125,8 +125,8 @@ public class SetLayoutTests (ITestOutputHelper output)
         superView.BeginInit ();
         superView.EndInit ();
         superView.LayoutSubviews ();
-        Assert.Equal (2, layoutStartedRaised);
-        Assert.Equal (2, layoutCompleteRaised);
+        Assert.Equal (3, layoutStartedRaised);
+        Assert.Equal (3, layoutCompleteRaised);
     }
 
     [Fact]
@@ -230,21 +230,21 @@ public class SetLayoutTests (ITestOutputHelper output)
         superView.EndInit ();
         Assert.Equal (1, borderLayoutStartedCount);
         Assert.Equal (1, borderLayoutCompleteCount);
-        Assert.Equal (1, layoutStartedCount);
-        Assert.Equal (1, layoutCompleteCount);
+        Assert.Equal (2, layoutStartedCount);
+        Assert.Equal (2, layoutCompleteCount);
 
         superView.LayoutSubviews ();
         Assert.Equal (1, borderLayoutStartedCount);
         Assert.Equal (1, borderLayoutCompleteCount);
-        Assert.Equal (1, layoutStartedCount);
-        Assert.Equal (1, layoutCompleteCount);
+        Assert.Equal (3, layoutStartedCount);
+        Assert.Equal (3, layoutCompleteCount);
 
         superView.SetNeedsLayout ();
         superView.LayoutSubviews ();
         Assert.Equal (1, borderLayoutStartedCount);
         Assert.Equal (1, borderLayoutCompleteCount);
-        Assert.Equal (2, layoutStartedCount);
-        Assert.Equal (2, layoutCompleteCount);
+        Assert.Equal (4, layoutStartedCount);
+        Assert.Equal (4, layoutCompleteCount);
 
         superView.Dispose ();
     }
@@ -317,8 +317,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_X_PosAbsolute_Layout_Is_Implicit ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.X);
 
         v.X = 1;
         Assert.False (v.NeedsLayout);
@@ -346,8 +344,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_X_Non_PosAbsolute_Explicit_Layout_Required ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.X);
 
         v.X = Pos.Center ();
         Assert.True (v.NeedsLayout);
@@ -379,8 +375,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Y_PosAbsolute_Layout_Is_Implicit ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Y);
 
         v.Y = 1;
         Assert.False (v.NeedsLayout);
@@ -408,8 +402,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Y_Non_PosAbsolute_Explicit_Layout_Required ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Y);
 
         v.Y = Pos.Center ();
         Assert.True (v.NeedsLayout);
@@ -441,8 +433,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Width_DimAbsolute_Layout_Is_Implicit ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Width);
 
         v.Width = 1;
         Assert.False (v.NeedsLayout);
@@ -470,8 +460,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Width_Non_DimAbsolute_Explicit_Layout_Required ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Width);
 
         v.Width = Dim.Auto();
         Assert.True (v.NeedsLayout);
@@ -498,8 +486,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Height_DimAbsolute_Layout_Is_Implicit ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Height);
 
         v.Height = 1;
         Assert.False (v.NeedsLayout);
@@ -527,8 +513,6 @@ public class SetLayoutTests (ITestOutputHelper output)
     public void Set_Height_Non_DimAbsolute_Explicit_Layout_Required ()
     {
         var v = new View ();
-        Assert.False (v.NeedsLayout);
-        Assert.Equal (0, v.Frame.Height);
 
         v.Height = Dim.Auto ();
         Assert.True (v.NeedsLayout);

+ 1 - 0
UnitTests/Views/MenuBarTests.cs

@@ -412,6 +412,7 @@ public class MenuBarTests (ITestOutputHelper output)
                                         new () { Position = new (0, 2), Flags = MouseFlags.Button1Clicked, View = top.Subviews [1] }
                                        )
                     );
+        top.Subviews [1].Layout();
         top.Subviews [1].Draw ();
 
         TestHelpers.AssertDriverAttributesAre (