Browse Source

Perf work

Tig 8 months ago
parent
commit
9fc9438f6c

+ 1 - 1
Terminal.Gui/View/Adornment/Adornment.cs

@@ -171,7 +171,7 @@ public class Adornment : View, IDesignable
         // This just draws/clears the thickness, not the insides.
         // This just draws/clears the thickness, not the insides.
         Thickness.Draw (ViewportToScreen (Viewport), Diagnostics, ToString ());
         Thickness.Draw (ViewportToScreen (Viewport), Diagnostics, ToString ());
 
 
-        //NeedsDraw = true;
+        NeedsDraw = true;
 
 
         return true;
         return true;
     }
     }

+ 2 - 1
Terminal.Gui/View/Adornment/Border.cs

@@ -68,6 +68,8 @@ public class Border : Adornment
         ThicknessChanged += OnThicknessChanged;
         ThicknessChanged += OnThicknessChanged;
     }
     }
 
 
+    // TODO: Move DrawIndicator out of Border and into View
+
     private void OnThicknessChanged (object? sender, EventArgs e)
     private void OnThicknessChanged (object? sender, EventArgs e)
     {
     {
         if (IsInitialized)
         if (IsInitialized)
@@ -75,7 +77,6 @@ public class Border : Adornment
             ShowHideDrawIndicator ();
             ShowHideDrawIndicator ();
         }
         }
     }
     }
-
     private void ShowHideDrawIndicator ()
     private void ShowHideDrawIndicator ()
     {
     {
         if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator) && Thickness != Thickness.Empty)
         if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator) && Thickness != Thickness.Empty)

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

@@ -149,6 +149,10 @@ public partial class View // Adornments
             }
             }
 
 
             LineStyle old = Border?.LineStyle ?? LineStyle.None;
             LineStyle old = Border?.LineStyle ?? LineStyle.None;
+
+            // It's tempting to try to optimize this by checking that old != value and returning.
+            // Do not.
+
             CancelEventArgs<LineStyle> e = new (ref old, ref value);
             CancelEventArgs<LineStyle> e = new (ref old, ref value);
 
 
             if (OnBorderStyleChanging (e) || e.Cancel)
             if (OnBorderStyleChanging (e) || e.Cancel)

+ 2 - 0
Terminal.Gui/View/View.Content.cs

@@ -308,6 +308,8 @@ public partial class View
             {
             {
                 _viewportLocation = viewport.Location;
                 _viewportLocation = viewport.Location;
                 SetNeedsLayout ();
                 SetNeedsLayout ();
+                //SetNeedsDraw();
+                //SetSubViewNeedsDraw();
             }
             }
 
 
             OnViewportChanged (new (IsInitialized ? Viewport : Rectangle.Empty, oldViewport));
             OnViewportChanged (new (IsInitialized ? Viewport : Rectangle.Empty, oldViewport));

+ 12 - 1
Terminal.Gui/View/View.Drawing.cs

@@ -5,6 +5,11 @@ namespace Terminal.Gui;
 
 
 public partial class View // Drawing APIs
 public partial class View // Drawing APIs
 {
 {
+    /// <summary>
+    ///     Draws a set of views.
+    /// </summary>
+    /// <param name="views">The peer views to draw.</param>
+    /// <param name="force">If <see langword="true"/>, <see cref="View.SetNeedsDraw()"/> will be called on each view to force it to be drawn.</param>
     internal static void Draw (IEnumerable<View> views, bool force)
     internal static void Draw (IEnumerable<View> views, bool force)
     {
     {
         IEnumerable<View> viewsArray = views as View [] ?? views.ToArray ();
         IEnumerable<View> viewsArray = views as View [] ?? views.ToArray ();
@@ -130,9 +135,14 @@ public partial class View // Drawing APIs
     {
     {
         if (Border?.Subviews is { } && Border.Thickness != Thickness.Empty)
         if (Border?.Subviews is { } && Border.Thickness != Thickness.Empty)
         {
         {
+            // PERFORMANCE: Get the check for DrawIndicator out of this somehow.
             foreach (View subview in Border.Subviews.Where (v => v.Visible || v.Id == "DrawIndicator"))
             foreach (View subview in Border.Subviews.Where (v => v.Visible || v.Id == "DrawIndicator"))
             {
             {
-                subview.SetNeedsDraw ();
+                if (subview.Id != "DrawIndicator")
+                {
+                    subview.SetNeedsDraw ();
+                }
+
                 LineCanvas.Exclude (new (subview.FrameToScreen()));
                 LineCanvas.Exclude (new (subview.FrameToScreen()));
             }
             }
 
 
@@ -759,6 +769,7 @@ public partial class View // Drawing APIs
             SuperView.SubViewNeedsDraw = false;
             SuperView.SubViewNeedsDraw = false;
         }
         }
 
 
+        // This ensures LineCanvas' get redrawn
         if (!SuperViewRendersLineCanvas)
         if (!SuperViewRendersLineCanvas)
         {
         {
             LineCanvas.Clear ();
             LineCanvas.Clear ();

+ 1 - 1
Terminal.Gui/View/View.Layout.cs

@@ -777,7 +777,7 @@ public partial class View // Layout APIs
         {
         {
             foreach (Toplevel tl in Application.TopLevels)
             foreach (Toplevel tl in Application.TopLevels)
             {
             {
-                tl.SetNeedsDraw ();
+               // tl.SetNeedsDraw ();
             }
             }
         }
         }
 
 

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

@@ -140,7 +140,7 @@ public class Bar : View, IOrientation, IDesignable
         set
         set
         {
         {
             _alignmentModes = value;
             _alignmentModes = value;
-            SetNeedsDraw ();
+            //SetNeedsDraw ();
             SetNeedsLayout ();
             SetNeedsLayout ();
         }
         }
     }
     }
@@ -168,7 +168,7 @@ public class Bar : View, IOrientation, IDesignable
             }
             }
         }
         }
 
 
-        SetNeedsDraw ();
+        //SetNeedsDraw ();
         SetNeedsLayout ();
         SetNeedsLayout ();
     }
     }
 
 
@@ -192,7 +192,7 @@ public class Bar : View, IOrientation, IDesignable
         if (toRemove is { })
         if (toRemove is { })
         {
         {
             Remove (toRemove);
             Remove (toRemove);
-            SetNeedsDraw ();
+            //SetNeedsDraw ();
             SetNeedsLayout ();
             SetNeedsLayout ();
         }
         }
 
 

+ 5 - 7
Terminal.Gui/Views/Shortcut.cs

@@ -97,8 +97,6 @@ public class Shortcut : View, IOrientation, IDesignable
         HighlightStyle = HighlightStyle.None;
         HighlightStyle = HighlightStyle.None;
         CanFocus = true;
         CanFocus = true;
 
 
-        SuperViewRendersLineCanvas = true;
-
         if (Border is { })
         if (Border is { })
         {
         {
             Border.Settings &= ~BorderSettings.Title;
             Border.Settings &= ~BorderSettings.Title;
@@ -655,11 +653,11 @@ public class Shortcut : View, IOrientation, IDesignable
             _minimumKeyTextSize = value;
             _minimumKeyTextSize = value;
             SetKeyViewDefaultLayout ();
             SetKeyViewDefaultLayout ();
 
 
-            // TODO: Prob not needed
-            CommandView.SetNeedsLayout ();
-            HelpView.SetNeedsLayout ();
-            KeyView.SetNeedsLayout ();
-            SetSubViewNeedsDraw ();
+            //// TODO: Prob not needed
+            //CommandView.SetNeedsLayout ();
+            //HelpView.SetNeedsLayout ();
+            //KeyView.SetNeedsLayout ();
+            //SetSubViewNeedsDraw ();
         }
         }
     }
     }
 
 

+ 20 - 6
Terminal.Gui/Views/TableView/TableView.cs

@@ -320,8 +320,13 @@ public class TableView : View, IDesignable
         //try to prevent this being set to an out of bounds column
         //try to prevent this being set to an out of bounds column
         set
         set
         {
         {
+            int prev = columnOffset;
             columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value));
             columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value));
-            SetNeedsDraw ();
+
+            if (prev != columnOffset)
+            {
+                SetNeedsDraw ();
+            }
         }
         }
     }
     }
 
 
@@ -358,7 +363,16 @@ public class TableView : View, IDesignable
     public int RowOffset
     public int RowOffset
     {
     {
         get => rowOffset;
         get => rowOffset;
-        set => rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value));
+        set
+        {
+            int prev = rowOffset;
+            rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value));
+
+            if (rowOffset != prev)
+            {
+                SetNeedsDraw ();
+            }
+        }
     }
     }
 
 
     /// <summary>The index of <see cref="DataTable.Columns"/> in <see cref="Table"/> that the user has currently selected</summary>
     /// <summary>The index of <see cref="DataTable.Columns"/> in <see cref="Table"/> that the user has currently selected</summary>
@@ -830,28 +844,28 @@ public class TableView : View, IDesignable
             case MouseFlags.WheeledDown:
             case MouseFlags.WheeledDown:
                 RowOffset++;
                 RowOffset++;
                 EnsureValidScrollOffsets ();
                 EnsureValidScrollOffsets ();
-                SetNeedsDraw ();
+                //SetNeedsDraw ();
 
 
                 return true;
                 return true;
 
 
             case MouseFlags.WheeledUp:
             case MouseFlags.WheeledUp:
                 RowOffset--;
                 RowOffset--;
                 EnsureValidScrollOffsets ();
                 EnsureValidScrollOffsets ();
-                SetNeedsDraw ();
+                //SetNeedsDraw ();
 
 
                 return true;
                 return true;
 
 
             case MouseFlags.WheeledRight:
             case MouseFlags.WheeledRight:
                 ColumnOffset++;
                 ColumnOffset++;
                 EnsureValidScrollOffsets ();
                 EnsureValidScrollOffsets ();
-                SetNeedsDraw ();
+                //SetNeedsDraw ();
 
 
                 return true;
                 return true;
 
 
             case MouseFlags.WheeledLeft:
             case MouseFlags.WheeledLeft:
                 ColumnOffset--;
                 ColumnOffset--;
                 EnsureValidScrollOffsets ();
                 EnsureValidScrollOffsets ();
-                SetNeedsDraw ();
+                //SetNeedsDraw ();
 
 
                 return true;
                 return true;
         }
         }

+ 5 - 5
UICatalog/UICatalog.cs

@@ -785,7 +785,7 @@ public class UICatalogApp
                                              {
                                              {
                                                  if (_statusBar.NeedsLayout)
                                                  if (_statusBar.NeedsLayout)
                                                  {
                                                  {
-                                                     throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
+                                                   //  throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
                                                  }
                                                  }
                                                  return _statusBar.Frame.Height;
                                                  return _statusBar.Frame.Height;
                                              })),
                                              })),
@@ -793,7 +793,7 @@ public class UICatalogApp
                 CanFocus = true,
                 CanFocus = true,
                 Title = "_Categories",
                 Title = "_Categories",
                 BorderStyle = LineStyle.Rounded,
                 BorderStyle = LineStyle.Rounded,
-                SuperViewRendersLineCanvas = true,
+                //SuperViewRendersLineCanvas = true,
                 Source = new ListWrapper<string> (_categories)
                 Source = new ListWrapper<string> (_categories)
             };
             };
             CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); };
             CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); };
@@ -804,14 +804,14 @@ public class UICatalogApp
             // category).
             // category).
             ScenarioList = new ()
             ScenarioList = new ()
             {
             {
-                X = Pos.Right (CategoryList) - 1,
+                X = Pos.Right (CategoryList),
                 Y = Pos.Bottom (menuBar),
                 Y = Pos.Bottom (menuBar),
                 Width = Dim.Fill (),
                 Width = Dim.Fill (),
                 Height = Dim.Fill (Dim.Func (() =>
                 Height = Dim.Fill (Dim.Func (() =>
                                              {
                                              {
                                                  if (_statusBar.NeedsLayout)
                                                  if (_statusBar.NeedsLayout)
                                                  {
                                                  {
-                                                     throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
+                                                    // throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
                                                  }
                                                  }
                                                  return _statusBar.Frame.Height;
                                                  return _statusBar.Frame.Height;
                                              })),
                                              })),
@@ -819,7 +819,7 @@ public class UICatalogApp
                 CanFocus = true,
                 CanFocus = true,
                 Title = "_Scenarios",
                 Title = "_Scenarios",
                 BorderStyle = CategoryList.BorderStyle,
                 BorderStyle = CategoryList.BorderStyle,
-                SuperViewRendersLineCanvas = true
+                //SuperViewRendersLineCanvas = true
             };
             };
 
 
             // TableView provides many options for table headers. For simplicity we turn all 
             // TableView provides many options for table headers. For simplicity we turn all