From 5a11a390ba28ea172fd42f60ee026da8383099d5 Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 24 Oct 2024 15:44:49 -0600 Subject: [PATCH] Code cleanup --- Terminal.Gui/View/View.Drawing.cs | 14 +++++++++++ UnitTests/View/Draw/NeedsDisplayTests.cs | 6 +++-- UnitTests/View/Layout/FrameTests.cs | 2 +- UnitTests/View/Layout/SetLayoutTests.cs | 32 ++++++------------------ UnitTests/Views/MenuBarTests.cs | 1 + 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Terminal.Gui/View/View.Drawing.cs b/Terminal.Gui/View/View.Drawing.cs index 5f31c64db..e8bc2ef9e 100644 --- a/Terminal.Gui/View/View.Drawing.cs +++ b/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; /// Gets or sets whether the view needs to be redrawn. + /// + /// + /// Will be if the property is or if + /// any part of the view's needs to be redrawn. + /// + /// + /// Setting has no effect on . + /// + /// public bool NeedsDisplay { + // TODO: Figure out if we can decouple NeedsDisplay from NeedsLayout. This is a temporary fix. get => _needsDisplayRect != Rectangle.Empty || NeedsLayout; set { diff --git a/UnitTests/View/Draw/NeedsDisplayTests.cs b/UnitTests/View/Draw/NeedsDisplayTests.cs index f57a4d36e..77887219c 100644 --- a/UnitTests/View/Draw/NeedsDisplayTests.cs +++ b/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); } diff --git a/UnitTests/View/Layout/FrameTests.cs b/UnitTests/View/Layout/FrameTests.cs index 18cdd4ba3..173409a0f 100644 --- a/UnitTests/View/Layout/FrameTests.cs +++ b/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; diff --git a/UnitTests/View/Layout/SetLayoutTests.cs b/UnitTests/View/Layout/SetLayoutTests.cs index 613e71729..4859957d6 100644 --- a/UnitTests/View/Layout/SetLayoutTests.cs +++ b/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); diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index 08177767a..e22749cc2 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/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 (