diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index b63175aa0..1734de200 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -1,4 +1,6 @@ #nullable enable +using static Unix.Terminal.Curses; + namespace Terminal.Gui; /// The Margin for a . @@ -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 subviewsNeedingDraw = Subviews.Where ( + view => view.Visible + && (view.NeedsDisplay || view.SubViewNeedsDisplay || view.LayoutNeeded) + ); + foreach (View view in subviewsNeedingDraw) + { + if (view.LayoutNeeded) + { + view.LayoutSubviews (); + } + view.Draw (); + } + } + } + } /// /// The color scheme for the Margin. If set to , gets the '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'; diff --git a/UICatalog/Scenarios/ThreeD.cs b/UICatalog/Scenarios/ThreeD.cs index 423c1e7dd..78b58b8f3 100644 --- a/UICatalog/Scenarios/ThreeD.cs +++ b/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 ();