Browse Source

DimAuto -> public

Tig 1 year ago
parent
commit
c26e62f709

+ 30 - 24
Terminal.Gui/View/Layout/Dim.cs

@@ -360,7 +360,7 @@ public class DimAbsolute (int size) : Dim
 }
 }
 
 
 /// <summary>
 /// <summary>
-///     A <see cref="Dim"/> object that automatically sizes the view to fit all the view's SubViews and/or Text.
+///     Represents a dimension that automatically sizes the view to fit all the view's Content, SubViews, and/or Text.
 /// </summary>
 /// </summary>
 /// <remarks>
 /// <remarks>
 ///     <para>
 ///     <para>
@@ -374,34 +374,32 @@ public class DimAbsolute (int size) : Dim
 /// <param name="maximumContentDim">The maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED.</param>
 /// <param name="maximumContentDim">The maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED.</param>
 public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumContentDim) : Dim
 public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumContentDim) : Dim
 {
 {
-    internal readonly Dim _minContentDim = minimumContentDim;
-    internal readonly Dim _maxContentDim = maximumContentDim;
-    internal readonly DimAutoStyle _style = style;
-    internal int _size;
-
-    /// <inheritdoc/>
-    public override bool Equals (object other)
-    {
-        return other is DimAuto auto && auto._minContentDim == _minContentDim && auto._maxContentDim == _maxContentDim && auto._style == _style;
-    }
+    /// <summary>
+    /// Gets the minimum dimension the View's ContentSize will be constrained to.
+    /// </summary>
+    public Dim MinimumContentDim { get; } = minimumContentDim;
 
 
-    /// <inheritdoc/>
-    public override int GetHashCode () { return HashCode.Combine (base.GetHashCode (), _minContentDim, _maxContentDim, _style); }
+    /// <summary>
+    /// Gets the maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED.
+    /// </summary>
+    public Dim MaximumContentDim { get; } = maximumContentDim;
 
 
-    /// <inheritdoc/>
-    public override string ToString () { return $"Auto({_style},{_minContentDim},{_maxContentDim})"; }
+    /// <summary>
+    /// Gets the style of the DimAuto.
+    /// </summary>
+    public DimAutoStyle Style { get; } = style;
 
 
     internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension)
     internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension)
     {
     {
         if (us == null)
         if (us == null)
         {
         {
-            return _maxContentDim?.Anchor (0) ?? 0;
+            return MaximumContentDim?.Anchor (0) ?? 0;
         }
         }
 
 
         var textSize = 0;
         var textSize = 0;
         var subviewsSize = 0;
         var subviewsSize = 0;
 
 
-        int autoMin = _minContentDim?.Anchor (superviewContentSize) ?? 0;
+        int autoMin = MinimumContentDim?.Anchor (superviewContentSize) ?? 0;
 
 
         if (superviewContentSize < autoMin)
         if (superviewContentSize < autoMin)
         {
         {
@@ -410,12 +408,12 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
             return superviewContentSize;
             return superviewContentSize;
         }
         }
 
 
-        if (_style.HasFlag (DimAutoStyle.Text))
+        if (Style.HasFlag (DimAutoStyle.Text))
         {
         {
             textSize = int.Max (autoMin, dimension == Dimension.Width ? us.TextFormatter.Size.Width : us.TextFormatter.Size.Height);
             textSize = int.Max (autoMin, dimension == Dimension.Width ? us.TextFormatter.Size.Width : us.TextFormatter.Size.Height);
         }
         }
 
 
-        if (_style.HasFlag (DimAutoStyle.Content))
+        if (Style.HasFlag (DimAutoStyle.Content))
         {
         {
             if (us._contentSize is { })
             if (us._contentSize is { })
             {
             {
@@ -473,18 +471,26 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
         }
         }
 
 
         // If max: is set, clamp the return - BUGBUG: Not tested
         // If max: is set, clamp the return - BUGBUG: Not tested
-        return int.Min (max, _maxContentDim?.Anchor (superviewContentSize) ?? superviewContentSize);
+        return int.Min (max, MaximumContentDim?.Anchor (superviewContentSize) ?? superviewContentSize);
     }
     }
 
 
-    /// <summary>
-    ///     Diagnostics API to determine if this Dim object references other views.
-    /// </summary>
-    /// <returns></returns>
     internal override bool ReferencesOtherViews ()
     internal override bool ReferencesOtherViews ()
     {
     {
         // BUGBUG: This is not correct. _contentSize may be null.
         // BUGBUG: This is not correct. _contentSize may be null.
         return false; //_style.HasFlag (DimAutoStyle.Content);
         return false; //_style.HasFlag (DimAutoStyle.Content);
     }
     }
+
+    /// <inheritdoc/>
+    public override bool Equals (object other)
+    {
+        return other is DimAuto auto && auto.MinimumContentDim == MinimumContentDim && auto.MaximumContentDim == MaximumContentDim && auto.Style == Style;
+    }
+
+    /// <inheritdoc/>
+    public override int GetHashCode () { return HashCode.Combine (base.GetHashCode (), MinimumContentDim, MaximumContentDim, Style); }
+
+    /// <inheritdoc/>
+    public override string ToString () { return $"Auto({Style},{MinimumContentDim},{MaximumContentDim})"; }
 }
 }
 
 
 internal class DimCombine (bool add, Dim left, Dim right) : Dim
 internal class DimCombine (bool add, Dim left, Dim right) : Dim

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

@@ -1083,13 +1083,13 @@ public partial class View
         // Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions.
         // Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions.
         foreach (View view in Subviews)
         foreach (View view in Subviews)
         {
         {
-            if (Width is DimAuto { _minContentDim: null })
+            if (Width is DimAuto { MinimumContentDim: null })
             {
             {
                 ThrowInvalid (view, view.Width, nameof (view.Width));
                 ThrowInvalid (view, view.Width, nameof (view.Width));
                 ThrowInvalid (view, view.X, nameof (view.X));
                 ThrowInvalid (view, view.X, nameof (view.X));
             }
             }
 
 
-            if (Height is DimAuto { _minContentDim: null })
+            if (Height is DimAuto { MinimumContentDim: null })
             {
             {
                 ThrowInvalid (view, view.Height, nameof (view.Height));
                 ThrowInvalid (view, view.Height, nameof (view.Height));
                 ThrowInvalid (view, view.Y, nameof (view.Y));
                 ThrowInvalid (view, view.Y, nameof (view.Y));

+ 4 - 4
Terminal.Gui/View/ViewText.cs

@@ -186,17 +186,17 @@ public partial class View
         // Use _width & _height instead of Width & Height to avoid debug spew
         // Use _width & _height instead of Width & Height to avoid debug spew
         DimAuto widthAuto = _width as DimAuto;
         DimAuto widthAuto = _width as DimAuto;
         DimAuto heightAuto = _height as DimAuto;
         DimAuto heightAuto = _height as DimAuto;
-        if ((widthAuto is { } && widthAuto._style.HasFlag (DimAutoStyle.Text))
-            || (heightAuto is { } && heightAuto._style.HasFlag (DimAutoStyle.Text)))
+        if ((widthAuto is { } && widthAuto.Style.HasFlag (DimAutoStyle.Text))
+            || (heightAuto is { } && heightAuto.Style.HasFlag (DimAutoStyle.Text)))
         {
         {
             size = TextFormatter.GetAutoSize ();
             size = TextFormatter.GetAutoSize ();
 
 
-            if (widthAuto is null || !widthAuto._style.HasFlag (DimAutoStyle.Text))
+            if (widthAuto is null || !widthAuto.Style.HasFlag (DimAutoStyle.Text))
             {
             {
                 size.Width = ContentSize.Width;
                 size.Width = ContentSize.Width;
             }
             }
 
 
-            if (heightAuto is null || !heightAuto._style.HasFlag (DimAutoStyle.Text))
+            if (heightAuto is null || !heightAuto.Style.HasFlag (DimAutoStyle.Text))
             {
             {
                 size.Height = ContentSize.Height;
                 size.Height = ContentSize.Height;
             }
             }