2
0
Tig 9 сар өмнө
parent
commit
2214d8c715

+ 12 - 10
Terminal.Gui/View/Adornment/Border.cs

@@ -72,7 +72,7 @@ public class Border : Adornment
     {
         if (IsInitialized)
         {
-            ShowHideDrawIndicator();
+            ShowHideDrawIndicator ();
         }
     }
 
@@ -87,6 +87,7 @@ public class Border : Adornment
                     X = 1,
                     Style = new SpinnerStyle.Dots2 (),
                     SpinDelay = 0,
+                    Visible = false
                 };
                 Add (DrawIndicator);
             }
@@ -99,6 +100,15 @@ public class Border : Adornment
         }
     }
 
+    internal void AdvanceDrawIndicator ()
+    {
+        if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator) && DrawIndicator is { })
+        {
+            DrawIndicator.AdvanceAnimation (false);
+            DrawIndicator.Render ();
+        }
+    }
+
 #if SUBVIEW_BASED_BORDER
     private Line _left;
 
@@ -164,15 +174,7 @@ public class Border : Adornment
     /// </summary>
     public override ColorScheme? ColorScheme
     {
-        get
-        {
-            if (base.ColorScheme is { })
-            {
-                return base.ColorScheme;
-            }
-
-            return Parent?.ColorScheme;
-        }
+        get => base.ColorScheme ?? Parent?.ColorScheme;
         set
         {
             base.ColorScheme = value;

+ 20 - 6
Terminal.Gui/View/Adornment/Margin.cs

@@ -40,7 +40,20 @@ public class Margin : Adornment
 
     // When the Parent is drawn, we cache the clip region so we can draw the Margin after all other Views
     // QUESTION: Why can't this just be the NeedsDisplay region?
-    internal Region? CachedClip { get; set; }
+    private Region? _cachedClip;
+
+    internal Region? GetCachedClip () { return _cachedClip; }
+
+    internal void ClearCachedClip () { _cachedClip = null; }
+
+    internal void CacheClip ()
+    {
+        if (Thickness != Thickness.Empty)
+        {
+            // PERFORMANCE: How expensive are these clones?
+            _cachedClip = GetClip ()?.Clone ();
+        }
+    }
 
     // PERFORMANCE: Margins are ALWAYS drawn. This may be an issue for apps that have a large number of views with shadows.
     /// <summary>
@@ -57,22 +70,22 @@ public class Margin : Adornment
         {
             var view = stack.Pop ();
 
-            if (view.Margin is { CachedClip: { } })
+            if (view.Margin?.GetCachedClip() != null)
             {
                 view.Margin.NeedsDraw = true;
                 Region? saved = GetClip ();
-                View.SetClip (view.Margin.CachedClip);
+                View.SetClip (view.Margin.GetCachedClip ());
                 view.Margin.Draw ();
                 View.SetClip (saved);
-                view.Margin.CachedClip = null;
+                view.Margin.ClearCachedClip ();
             }
 
+            view.NeedsDraw = false;
+
             foreach (var subview in view.Subviews)
             {
                 stack.Push (subview);
             }
-
-            view.NeedsDraw = false;
         }
 
         return true;
@@ -297,4 +310,5 @@ public class Margin : Adornment
     }
 
     #endregion Shadow
+
 }

+ 4 - 11
Terminal.Gui/View/Adornment/Padding.cs

@@ -1,4 +1,5 @@
-namespace Terminal.Gui;
+#nullable enable
+namespace Terminal.Gui;
 
 /// <summary>The Padding for a <see cref="View"/>. Accessed via <see cref="View.Padding"/></summary>
 /// <remarks>
@@ -21,17 +22,9 @@ public class Padding : Adornment
     ///     The color scheme for the Padding. If set to <see langword="null"/>, gets the <see cref="Adornment.Parent"/>
     ///     scheme. color scheme.
     /// </summary>
-    public override ColorScheme ColorScheme
+    public override ColorScheme? ColorScheme
     {
-        get
-        {
-            if (base.ColorScheme is { })
-            {
-                return base.ColorScheme;
-            }
-
-            return Parent?.ColorScheme;
-        }
+        get => base.ColorScheme ?? Parent?.ColorScheme;
         set
         {
             base.ColorScheme = value;

+ 16 - 15
Terminal.Gui/View/Adornment/ShadowView.cs

@@ -14,26 +14,27 @@ internal class ShadowView : View
     /// <inheritdoc/>
     public override Attribute GetNormalColor ()
     {
-        if (SuperView is Adornment adornment)
+        if (SuperView is not Adornment adornment)
         {
-            var attr = Attribute.Default;
+            return base.GetNormalColor ();
+        }
 
-            if (adornment.Parent?.SuperView is { })
-            {
-                attr = adornment.Parent.SuperView.GetNormalColor ();
-            }
-            else if (Application.Top is { })
-            {
-                attr = Application.Top.GetNormalColor ();
-            }
+        var attr = Attribute.Default;
 
-            return new (
-                        new Attribute (
-                                       ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
-                                       ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor ()));
+        if (adornment.Parent?.SuperView is { })
+        {
+            attr = adornment.Parent.SuperView.GetNormalColor ();
+        }
+        else if (Application.Top is { })
+        {
+            attr = Application.Top.GetNormalColor ();
         }
 
-        return base.GetNormalColor ();
+        return new (
+                    new Attribute (
+                                   ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
+                                   ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor ()));
+
     }
 
     /// <inheritdoc />

+ 14 - 35
Terminal.Gui/View/View.Attribute.cs

@@ -13,29 +13,23 @@ public partial class View
     /// <summary>The color scheme for this view, if it is not defined, it returns the <see cref="SuperView"/>'s color scheme.</summary>
     public virtual ColorScheme? ColorScheme
     {
-        get
-        {
-            if (_colorScheme is null)
-            {
-                return SuperView?.ColorScheme;
-            }
-
-            return _colorScheme;
-        }
+        get => _colorScheme ?? SuperView?.ColorScheme;
         set
         {
-            if (_colorScheme != value)
+            if (_colorScheme == value)
             {
-                _colorScheme = value;
+                return;
+            }
 
-                // BUGBUG: This should be in Border.cs somehow
-                if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { })
-                {
-                    Border.ColorScheme = _colorScheme;
-                }
+            _colorScheme = value;
 
-                SetNeedsDraw ();
+            // BUGBUG: This should be in Border.cs somehow
+            if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { })
+            {
+                Border.ColorScheme = _colorScheme;
             }
+
+            SetNeedsDraw ();
         }
     }
 
@@ -47,12 +41,7 @@ public partial class View
     /// </returns>
     public virtual Attribute GetFocusColor ()
     {
-        ColorScheme? cs = ColorScheme;
-
-        if (cs is null)
-        {
-            cs = new ();
-        }
+        ColorScheme? cs = ColorScheme ?? new ();
 
         return Enabled ? GetColor (cs.Focus) : cs.Disabled;
     }
@@ -78,12 +67,7 @@ public partial class View
     /// </returns>
     public virtual Attribute GetHotNormalColor ()
     {
-        ColorScheme? cs = ColorScheme;
-
-        if (cs is null)
-        {
-            cs = new ();
-        }
+        ColorScheme? cs = ColorScheme ?? new ();
 
         return Enabled ? GetColor (cs.HotNormal) : cs.Disabled;
     }
@@ -96,12 +80,7 @@ public partial class View
     /// </returns>
     public virtual Attribute GetNormalColor ()
     {
-        ColorScheme? cs = ColorScheme;
-
-        if (cs is null)
-        {
-            cs = new ();
-        }
+        ColorScheme? cs = ColorScheme ?? new ();
 
         Attribute disabled = new (cs.Disabled.Foreground, cs.Disabled.Background);
 

+ 40 - 20
Terminal.Gui/View/View.Drawing.cs

@@ -64,7 +64,6 @@ public partial class View // Drawing APIs
             if (SubViewNeedsDraw)
             {
                 DoSetAttribute ();
-
                 DoDrawSubviews ();
             }
 
@@ -84,22 +83,14 @@ public partial class View // Drawing APIs
 
             DoDrawBorderAndPaddingSubViews ();
 
-            if (Border is { Diagnostics: ViewDiagnosticFlags.DrawIndicator, DrawIndicator: { } })
-            {
-                Border.DrawIndicator.AdvanceAnimation (false);
-                Border.DrawIndicator.Render ();
-            }
+            Border?.AdvanceDrawIndicator ();
 
             ClearNeedsDraw ();
         }
 
         // This causes the Margin to be drawn in a second pass
         // PERFORMANCE: If there is a Margin, it will be redrawn each iteration of the main loop.
-        if (Margin is { } && Margin?.Thickness != Thickness.Empty)
-        {
-            // PERFORMANCE: How expensive are these clones?
-            Margin!.CachedClip = GetClip ()?.Clone ();
-        }
+        Margin?.CacheClip ();
 
         // We're done drawing
         DoDrawComplete ();
@@ -622,7 +613,7 @@ public partial class View // Drawing APIs
     public bool NeedsDraw
     {
         // TODO: Figure out if we can decouple NeedsDraw from NeedsLayout. This is a temporary fix.
-        get => _needsDrawRect != Rectangle.Empty || NeedsLayout;
+        get => Visible && (_needsDrawRect != Rectangle.Empty || NeedsLayout);
         set
         {
             if (value)
@@ -636,8 +627,22 @@ public partial class View // Drawing APIs
         }
     }
 
+    private bool _subViewNeedsDraw;
+
     /// <summary>Gets whether any Subviews need to be redrawn.</summary>
-    public bool SubViewNeedsDraw { get; private set; }
+    public bool SubViewNeedsDraw
+    {
+        get => _subViewNeedsDraw;
+        private set
+        {
+            //if (!Visible)
+            //{
+            //    _subViewNeedsDraw = false;
+            //    return;
+            //}
+            _subViewNeedsDraw = value;
+        }
+    }
 
     /// <summary>Sets that the <see cref="Viewport"/> of this View needs to be redrawn.</summary>
     /// <remarks>
@@ -648,7 +653,7 @@ public partial class View // Drawing APIs
     {
         Rectangle viewport = Viewport;
 
-        if (_needsDrawRect != Rectangle.Empty && viewport.IsEmpty)
+        if (/*!Visible || */(_needsDrawRect != Rectangle.Empty && viewport.IsEmpty))
         {
             // This handles the case where the view has not been initialized yet
             return;
@@ -670,6 +675,10 @@ public partial class View // Drawing APIs
     /// <param name="viewPortRelativeRegion">The <see cref="Viewport"/>relative region that needs to be redrawn.</param>
     public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
     {
+        //if (!Visible)
+        //{
+        //    return;
+        //}
         if (_needsDrawRect.IsEmpty)
         {
             _needsDrawRect = viewPortRelativeRegion;
@@ -683,10 +692,10 @@ public partial class View // Drawing APIs
             _needsDrawRect = new (x, y, w, h);
         }
 
-        if (Margin is { } && Margin.Thickness != Thickness.Empty)
-        {
-            Margin?.SetNeedsDraw ();
-        }
+        //if (Margin is { } && Margin.Thickness != Thickness.Empty)
+        //{
+        //    Margin?.SetNeedsDraw ();
+        //}
 
         if (Border is { } && Border.Thickness != Thickness.Empty)
         {
@@ -700,7 +709,7 @@ public partial class View // Drawing APIs
 
         SuperView?.SetSubViewNeedsDraw ();
 
-        if (this is Adornment adornment)
+        if (this is Adornment adornment /*and (Gui.Padding or Gui.Border)*/)
         {
             adornment.Parent?.SetSubViewNeedsDraw ();
         }
@@ -720,9 +729,15 @@ public partial class View // Drawing APIs
     /// <summary>Sets <see cref="SubViewNeedsDraw"/> to <see langword="true"/> for this View and all Superviews.</summary>
     public void SetSubViewNeedsDraw ()
     {
+        //if (!Visible)
+        //{
+        //    SubViewNeedsDraw = false;
+        //    return;
+        //}
+
         SubViewNeedsDraw = true;
 
-        if (this is Adornment adornment)
+        if (this is Adornment adornment/* and (Gui.Padding or Gui.Border)*/)
         {
             adornment.Parent?.SetSubViewNeedsDraw ();
         }
@@ -758,6 +773,11 @@ public partial class View // Drawing APIs
         {
             subview.ClearNeedsDraw ();
         }
+
+        if (SuperView is { })
+        {
+            SuperView.SubViewNeedsDraw = false;
+        }
     }
 
     #endregion NeedsDraw

+ 2 - 2
Terminal.Gui/Views/Dialog.cs

@@ -89,13 +89,13 @@ public class Dialog : Window
     /// <inheritdoc />
     public override Attribute GetNormalColor ()
     {
-        return ColorScheme.Normal;
+        return ColorScheme!.Normal;
     }
 
     /// <inheritdoc />
     public override Attribute GetFocusColor ()
     {
-        return ColorScheme.Normal;
+        return ColorScheme!.Normal;
     }
 
     private bool _canceled;

+ 26 - 50
Terminal.Gui/Views/ProgressBar.cs

@@ -1,4 +1,5 @@
-namespace Terminal.Gui;
+#nullable enable
+namespace Terminal.Gui;
 
 /// <summary>Specifies the style that a <see cref="ProgressBar"/> uses to indicate the progress of an operation.</summary>
 public enum ProgressBarStyle
@@ -37,30 +38,29 @@ public enum ProgressBarFormat
 /// </remarks>
 public class ProgressBar : View, IDesignable
 {
-    private int [] _activityPos;
-    private bool _bidirectionalMarquee = true;
+    private int []? _activityPos;
     private int _delta;
     private float _fraction;
     private bool _isActivity;
     private ProgressBarStyle _progressBarStyle = ProgressBarStyle.Blocks;
-    private ProgressBarFormat _progressBarFormat = ProgressBarFormat.Simple;
-    private Rune _segmentCharacter = Glyphs.BlocksMeterSegment;
 
     /// <summary>
     ///     Initializes a new instance of the <see cref="ProgressBar"/> class, starts in percentage mode and uses relative
     ///     layout.
     /// </summary>
-    public ProgressBar () { SetInitialProperties (); }
+    public ProgressBar ()
+    {
+        Width = Dim.Auto (DimAutoStyle.Content);
+        Height = Dim.Auto (DimAutoStyle.Content, 1);
+        CanFocus = false;
+        _fraction = 0;
+    }
 
     /// <summary>
     ///     Specifies if the <see cref="ProgressBarStyle.MarqueeBlocks"/> or the
     ///     <see cref="ProgressBarStyle.MarqueeContinuous"/> styles is unidirectional or bidirectional.
     /// </summary>
-    public bool BidirectionalMarquee
-    {
-        get => _bidirectionalMarquee;
-        set => _bidirectionalMarquee = value;
-    }
+    public bool BidirectionalMarquee { get; set; } = true;
 
     /// <summary>Gets or sets the <see cref="ProgressBar"/> fraction to display, must be a value between 0 and 1.</summary>
     /// <value>The fraction representing the progress.</value>
@@ -76,11 +76,7 @@ public class ProgressBar : View, IDesignable
     }
 
     /// <summary>Specifies the format that a <see cref="ProgressBar"/> uses to indicate the visual presentation.</summary>
-    public ProgressBarFormat ProgressBarFormat
-    {
-        get => _progressBarFormat;
-        set => _progressBarFormat = value;
-    }
+    public ProgressBarFormat ProgressBarFormat { get; set; } = ProgressBarFormat.Simple;
 
     /// <summary>Gets/Sets the progress bar style based on the <see cref="Terminal.Gui.ProgressBarStyle"/></summary>
     public ProgressBarStyle ProgressBarStyle
@@ -109,16 +105,13 @@ public class ProgressBar : View, IDesignable
 
                     break;
             }
+
             SetNeedsDraw ();
         }
     }
 
     /// <summary>Segment indicator for meter views.</summary>
-    public Rune SegmentCharacter
-    {
-        get => _segmentCharacter;
-        set => _segmentCharacter = value;
-    }
+    public Rune SegmentCharacter { get; set; } = Glyphs.BlocksMeterSegment;
 
     /// <summary>
     ///     Gets or sets the text displayed on the progress bar. If set to an empty string and
@@ -130,8 +123,7 @@ public class ProgressBar : View, IDesignable
         get => string.IsNullOrEmpty (base.Text) ? $"{_fraction * 100:F0}%" : base.Text;
         set
         {
-            if (ProgressBarStyle == ProgressBarStyle.MarqueeBlocks
-                || ProgressBarStyle == ProgressBarStyle.MarqueeContinuous)
+            if (ProgressBarStyle is ProgressBarStyle.MarqueeBlocks or ProgressBarStyle.MarqueeContinuous)
             {
                 base.Text = value;
             }
@@ -178,19 +170,19 @@ public class ProgressBar : View, IDesignable
         if (ProgressBarFormat != ProgressBarFormat.Simple && !_isActivity)
         {
             var tf = new TextFormatter { Alignment = Alignment.Center, Text = Text };
-            var attr = new Attribute (ColorScheme.HotNormal.Foreground, ColorScheme.HotNormal.Background);
+            var attr = new Attribute (ColorScheme!.HotNormal.Foreground, ColorScheme.HotNormal.Background);
 
             if (_fraction > .5)
             {
-                attr = new Attribute (ColorScheme.HotNormal.Background, ColorScheme.HotNormal.Foreground);
+                attr = new (ColorScheme.HotNormal.Background, ColorScheme.HotNormal.Foreground);
             }
 
             tf.Draw (
-                      ViewportToScreen (Viewport),
-                      attr,
-                      ColorScheme.Normal,
-                      SuperView?.ViewportToScreen (SuperView.Viewport) ?? default (Rectangle)
-                     );
+                     ViewportToScreen (Viewport),
+                     attr,
+                     ColorScheme.Normal,
+                     SuperView?.ViewportToScreen (SuperView.Viewport) ?? default (Rectangle)
+                    );
         }
 
         return true;
@@ -236,7 +228,7 @@ public class ProgressBar : View, IDesignable
             }
             else if (_activityPos [0] >= Viewport.Width)
             {
-                if (_bidirectionalMarquee)
+                if (BidirectionalMarquee)
                 {
                     for (var i = 0; i < _activityPos.Length; i++)
                     {
@@ -265,29 +257,13 @@ public class ProgressBar : View, IDesignable
         }
     }
 
-    private void ProgressBar_Initialized (object sender, EventArgs e)
-    {
-        //ColorScheme = new ColorScheme (ColorScheme ?? SuperView?.ColorScheme ?? Colors.ColorSchemes ["Base"])
-        //{
-        //    HotNormal = new Attribute (Color.BrightGreen, Color.Gray)
-        //};
-    }
-
-    private void SetInitialProperties ()
-    {
-        Width = Dim.Auto (DimAutoStyle.Content);
-        Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 1);
-        CanFocus = false;
-        _fraction = 0;
-        Initialized += ProgressBar_Initialized;
-    }
-
-    /// <inheritdoc />
+    /// <inheritdoc/>
     public bool EnableForDesign ()
     {
         Width = Dim.Fill ();
-        Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1);
+        Height = Dim.Auto (DimAutoStyle.Text, 1);
         Fraction = 0.75f;
+
         return true;
     }
 }

+ 9 - 6
Terminal.Gui/Views/Shortcut.cs

@@ -727,12 +727,6 @@ public class Shortcut : View, IOrientation, IDesignable
     /// </summary>
     internal void SetColors (bool highlight = false)
     {
-        // Border should match superview.
-        if (Border is { })
-        {
-            // Border.ColorScheme = SuperView?.ColorScheme;
-        }
-
         if (HasFocus || highlight)
         {
             if (_nonFocusColorScheme is null)
@@ -779,6 +773,15 @@ public class Shortcut : View, IOrientation, IDesignable
         {
             CommandView.Margin.ColorScheme = base.ColorScheme;
         }
+        if (HelpView.Margin is { })
+        {
+            HelpView.Margin.ColorScheme = base.ColorScheme;
+        }
+
+        if (KeyView.Margin is { })
+        {
+            KeyView.Margin.ColorScheme = base.ColorScheme;
+        }
     }
 
     /// <inheritdoc/>

+ 1 - 1
UICatalog/Scenarios/Editors/AdornmentEditor.cs

@@ -61,7 +61,7 @@ public class AdornmentEditor : EditorBase
                 _adornment.Initialized += (sender, args) =>
                                           {
                                               ColorScheme? cs = _adornment.ColorScheme;
-                                              _foregroundColorPicker.SelectedColor = cs.Normal.Foreground.GetClosestNamedColor16 ();
+                                              _foregroundColorPicker.SelectedColor = cs!.Normal.Foreground.GetClosestNamedColor16 ();
                                               _backgroundColorPicker.SelectedColor = cs.Normal.Background.GetClosestNamedColor16 ();
                                           };
             }

+ 1 - 1
UICatalog/Scenarios/Editors/EditorBase.cs

@@ -28,7 +28,7 @@ public abstract class EditorBase : View
 
         void OnInitialized (object sender, EventArgs e)
         {
-            Border.Add (ExpanderButton!);
+            Border?.Add (ExpanderButton!);
 
             Application.MouseEvent += ApplicationOnMouseEvent;
             Application.Navigation!.FocusedChanged += NavigationOnFocusedChanged;