Browse Source

Simplified View.CrateAdornments; removed reflection

Tig 1 year ago
parent
commit
11c1be60b9
2 changed files with 10 additions and 36 deletions
  1. 5 5
      Terminal.Gui/View/Adornment/Adornment.cs
  2. 5 31
      Terminal.Gui/View/ViewAdornments.cs

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

@@ -94,11 +94,11 @@ public class Adornment : View
         set => throw new NotImplementedException ();
     }
 
-    internal override Adornment CreateAdornment (Type adornmentType)
-    {
-        /* Do nothing - Adornments do not have Adornments */
-        return null;
-    }
+    //internal override Adornment CreateAdornment (Type adornmentType)
+    //{
+    //    /* Do nothing - Adornments do not have Adornments */
+    //    return null;
+    //}
 
     internal override void LayoutAdornments ()
     {

+ 5 - 31
Terminal.Gui/View/ViewAdornments.cs

@@ -3,38 +3,13 @@ public partial class View
 {
     private void CreateAdornments ()
     {
-        Margin = CreateAdornment (typeof (Margin)) as Margin;
-        Border = CreateAdornment (typeof (Border)) as Border;
-        Padding = CreateAdornment (typeof (Padding)) as Padding;
-    }
-
-    // TODO: Move this to Adornment as a static factory method
-    /// <summary>
-    ///     This internal method is overridden by Adornment to do nothing to prevent recursion during View construction.
-    ///     And, because Adornments don't have Adornments. It's internal to support unit tests.
-    /// </summary>
-    /// <param name="adornmentType"></param>
-    /// <exception cref="ArgumentNullException"></exception>
-    /// <exception cref="ArgumentException"></exception>
-    internal virtual Adornment CreateAdornment (Type adornmentType)
-    {
-        void ThicknessChangedHandler (object sender, EventArgs e)
+        //// TODO: Move this to Adornment as a static factory method
+        if (this is not Adornment)
         {
-            if (IsInitialized)
-            {
-                LayoutAdornments ();
-            }
-
-            SetNeedsLayout ();
-            SetNeedsDisplay ();
+            Margin = new (this);
+            Border = new (this);
+            Padding = new (this);
         }
-
-        Adornment adornment;
-
-        adornment = Activator.CreateInstance (adornmentType, this) as Adornment;
-        adornment.ThicknessChanged += ThicknessChangedHandler;
-
-        return adornment;
     }
 
     private void BeginInitAdornments ()
@@ -50,7 +25,6 @@ public partial class View
         Border?.EndInit ();
         Padding?.EndInit ();
     }
-
     private void DisposeAdornments ()
     {
         Margin?.Dispose ();