diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index ceafe6224..2d8d31918 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -2,8 +2,6 @@ public partial class View { - // The view-relative region that needs to be redrawn. Marked internal for unit tests. - internal Rectangle _needsDisplayRect = Rectangle.Empty; private ColorScheme _colorScheme; /// The color scheme for this view, if it is not defined, it returns the 's color scheme. @@ -32,6 +30,9 @@ public partial class View /// adds border lines to this LineCanvas. public LineCanvas LineCanvas { get; } = new (); + // The view-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. public bool NeedsDisplay { @@ -502,7 +503,7 @@ public partial class View /// redrawn will be the . /// /// The Bounds-relative region that needs to be redrawn. - public virtual void SetNeedsDisplay (Rectangle region) + public void SetNeedsDisplay (Rectangle region) { if (!IsInitialized) { @@ -523,11 +524,11 @@ public partial class View _needsDisplayRect = new (x, y, w, h); } - _superView?.SetSubViewNeedsDisplay (); + SuperView?.SetSubViewNeedsDisplay (); - Margin?.SetNeedsDisplay (Margin.Bounds); - Border?.SetNeedsDisplay (Border.Bounds); - Padding?.SetNeedsDisplay (Padding.Bounds); + Margin?.SetNeedsDisplay (); + Border?.SetNeedsDisplay (); + Padding?.SetNeedsDisplay (); foreach (View subview in Subviews) { @@ -541,19 +542,31 @@ public partial class View } } - /// Indicates that any Subviews (in the list) need to be repainted. + /// Sets to for this View and all Superviews. public void SetSubViewNeedsDisplay () { SubViewNeedsDisplay = true; - _superView?.SetSubViewNeedsDisplay (); + if (SuperView is { SubViewNeedsDisplay: false }) + { + SuperView.SetSubViewNeedsDisplay (); + } } /// Clears and . - protected virtual void ClearNeedsDisplay () + protected void ClearNeedsDisplay () { _needsDisplayRect = Rectangle.Empty; SubViewNeedsDisplay = false; + + Margin?.ClearNeedsDisplay (); + Border?.ClearNeedsDisplay (); + Padding?.ClearNeedsDisplay (); + + foreach (View subview in Subviews) + { + subview.ClearNeedsDisplay(); + } } // INTENT: Isn't this just intersection? It isn't used anyway. diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 3389c3b1d..2b49aaadb 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -32,7 +32,7 @@ public class Clipping : Scenario //scrollView.ShowVerticalScrollIndicator = true; //scrollView.ShowHorizontalScrollIndicator = true; - var embedded1 = new Window + var embedded1 = new View { Title = "1", X = 3, @@ -40,22 +40,26 @@ public class Clipping : Scenario Width = Dim.Fill (3), Height = Dim.Fill (3), ColorScheme = Colors.ColorSchemes ["Dialog"], - Id = "1" + Id = "1", + BorderStyle = LineStyle.Rounded, + Arrangement = ViewArrangement.Movable }; - var embedded2 = new Window + var embedded2 = new View { - Title = "1", + Title = "2", X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), ColorScheme = Colors.ColorSchemes ["Error"], - Id = "2" + Id = "2", + BorderStyle = LineStyle.Rounded, + Arrangement = ViewArrangement.Movable }; embedded1.Add (embedded2); - var embedded3 = new Window + var embedded3 = new View { Title = "3", X = 3, @@ -63,7 +67,9 @@ public class Clipping : Scenario Width = Dim.Fill (3), Height = Dim.Fill (3), ColorScheme = Colors.ColorSchemes ["TopLevel"], - Id = "3" + Id = "3", + BorderStyle = LineStyle.Rounded, + Arrangement = ViewArrangement.Movable }; var testButton = new Button { X = 2, Y = 2, Text = "click me" };