浏览代码

simplified BoundsToScreen leveraging frameToScreen

Tig 1 年之前
父节点
当前提交
bdc87a4005
共有 2 个文件被更改,包括 5 次插入24 次删除
  1. 0 14
      Terminal.Gui/View/Adornment/Adornment.cs
  2. 5 10
      Terminal.Gui/View/Layout/ViewLayout.cs

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

@@ -82,20 +82,6 @@ public class Adornment : View
         }
     }
 
-    /// <inheritdoc/>
-    public override Rectangle BoundsToScreen (Rectangle bounds)
-    {
-        // Adornments are *Children* of a View, not SubViews. Thus View.BoundsToScreen will not work.
-        // To get the screen-relative coordinates of a Adornment, we need to know who
-        // the Parent is
-        Rectangle parentFrame = Parent?.Frame ?? Frame;
-        bounds.Offset (parentFrame.X, parentFrame.Y);
-
-        // We now have rcol/rrow in coordinates relative to our View's SuperView. If our View's SuperView has
-        // a SuperView, keep going...
-        return Parent?.SuperView?.BoundsToScreen (bounds) ?? bounds;
-    }
-
     /// <inheritdoc/>
     public override Rectangle FrameToScreen ()
     {

+ 5 - 10
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -499,21 +499,16 @@ public partial class View
     public event EventHandler Initialized;
 
     /// <summary>Converts a <see cref="Bounds"/>-relative rectangle to a screen-relative rectangle.</summary>
-    public virtual Rectangle BoundsToScreen (Rectangle bounds)
+    public Rectangle BoundsToScreen (Rectangle bounds)
     {
+        // Translate bounds to Frame (our SuperView's Bounds-relative coordinates)
         Point boundsOffset = GetBoundsOffset ();
         bounds.Offset(Frame.X + boundsOffset.X, Frame.Y + boundsOffset.Y);
 
-        View super = SuperView;
-
-        while (super is { })
-        {
-            boundsOffset = super.GetBoundsOffset ();
-            bounds.Offset(super.Frame.X + boundsOffset.X, super.Frame.Y + boundsOffset.Y);
-            super = super.SuperView;
-        }
+        Rectangle screen = FrameToScreen ();
+        screen.Offset (boundsOffset.X + bounds.X, boundsOffset.Y + bounds.Y);
 
-        return bounds;
+        return screen;
     }
 
 #nullable enable