diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs
index 94b5c6b12..005be7364 100644
--- a/Terminal.Gui/View/Layout/ViewLayout.cs
+++ b/Terminal.Gui/View/Layout/ViewLayout.cs
@@ -276,24 +276,6 @@ public partial class View
_height = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Height)} cannot be null");
- if (AutoSize)
- {
- Debug.WriteLine (@$"Must set AutoSize to false before setting {nameof (Height)}.");
- AutoSize = false;
- }
-
- //if (ValidatePosDim) {
- bool isValidNewAutoSize = AutoSize && IsValidAutoSizeHeight (_height);
-
- if (IsAdded && AutoSize && !isValidNewAutoSize)
- {
- Debug.WriteLine (
- @$"Must set AutoSize to false before setting the {nameof (Height)}."
- );
- AutoSize = false;
- }
-
- //}
OnResizeNeeded ();
}
}
@@ -334,19 +316,6 @@ public partial class View
_width = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Width)} cannot be null");
- if (AutoSize)
- {
- Debug.WriteLine ($@"Must set AutoSize to false before setting {nameof (Width)}.");
- AutoSize = false;
- }
-
- bool isValidNewAutoSize = AutoSize && IsValidAutoSizeWidth (_width);
-
- if (IsAdded && AutoSize && !isValidNewAutoSize)
- {
- Debug.WriteLine ($@"Must set AutoSize to false before setting {nameof (Width)}.");
- AutoSize = false;
- }
OnResizeNeeded ();
}
@@ -356,8 +325,6 @@ public partial class View
#region AutoSize
- private bool _autoSize;
-
///
/// Gets or sets a flag that determines whether the View will be automatically resized to fit the
/// within .
@@ -377,60 +344,24 @@ public partial class View
///
public virtual bool AutoSize
{
- get => _autoSize;
+ get => Height is Dim.DimAuto && Width is Dim.DimAuto;
set
{
- if (Width != Dim.Sized (0) && Height != Dim.Sized (0))
+ if (IsInitialized)
{
- Debug.WriteLine (
- $@"WARNING: {GetType ().Name} - Setting {nameof (AutoSize)} invalidates {nameof (Width)} and {nameof (Height)}."
- );
- }
+ Height = Dim.Auto (Dim.DimAutoStyle.Text);
+ Width = Dim.Auto (Dim.DimAutoStyle.Text);
- bool v = ResizeView (value);
- TextFormatter.AutoSize = v;
-
- if (_autoSize != v)
- {
- _autoSize = v;
- TextFormatter.NeedsFormat = true;
- UpdateTextFormatterText ();
- OnResizeNeeded ();
- }
- }
- }
-
-
- /// If is true, resizes the view.
- ///
- ///
- private bool ResizeView (bool autoSize)
- {
- if (!autoSize)
- {
- return false;
- }
-
- var boundsChanged = true;
- Size newFrameSize = GetTextAutoSize ();
-
- if (IsInitialized && newFrameSize != Frame.Size)
- {
- if (ValidatePosDim)
- {
- // BUGBUG: This ain't right, obviously. We need to figure out how to handle this.
- boundsChanged = ResizeViewportToFit (newFrameSize);
}
else
{
- Height = newFrameSize.Height;
- Width = newFrameSize.Width;
+ _height = Dim.Auto (Dim.DimAutoStyle.Text);
+ _width = Dim.Auto (Dim.DimAutoStyle.Text);
}
}
-
- return boundsChanged;
}
+
/// Determines if the View's can be set to a new value.
/// TrySetHeight can only be called when AutoSize is true (or being set to true).
///
@@ -1050,11 +981,11 @@ public partial class View
// TODO: Determine what, if any of the below is actually needed here.
if (IsInitialized)
{
- if (AutoSize)
- {
- SetFrameToFitText ();
- SetTextFormatterSize ();
- }
+ //if (AutoSize)
+ //{
+ // SetFrameToFitText ();
+ // SetTextFormatterSize ();
+ //}
LayoutAdornments ();
SetNeedsDisplay ();
@@ -1156,32 +1087,32 @@ public partial class View
SetNeedsDisplay ();
}
- if (AutoSize)
- {
- if (autoSize.Width == 0 || autoSize.Height == 0)
- {
- // Set the frame. Do NOT use `Frame` as it overwrites X, Y, Width, and Height, making
- // the view LayoutStyle.Absolute.
- SetFrame (_frame with { Size = autoSize });
+ //if (AutoSize)
+ //{
+ // if (autoSize.Width == 0 || autoSize.Height == 0)
+ // {
+ // // Set the frame. Do NOT use `Frame` as it overwrites X, Y, Width, and Height, making
+ // // the view LayoutStyle.Absolute.
+ // SetFrame (_frame with { Size = autoSize });
- if (autoSize.Width == 0)
- {
- _width = 0;
- }
+ // if (autoSize.Width == 0)
+ // {
+ // _width = 0;
+ // }
- if (autoSize.Height == 0)
- {
- _height = 0;
- }
- }
- else if (!SetFrameToFitText ())
- {
- SetTextFormatterSize ();
- }
+ // if (autoSize.Height == 0)
+ // {
+ // _height = 0;
+ // }
+ // }
+ // //else if (!SetFrameToFitText ())
+ // //{
+ // // SetTextFormatterSize ();
+ // //}
- SetNeedsLayout ();
- SetNeedsDisplay ();
- }
+ // SetNeedsLayout ();
+ // SetNeedsDisplay ();
+ //}
}
internal void CollectAll (View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges)
diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs
index 4bc673608..ce5d97a45 100644
--- a/Terminal.Gui/View/ViewText.cs
+++ b/Terminal.Gui/View/ViewText.cs
@@ -290,18 +290,18 @@ public partial class View
TextFormatter.Size = new Size (w, h);
}
- private bool IsValidAutoSize (out Size autoSize)
- {
- Rectangle rect = TextFormatter.CalcRect (_frame.X, _frame.Y, TextFormatter.Text, TextDirection);
+ //private bool IsValidAutoSize (out Size autoSize)
+ //{
+ // Rectangle rect = TextFormatter.CalcRect (_frame.X, _frame.Y, TextFormatter.Text, TextDirection);
- autoSize = new Size (
- rect.Size.Width - GetHotKeySpecifierLength (),
- rect.Size.Height - GetHotKeySpecifierLength (false));
+ // autoSize = new Size (
+ // rect.Size.Width - GetHotKeySpecifierLength (),
+ // rect.Size.Height - GetHotKeySpecifierLength (false));
- return !((ValidatePosDim && (!(Width is Dim.DimAbsolute) || !(Height is Dim.DimAbsolute)))
- || _frame.Size.Width != rect.Size.Width - GetHotKeySpecifierLength ()
- || _frame.Size.Height != rect.Size.Height - GetHotKeySpecifierLength (false));
- }
+ // return !((ValidatePosDim && (!(Width is Dim.DimAbsolute) || !(Height is Dim.DimAbsolute)))
+ // || _frame.Size.Width != rect.Size.Width - GetHotKeySpecifierLength ()
+ // || _frame.Size.Height != rect.Size.Height - GetHotKeySpecifierLength (false));
+ //}
private bool IsValidAutoSizeHeight (Dim height)
{
@@ -319,113 +319,113 @@ public partial class View
return !((ValidatePosDim && !(width is Dim.DimAbsolute)) || dimValue != rect.Size.Width - GetHotKeySpecifierLength ());
}
- ///
- /// Sets the size of the View to the minimum width or height required to fit .
- ///
- ///
- /// if the size was changed; if ==
- /// or
- /// will not fit.
- ///
- ///
- /// Always returns if is or
- /// if (Horizontal) or (Vertical) are not not set or zero.
- /// Does not take into account word wrapping.
- ///
- private bool SetFrameToFitText ()
- {
- if (AutoSize == false)
- {
- throw new InvalidOperationException ("SetFrameToFitText can only be called when AutoSize is true");
- }
+ /////
+ ///// Sets the size of the View to the minimum width or height required to fit .
+ /////
+ /////
+ ///// if the size was changed; if ==
+ ///// or
+ ///// will not fit.
+ /////
+ /////
+ ///// Always returns if is or
+ ///// if (Horizontal) or (Vertical) are not not set or zero.
+ ///// Does not take into account word wrapping.
+ /////
+ //private bool SetFrameToFitText ()
+ //{
+ // if (AutoSize == false)
+ // {
+ // throw new InvalidOperationException ("SetFrameToFitText can only be called when AutoSize is true");
+ // }
- // BUGBUG: This API is broken - should not assume Frame.Height == ContentSize.Height
- //
- // Gets the minimum dimensions required to fit the View's , factoring in .
- //
- // The minimum dimensions required.
- // if the dimensions fit within the View's , otherwise.
- //
- // Always returns if is or
- // if (Horizontal) or (Vertical) are not not set or zero.
- // Does not take into account word wrapping.
- //
- bool GetMinimumSizeOfText (out Size sizeRequired)
- {
- if (!IsInitialized)
- {
- sizeRequired = Size.Empty;
+ // // BUGBUG: This API is broken - should not assume Frame.Height == ContentSize.Height
+ // //
+ // // Gets the minimum dimensions required to fit the View's , factoring in .
+ // //
+ // // The minimum dimensions required.
+ // // if the dimensions fit within the View's , otherwise.
+ // //
+ // // Always returns if is or
+ // // if (Horizontal) or (Vertical) are not not set or zero.
+ // // Does not take into account word wrapping.
+ // //
+ // bool GetMinimumSizeOfText (out Size sizeRequired)
+ // {
+ // if (!IsInitialized)
+ // {
+ // sizeRequired = Size.Empty;
- return false;
- }
+ // return false;
+ // }
- sizeRequired = ContentSize;
+ // sizeRequired = ContentSize;
- if (AutoSize || string.IsNullOrEmpty (TextFormatter.Text))
- {
- return false;
- }
+ // if (AutoSize || string.IsNullOrEmpty (TextFormatter.Text))
+ // {
+ // return false;
+ // }
- switch (TextFormatter.IsVerticalDirection (TextDirection))
- {
- case true:
- int colWidth = TextFormatter.GetSumMaxCharWidth (TextFormatter.Text, 0, 1);
+ // switch (TextFormatter.IsVerticalDirection (TextDirection))
+ // {
+ // case true:
+ // int colWidth = TextFormatter.GetSumMaxCharWidth (TextFormatter.Text, 0, 1);
- // TODO: v2 - This uses frame.Width; it should only use ContentSize
- if (_frame.Width < colWidth
- && (Width is null || (ContentSize.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth)))
- {
- sizeRequired = new (colWidth, ContentSize.Height);
+ // // TODO: v2 - This uses frame.Width; it should only use ContentSize
+ // if (_frame.Width < colWidth
+ // && (Width is null || (ContentSize.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth)))
+ // {
+ // sizeRequired = new (colWidth, ContentSize.Height);
- return true;
- }
+ // return true;
+ // }
- break;
- default:
- if (_frame.Height < 1 && (Height is null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0)))
- {
- sizeRequired = new (ContentSize.Width, 1);
+ // break;
+ // default:
+ // if (_frame.Height < 1 && (Height is null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0)))
+ // {
+ // sizeRequired = new (ContentSize.Width, 1);
- return true;
- }
+ // return true;
+ // }
- break;
- }
+ // break;
+ // }
- return false;
- }
+ // return false;
+ // }
- if (GetMinimumSizeOfText (out Size size))
- {
- // TODO: This is a hack.
- //_width = size.Width;
- //_height = size.Height;
- SetFrame (new (_frame.Location, size));
+ // if (GetMinimumSizeOfText (out Size size))
+ // {
+ // // TODO: This is a hack.
+ // //_width = size.Width;
+ // //_height = size.Height;
+ // SetFrame (new (_frame.Location, size));
- //throw new InvalidOperationException ("This is a hack.");
- return true;
- }
+ // //throw new InvalidOperationException ("This is a hack.");
+ // return true;
+ // }
- return false;
- }
+ // return false;
+ //}
private void UpdateTextDirection (TextDirection newDirection)
{
bool directionChanged = TextFormatter.IsHorizontalDirection (TextFormatter.Direction) != TextFormatter.IsHorizontalDirection (newDirection);
TextFormatter.Direction = newDirection;
- bool isValidOldAutoSize = AutoSize && IsValidAutoSize (out Size _);
+ //bool isValidOldAutoSize = AutoSize && IsValidAutoSize (out Size _);
UpdateTextFormatterText ();
- if ((!ValidatePosDim && directionChanged && AutoSize) || (ValidatePosDim && directionChanged && AutoSize && isValidOldAutoSize))
- {
- OnResizeNeeded ();
- }
- else if (directionChanged && IsAdded)
- {
- ResizeViewportToFit (Viewport.Size);
- }
+ //if ((!ValidatePosDim && directionChanged && AutoSize) || (ValidatePosDim && directionChanged && AutoSize && isValidOldAutoSize))
+ //{
+ // OnResizeNeeded ();
+ //}
+ //else if (directionChanged && IsAdded)
+ //{
+ // ResizeViewportToFit (Viewport.Size);
+ //}
SetTextFormatterSize ();
SetNeedsDisplay ();