Przeglądaj źródła

Adjusted shadow

Tig 1 rok temu
rodzic
commit
8c82881ca2

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

@@ -1,4 +1,6 @@
 #nullable enable
+using static Unix.Terminal.Curses;
+
 namespace Terminal.Gui;
 
 /// <summary>The Margin for a <see cref="View"/>.</summary>
@@ -25,10 +27,10 @@ public class Margin : Adornment
     private void Margin_LayoutStarted (object? sender, LayoutEventArgs e)
     {
         // Adjust the shadow such that it is drawn aligned with the Border
-        if (_shadow && _rightShadow is {} && _bottomShadow is {})
+        if (_shadow && _rightShadow is { } && _bottomShadow is { })
         {
-            _rightShadow.Y = Parent.Border.Thickness.Top - (Parent.Border.Thickness.Top > 2 && Parent.Border.ShowTitle ? 1 : 0);
-            _bottomShadow.X = Parent.Border.Thickness.Left;
+            _rightShadow.Y = Parent.Border.Thickness.Top > 0 ? Parent.Border.Thickness.Top - (Parent.Border.Thickness.Top > 2 && Parent.Border.ShowTitle ? 1 : 0) : 1;
+            _bottomShadow.X = Parent.Border.Thickness.Left > 0 ? Parent.Border.Thickness.Left : 1;
         }
     }
 
@@ -73,6 +75,40 @@ public class Margin : Adornment
 
     }
 
+    public override void OnDrawContent (Rectangle viewport)
+    {
+        Rectangle screen = ViewportToScreen (viewport);
+        Attribute normalAttr = GetNormalColor ();
+        Driver.SetAttribute (normalAttr);
+
+        // This just draws/clears the thickness, not the insides.
+        if (Parent?.Shadow == true)
+        {
+            screen = Rectangle.Inflate (screen, -1, -1);
+        }
+        Thickness.Draw (screen, ToString ());
+
+        if (Subviews.Count > 0)
+        {
+            // Draw subviews
+            // TODO: Implement OnDrawSubviews (cancelable);
+            if (Subviews is { } && SubViewNeedsDisplay)
+            {
+                IEnumerable<View> subviewsNeedingDraw = Subviews.Where (
+                                                                        view => view.Visible
+                                                                                && (view.NeedsDisplay || view.SubViewNeedsDisplay || view.LayoutNeeded)
+                                                                       );
+                foreach (View view in subviewsNeedingDraw)
+                {
+                    if (view.LayoutNeeded)
+                    {
+                        view.LayoutSubviews ();
+                    }
+                    view.Draw ();
+                }
+            }
+        }
+    }
 
     /// <summary>
     ///     The color scheme for the Margin. If set to <see langword="null"/>, gets the <see cref="Adornment.Parent"/>'s
@@ -177,9 +213,9 @@ public class Margin : Adornment
 internal class ShadowView : View
 {
     // TODO: Add these to CM.Glyphs
-    private readonly char VERTICAL_START_GLYPH = '\u2596';
+    private readonly char VERTICAL_START_GLYPH = '\u258C'; // Half: '\u2596';
     private readonly char VERTICAL_GLYPH = '\u258C';
-    private readonly char HORIZONTAL_START_GLYPH = '\u259d';
+    private readonly char HORIZONTAL_START_GLYPH = '\u2580'; // Half: '\u259d';
     private readonly char HORIZONTAL_GLYPH = '\u2580';
     private readonly char HORIZONTAL_END_GLYPH = '\u2598';
 

+ 3 - 2
UICatalog/Scenarios/ThreeD.cs

@@ -35,13 +35,14 @@ public class ThreeD : Scenario
             Height = Dim.Percent (30),
             Title = "Shadow Window",
             Arrangement = ViewArrangement.Movable,
+            Shadow = true
         };
 
         var buttonInWin = new Button
         {
             X = Pos.Center (),
             Y = Pos.Center (), Text = "Button in Window",
-            //Shadow = true
+            Shadow = true
         };
         win.Add (buttonInWin);
         app.Add (win);
@@ -50,10 +51,10 @@ public class ThreeD : Scenario
         {
             X = Pos.Right (editor) + 10,
             Y = Pos.Center (), Text = "Button",
+            Shadow = true
         };
         app.Add (button);
 
-
         Application.Run (app);
         app.Dispose ();