Browse Source

Added simpler adornments sceanario

Tig Kindel 1 year ago
parent
commit
ef8dc48838

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

@@ -95,6 +95,8 @@ public class Adornment : View
     /// <inheritdoc/>
     /// <inheritdoc/>
     public override void BoundsToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true)
     public override void BoundsToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true)
     {
     {
+        rcol = 0;
+        rrow = 0;
         // Adornments are *Children* of a View, not SubViews. Thus View.BoundsToScreen will not work.
         // 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
         // To get the screen-relative coordinates of a Adornment, we need to know who
         // the Parent is
         // the Parent is
@@ -102,7 +104,7 @@ public class Adornment : View
         rrow = row + parentFrame.Y;
         rrow = row + parentFrame.Y;
         rcol = col + parentFrame.X;
         rcol = col + parentFrame.X;
 
 
-        // We now have rcol/rrow in coordinates relative to our View's SuperView. If our View's SuperView has
+        // We now have rcol/rrow in coordinates relative to our Parent View's SuperView. If our Parent View's SuperView has
         // a SuperView, keep going...
         // a SuperView, keep going...
         Parent?.SuperView?.BoundsToScreen (rcol, rrow, out rcol, out rrow, clipped);
         Parent?.SuperView?.BoundsToScreen (rcol, rrow, out rcol, out rrow, clipped);
     }
     }
@@ -163,6 +165,11 @@ public class Adornment : View
             return;
             return;
         }
         }
 
 
+        if (Parent is Label)
+        {
+
+        }
+
         Rectangle screenBounds = BoundsToScreen (Frame);
         Rectangle screenBounds = BoundsToScreen (Frame);
 
 
         Attribute normalAttr = GetNormalColor ();
         Attribute normalAttr = GetNormalColor ();

+ 2 - 2
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -538,10 +538,10 @@ public partial class View
 
 
         while (super is { })
         while (super is { })
         {
         {
-            if (super is Adornment ador)
+            if (super is Adornment)
             {
             {
                 // TODO: Move this into Adornment somehow to remove coupling.
                 // TODO: Move this into Adornment somehow to remove coupling.
-                ador.BoundsToScreen (rx, ry, out rx, out ry);
+                super.BoundsToScreen (rx, ry, out rx, out ry);
             }
             }
 
 
             boundsOffset = super.GetBoundsOffset ();
             boundsOffset = super.GetBoundsOffset ();

+ 56 - 0
UICatalog/Scenarios/AdornmentExperiments.cs

@@ -0,0 +1,56 @@
+using Terminal.Gui;
+
+namespace UICatalog.Scenarios;
+
+[ScenarioMetadata ("Adornment Experiments", "Playground for Adornment experiments")]
+[ScenarioCategory ("Controls")]
+public class AdornmentExperiments : Scenario
+{
+    private ConsoleDriver.DiagnosticFlags _diagnosticFlags;
+
+    public override void Init ()
+    {
+        Application.Init ();
+        ConfigurationManager.Themes.Theme = Theme;
+        ConfigurationManager.Apply ();
+        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+
+        _diagnosticFlags = ConsoleDriver.Diagnostics;
+        ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.FramePadding;
+    }
+
+    private View _frameView;
+    public override void Setup ()
+    {
+        _frameView = new View ()
+        {
+            Title = "Frame View",
+            X = 0,
+            Y = 0,
+            Width = Dim.Percent(90),
+            Height = Dim.Percent (90),
+            CanFocus = true,
+        };
+        Application.Top.Add (_frameView);
+        _frameView.Initialized += FrameView_Initialized;
+
+        Application.Top.Closed += (s, e) => ConsoleDriver.Diagnostics = _diagnosticFlags;
+    }
+
+    private void FrameView_Initialized (object sender, System.EventArgs e)
+    {
+        _frameView.Border.Thickness = new (1, 1, 1, 1);
+        _frameView.Padding.Thickness = new (0, 10, 0, 0);
+        _frameView.Padding.ColorScheme = Colors.ColorSchemes ["Error"];
+
+        var label = new Label ()
+        {
+            Text = "In Padding",
+            X = Pos.Center (),
+            Y = 0,
+            BorderStyle = LineStyle.Dashed
+        };
+        _frameView.Padding.Add (label);
+    }
+
+}

+ 3 - 1
UICatalog/Scenarios/Adornments.cs

@@ -97,8 +97,10 @@ public class Adornments : Scenario
 
 
                                 var btnButtonInPadding = new Button { X = Pos.Center (), Y = 1, Text = "_Button in Padding" };
                                 var btnButtonInPadding = new Button { X = Pos.Center (), Y = 1, Text = "_Button in Padding" };
                                 btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
                                 btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
-                                //btnButtonInPadding.BorderStyle = LineStyle.Dashed;
+                                btnButtonInPadding.BorderStyle = LineStyle.Dashed;
+                                btnButtonInPadding.Border.Thickness = new (3,3,3,3);
                                 view.Padding.Add (btnButtonInPadding);
                                 view.Padding.Add (btnButtonInPadding);
+                                btnButtonInPadding.Border.CloseButton.Visible = true;
 
 
                                 view.Border.CloseButton.Visible = true;
                                 view.Border.CloseButton.Visible = true;
                                 view.Border.CloseButton.Accept += (s, e) =>
                                 view.Border.CloseButton.Accept += (s, e) =>