From e28f73f175ec8eecf5992f88fc68a7152af6d5fa Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 14 May 2024 16:01:42 -0700 Subject: [PATCH] Pos / Dim code cleanup --- Terminal.Gui/View/Layout/Dim.cs | 607 +++++++++++---------- Terminal.Gui/View/Layout/Pos.cs | 102 ++-- Terminal.Gui/View/Layout/ViewLayout.cs | 58 +- Terminal.Gui/View/ViewContent.cs | 14 +- Terminal.Gui/View/ViewText.cs | 20 +- Terminal.Gui/Views/Button.cs | 4 +- Terminal.Gui/Views/CheckBox.cs | 4 +- Terminal.Gui/Views/ComboBox.cs | 2 +- Terminal.Gui/Views/Label.cs | 8 +- Terminal.Gui/Views/ProgressBar.cs | 4 +- Terminal.Gui/Views/RadioGroup.cs | 4 +- Terminal.Gui/Views/Slider.cs | 6 +- Terminal.Gui/Views/Toplevel.cs | 2 +- UICatalog/Scenarios/AllViewsTester.cs | 14 +- UICatalog/Scenarios/Sliders.cs | 12 +- UnitTests/UICatalog/ScenarioTests.cs | 4 +- UnitTests/View/Layout/Dim.AutoTests.cs | 64 +-- UnitTests/View/Layout/Dim.CombineTests.cs | 2 +- UnitTests/View/Layout/Dim.FillTests.cs | 2 +- UnitTests/View/Layout/Dim.FunctionTests.cs | 2 +- UnitTests/View/Layout/Dim.PercentTests.cs | 2 +- UnitTests/View/Layout/Dim.Tests.cs | 20 +- UnitTests/View/TextTests.cs | 10 +- UnitTests/Views/CheckBoxTests.cs | 16 +- UnitTests/Views/MenuBarTests.cs | 4 +- UnitTests/Views/ScrollViewTests.cs | 4 +- UnitTests/Views/SliderTests.cs | 12 +- 27 files changed, 498 insertions(+), 505 deletions(-) diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs index 2ebe0a477..efa5f3798 100644 --- a/Terminal.Gui/View/Layout/Dim.cs +++ b/Terminal.Gui/View/Layout/Dim.cs @@ -2,6 +2,70 @@ using System.Diagnostics; namespace Terminal.Gui; +/// +/// Specifies how will compute the dimension. +/// +[Flags] +public enum DimAutoStyle +{ + /// + /// The dimension will be computed using both the view's and + /// (whichever is larger). + /// + Auto = Content | Text, + + /// + /// The dimensions will be computed based on the View's non-Text content. + /// + /// If is explicitly set (is not ) then + /// + /// will be used to determine the dimension. + /// + /// + /// Otherwise, the Subview in with the largest corresponding position plus dimension + /// will determine the dimension. + /// + /// + /// The corresponding dimension of the view's will be ignored. + /// + /// + Content = 1, + + /// + /// + /// The corresponding dimension of the view's , formatted using the + /// settings, + /// will be used to determine the dimension. + /// + /// + /// The corresponding dimensions of the will be ignored. + /// + /// + Text = 2 +} + +/// +/// Indicates the dimension for operations. +/// +public enum Dimension +{ + /// + /// No dimension specified. + /// + None = 0, + + /// + /// The height dimension. + /// + Height = 1, + + /// + /// The width dimension. + /// + Width = 2 +} + + /// /// /// A Dim object describes the dimensions of a . Dim is the type of the @@ -80,70 +144,6 @@ namespace Terminal.Gui; /// public class Dim { - /// - /// Specifies how will compute the dimension. - /// - [Flags] - public enum DimAutoStyle - { - /// - /// The dimension will be computed using both the view's and - /// (whichever is larger). - /// - Auto = Content | Text, - - /// - /// The dimensions will be computed based on the View's non-Text content. - /// - /// If is explicitly set (is not ) then - /// will be used to determine the dimension. - /// - /// - /// Otherwise, the Subview in with the largest corresponding position plus dimension - /// will determine the dimension. - /// - /// - /// The corresponding dimension of the view's will be ignored. - /// - /// - Content = 1, - - /// - /// - /// The corresponding dimension of the view's , formatted using the - /// settings, - /// will be used to determine the dimension. - /// - /// - /// The corresponding dimensions of the will be ignored. - /// - /// - Text = 2 - } - - - /// - /// - /// - public enum Dimension - { - /// - /// No dimension specified. - /// - None = 0, - - /// - /// The height dimension. - /// - Height = 1, - - /// - /// The width dimension. - /// - Width = 2 - } - - /// /// Creates a object that automatically sizes the view to fit all the view's SubViews and/or Text. /// @@ -155,7 +155,7 @@ public class Dim /// /// This initializes a with two SubViews. The view will be automatically sized to fit the two /// SubViews. - /// + /// /// var button = new Button () { Text = "Click Me!", X = 1, Y = 1, Width = 10, Height = 1 }; /// var textField = new TextField { Text = "Type here", X = 1, Y = 2, Width = 20, Height = 1 }; /// var view = new Window () { Title = "MyWindow", X = 0, Y = 0, Width = Dim.Auto (), Height = Dim.Auto () }; @@ -308,7 +308,8 @@ public class Dim /// /// Calculates and returns the dimension of a object. It takes into account the location of the - /// , it's SuperView's ContentSize, and whether it should automatically adjust its size based on its content. + /// , it's SuperView's ContentSize, and whether it should automatically adjust its size based on its + /// content. /// /// /// The starting point from where the size calculation begins. It could be the left edge for width calculation or the @@ -327,290 +328,290 @@ public class Dim } /// - /// Diagnostics API to determine if this Dim object references other views. + /// Diagnostics API to determine if this Dim object references other views. /// /// - internal virtual bool ReferencesOtherViews () + internal virtual bool ReferencesOtherViews () { return false; } +} + +internal class DimAbsolute (int n) : Dim +{ + private readonly int _n = n; + public override bool Equals (object other) { return other is DimAbsolute abs && abs._n == _n; } + public override int GetHashCode () { return _n.GetHashCode (); } + public override string ToString () { return $"Absolute({_n})"; } + internal override int Anchor (int width) { return _n; } + + internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { - return false; + // DimAbsolute.Anchor (int width) ignores width and returns n + return Math.Max (Anchor (0), 0); + } +} + +/// +/// A object that automatically sizes the view to fit all the view's SubViews and/or Text. +/// +/// +/// +/// See . +/// +/// +/// +/// Specifies how will compute the dimension. The default is . +/// +/// The minimum dimension the View's ContentSize will be constrained to. +/// The maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED. +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; + + /// + public override bool Equals (object other) + { + return other is DimAuto auto && auto._minContentDim == _minContentDim && auto._maxContentDim == _maxContentDim && auto._style == _style; } - internal class DimAbsolute (int n) : Dim - { - private readonly int _n = n; - public override bool Equals (object other) { return other is DimAbsolute abs && abs._n == _n; } - public override int GetHashCode () { return _n.GetHashCode (); } - public override string ToString () { return $"Absolute({_n})"; } - internal override int Anchor (int width) { return _n; } + /// + public override int GetHashCode () { return HashCode.Combine (base.GetHashCode (), _minContentDim, _maxContentDim, _style); } - internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + /// + public override string ToString () { return $"Auto({_style},{_minContentDim},{_maxContentDim})"; } + + internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + { + if (us == null) { - // DimAbsolute.Anchor (int width) ignores width and returns n - return Math.Max (Anchor (0), 0); + return _maxContentDim?.Anchor (0) ?? 0; } - } - /// - /// A object that automatically sizes the view to fit all the view's SubViews and/or Text. - /// - /// - /// - /// See . - /// - /// - /// - /// Specifies how will compute the dimension. The default is . - /// - /// The minimum dimension the View's ContentSize will be constrained to. - /// The maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED. - 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; + var textSize = 0; + var subviewsSize = 0; - /// - public override bool Equals (object other) { return other is DimAuto auto && auto._minContentDim == _minContentDim && auto._maxContentDim == _maxContentDim && auto._style == _style; } - /// - public override int GetHashCode () { return HashCode.Combine (base.GetHashCode (), _minContentDim, _maxContentDim, _style); } - /// - public override string ToString () { return $"Auto({_style},{_minContentDim},{_maxContentDim})"; } + int autoMin = _minContentDim?.Anchor (superviewContentSize) ?? 0; - internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + if (superviewContentSize < autoMin) { - if (us == null) + Debug.WriteLine ($"WARNING: DimAuto specifies a min size ({autoMin}), but the SuperView's bounds are smaller ({superviewContentSize})."); + + return superviewContentSize; + } + + if (_style.HasFlag (DimAutoStyle.Text)) + { + textSize = int.Max (autoMin, dimension == Dimension.Width ? us.TextFormatter.Size.Width : us.TextFormatter.Size.Height); + } + + if (_style.HasFlag (DimAutoStyle.Content)) + { + if (us._contentSize is { }) { - return _maxContentDim?.Anchor (0) ?? 0; + subviewsSize = dimension == Dimension.Width ? us.ContentSize.Width : us.ContentSize.Height; } - - var textSize = 0; - var subviewsSize = 0; - - int autoMin = _minContentDim?.Anchor (superviewContentSize) ?? 0; - - if (superviewContentSize < autoMin) + else { - Debug.WriteLine ($"WARNING: DimAuto specifies a min size ({autoMin}), but the SuperView's bounds are smaller ({superviewContentSize})."); + // TODO: AnchorEnd needs work + // TODO: If _min > 0 we can SetRelativeLayout for the subviews? + subviewsSize = 0; - return superviewContentSize; - } - - if (_style.HasFlag (Dim.DimAutoStyle.Text)) - { - textSize = int.Max (autoMin, dimension == Dimension.Width ? us.TextFormatter.Size.Width : us.TextFormatter.Size.Height); - } - - if (_style.HasFlag (DimAutoStyle.Content)) - { - if (us._contentSize is { }) + if (us.Subviews.Count > 0) { - subviewsSize = dimension == Dimension.Width ? us.ContentSize.Width : us.ContentSize.Height; - } - else - { - // TODO: AnchorEnd needs work - // TODO: If _min > 0 we can SetRelativeLayout for the subviews? - subviewsSize = 0; - if (us.Subviews.Count > 0) + for (var i = 0; i < us.Subviews.Count; i++) { - for (int i = 0; i < us.Subviews.Count; i++) + View v = us.Subviews [i]; + bool isNotPosAnchorEnd = dimension == Dimension.Width ? v.X is not PosAnchorEnd : v.Y is not PosAnchorEnd; + + //if (!isNotPosAnchorEnd) + //{ + // v.SetRelativeLayout(dimension == Dimension.Width ? (new Size (autoMin, 0)) : new Size (0, autoMin)); + //} + + if (isNotPosAnchorEnd) { - var v = us.Subviews [i]; - bool isNotPosAnchorEnd = dimension == Dim.Dimension.Width ? v.X is not PosAnchorEnd : v.Y is not PosAnchorEnd; + int size = dimension == Dimension.Width ? v.Frame.X + v.Frame.Width : v.Frame.Y + v.Frame.Height; - //if (!isNotPosAnchorEnd) - //{ - // v.SetRelativeLayout(dimension == Dim.Dimension.Width ? (new Size (autoMin, 0)) : new Size (0, autoMin)); - //} - - if (isNotPosAnchorEnd) + if (size > subviewsSize) { - int size = dimension == Dim.Dimension.Width ? v.Frame.X + v.Frame.Width : v.Frame.Y + v.Frame.Height; - if (size > subviewsSize) - { - subviewsSize = size; - } + subviewsSize = size; } } } - } } - - // All sizes here are content-relative; ignoring adornments. - // We take the larger of text and content. - int max = int.Max (textSize, subviewsSize); - - // And, if min: is set, it wins if larger - max = int.Max (max, autoMin); - - // Factor in adornments - Thickness thickness = us.GetAdornmentsThickness (); - if (dimension == Dimension.Width) - { - max += thickness.Horizontal; - } - else - { - max += thickness.Vertical; - } - - // If max: is set, clamp the return - BUGBUG: Not tested - return int.Min (max, _maxContentDim?.Anchor (superviewContentSize) ?? superviewContentSize); } - /// - /// Diagnostics API to determine if this Dim object references other views. - /// - /// - internal override bool ReferencesOtherViews () + // All sizes here are content-relative; ignoring adornments. + // We take the larger of text and content. + int max = int.Max (textSize, subviewsSize); + + // And, if min: is set, it wins if larger + max = int.Max (max, autoMin); + + // Factor in adornments + Thickness thickness = us.GetAdornmentsThickness (); + + if (dimension == Dimension.Width) { - // BUGBUG: This is not correct. _contentSize may be null. - return false;//_style.HasFlag (Dim.DimAutoStyle.Content); + max += thickness.Horizontal; } - - } - internal class DimCombine (bool add, Dim left, Dim right) : Dim - { - internal bool _add = add; - internal Dim _left = left, _right = right; - - public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } - - internal override int Anchor (int width) + else { - int la = _left.Anchor (width); - int ra = _right.Anchor (width); - - if (_add) - { - return la + ra; - } - - return la - ra; + max += thickness.Vertical; } - internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) - { - int leftNewDim = _left.Calculate (location, superviewContentSize, us, dimension); - int rightNewDim = _right.Calculate (location, superviewContentSize, us, dimension); - - int newDimension; - - if (_add) - { - newDimension = leftNewDim + rightNewDim; - } - else - { - newDimension = Math.Max (0, leftNewDim - rightNewDim); - } - - return newDimension; - } - - - /// - /// Diagnostics API to determine if this Dim object references other views. - /// - /// - internal override bool ReferencesOtherViews () - { - if (_left.ReferencesOtherViews ()) - { - return true; - } - - if (_right.ReferencesOtherViews ()) - { - return true; - } - - return false; - } + // If max: is set, clamp the return - BUGBUG: Not tested + return int.Min (max, _maxContentDim?.Anchor (superviewContentSize) ?? superviewContentSize); } - internal class DimFactor (float factor, bool remaining = false) : Dim + /// + /// Diagnostics API to determine if this Dim object references other views. + /// + /// + internal override bool ReferencesOtherViews () { - private readonly float _factor = factor; - private readonly bool _remaining = remaining; + // BUGBUG: This is not correct. _contentSize may be null. + return false; //_style.HasFlag (DimAutoStyle.Content); + } +} - public override bool Equals (object other) { return other is DimFactor f && f._factor == _factor && f._remaining == _remaining; } - public override int GetHashCode () { return _factor.GetHashCode (); } - public bool IsFromRemaining () { return _remaining; } - public override string ToString () { return $"Factor({_factor},{_remaining})"; } - internal override int Anchor (int width) { return (int)(width * _factor); } +internal class DimCombine (bool add, Dim left, Dim right) : Dim +{ + internal bool _add = add; + internal Dim _left = left, _right = right; - internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } + + internal override int Anchor (int width) + { + int la = _left.Anchor (width); + int ra = _right.Anchor (width); + + if (_add) { - return _remaining ? Math.Max (Anchor (superviewContentSize - location), 0) : Anchor (superviewContentSize); + return la + ra; } + + return la - ra; } - internal class DimFill (int margin) : Dim + internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { - private readonly int _margin = margin; - public override bool Equals (object other) { return other is DimFill fill && fill._margin == _margin; } - public override int GetHashCode () { return _margin.GetHashCode (); } - public override string ToString () { return $"Fill({_margin})"; } - internal override int Anchor (int width) { return width - _margin; } + int leftNewDim = _left.Calculate (location, superviewContentSize, us, dimension); + int rightNewDim = _right.Calculate (location, superviewContentSize, us, dimension); + + int newDimension; + + if (_add) + { + newDimension = leftNewDim + rightNewDim; + } + else + { + newDimension = Math.Max (0, leftNewDim - rightNewDim); + } + + return newDimension; } - // Helper class to provide dynamic value by the execution of a function that returns an integer. - internal class DimFunc (Func n) : Dim + /// + /// Diagnostics API to determine if this Dim object references other views. + /// + /// + internal override bool ReferencesOtherViews () { - private readonly Func _function = n; - public override bool Equals (object other) { return other is DimFunc f && f._function () == _function (); } - public override int GetHashCode () { return _function.GetHashCode (); } - public override string ToString () { return $"DimFunc({_function ()})"; } - internal override int Anchor (int width) { return _function (); } - } - - internal class DimView : Dim - { - private readonly Dimension _side; - - internal DimView (View view, Dimension side) - { - Target = view; - _side = side; - } - - public View Target { get; init; } - public override bool Equals (object other) { return other is DimView abs && abs.Target == Target; } - public override int GetHashCode () { return Target.GetHashCode (); } - - public override string ToString () - { - if (Target == null) - { - throw new NullReferenceException (); - } - - string sideString = _side switch - { - Dimension.Height => "Height", - Dimension.Width => "Width", - _ => "unknown" - }; - - return $"View({sideString},{Target})"; - } - - internal override int Anchor (int width) - { - return _side switch - { - Dimension.Height => Target.Frame.Height, - Dimension.Width => Target.Frame.Width, - _ => 0 - }; - } - - internal override bool ReferencesOtherViews () + if (_left.ReferencesOtherViews ()) { return true; } + + if (_right.ReferencesOtherViews ()) + { + return true; + } + + return false; } -} \ No newline at end of file +} + +internal class DimFactor (float factor, bool remaining = false) : Dim +{ + private readonly float _factor = factor; + private readonly bool _remaining = remaining; + + public override bool Equals (object other) { return other is DimFactor f && f._factor == _factor && f._remaining == _remaining; } + public override int GetHashCode () { return _factor.GetHashCode (); } + public bool IsFromRemaining () { return _remaining; } + public override string ToString () { return $"Factor({_factor},{_remaining})"; } + internal override int Anchor (int width) { return (int)(width * _factor); } + + internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + { + return _remaining ? Math.Max (Anchor (superviewContentSize - location), 0) : Anchor (superviewContentSize); + } +} + +internal class DimFill (int margin) : Dim +{ + private readonly int _margin = margin; + public override bool Equals (object other) { return other is DimFill fill && fill._margin == _margin; } + public override int GetHashCode () { return _margin.GetHashCode (); } + public override string ToString () { return $"Fill({_margin})"; } + internal override int Anchor (int width) { return width - _margin; } +} + +// Helper class to provide dynamic value by the execution of a function that returns an integer. +internal class DimFunc (Func n) : Dim +{ + private readonly Func _function = n; + public override bool Equals (object other) { return other is DimFunc f && f._function () == _function (); } + public override int GetHashCode () { return _function.GetHashCode (); } + public override string ToString () { return $"DimFunc({_function ()})"; } + internal override int Anchor (int width) { return _function (); } +} + +internal class DimView : Dim +{ + private readonly Dimension _side; + + internal DimView (View view, Dimension side) + { + Target = view; + _side = side; + } + + public View Target { get; init; } + public override bool Equals (object other) { return other is DimView abs && abs.Target == Target; } + public override int GetHashCode () { return Target.GetHashCode (); } + + public override string ToString () + { + if (Target == null) + { + throw new NullReferenceException (); + } + + string sideString = _side switch + { + Dimension.Height => "Height", + Dimension.Width => "Width", + _ => "unknown" + }; + + return $"View({sideString},{Target})"; + } + + internal override int Anchor (int width) + { + return _side switch + { + Dimension.Height => Target.Frame.Height, + Dimension.Width => Target.Frame.Width, + _ => 0 + }; + } + + internal override bool ReferencesOtherViews () { return true; } +} diff --git a/Terminal.Gui/View/Layout/Pos.cs b/Terminal.Gui/View/Layout/Pos.cs index de017bf01..d45b242d2 100644 --- a/Terminal.Gui/View/Layout/Pos.cs +++ b/Terminal.Gui/View/Layout/Pos.cs @@ -1,7 +1,31 @@ -using System.Diagnostics; - namespace Terminal.Gui; +/// +/// Indicates the side for operations. +/// +public enum Side +{ + /// + /// The left (X) side of the view. + /// + Left = 0, + + /// + /// The top (Y) side of the view. + /// + Top = 1, + + /// + /// The right (X + Width) side of the view. + /// + Right = 2, + + /// + /// The bottom (Y + Height) side of the view. + /// + Bottom = 3 +} + /// /// Describes the position of a which can be an absolute value, a percentage, centered, or /// relative to the ending dimension. Integer values are implicitly convertible to an absolute . These @@ -346,11 +370,10 @@ public class Pos /// that /// is used. /// - internal virtual int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension) { return Anchor (superviewDimension); } - + internal virtual int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { return Anchor (superviewDimension); } /// - /// Diagnostics API to determine if this Pos object references other views. + /// Diagnostics API to determine if this Pos object references other views. /// /// internal virtual bool ReferencesOtherViews () { return false; } @@ -390,7 +413,7 @@ internal class PosAnchorEnd : Pos return width - _offset; } - internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension) + internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newLocation = Anchor (superviewDimension); @@ -408,7 +431,7 @@ internal class PosCenter : Pos public override string ToString () { return "Center"; } internal override int Anchor (int width) { return width / 2; } - internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension) + internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newDimension = Math.Max (dim.Calculate (0, superviewDimension, us, dimension), 0); @@ -436,7 +459,7 @@ internal class PosCombine (bool add, Pos left, Pos right) : Pos return la - ra; } - internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension) + internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newDimension = dim.Calculate (0, superviewDimension, us, dimension); int left = _left.Calculate (superviewDimension, dim, us, dimension); @@ -451,7 +474,7 @@ internal class PosCombine (bool add, Pos left, Pos right) : Pos } /// - /// Diagnostics API to determine if this Pos object references other views. + /// Diagnostics API to determine if this Pos object references other views. /// /// internal override bool ReferencesOtherViews () @@ -489,32 +512,6 @@ internal class PosFunc (Func n) : Pos internal override int Anchor (int width) { return _function (); } } -/// -/// Describes which side of the view to use for the position. -/// -public enum Side -{ - /// - /// The left (X) side of the view. - /// - Left = 0, - - /// - /// The top (Y) side of the view. - /// - Top = 1, - - /// - /// The right (X + Width) side of the view. - /// - Right = 2, - - /// - /// The bottom (Y + Height) side of the view. - /// - Bottom = 3 -} - internal class PosView (View view, Side side) : Pos { public readonly View Target = view; @@ -525,13 +522,13 @@ internal class PosView (View view, Side side) : Pos public override string ToString () { string sideString = side switch - { - Side.Left => "left", - Side.Top => "top", - Side.Right => "right", - Side.Bottom => "bottom", - _ => "unknown" - }; + { + Side.Left => "left", + Side.Top => "top", + Side.Right => "right", + Side.Bottom => "bottom", + _ => "unknown" + }; if (Target == null) { @@ -544,21 +541,18 @@ internal class PosView (View view, Side side) : Pos internal override int Anchor (int width) { return side switch - { - Side.Left => Target.Frame.X, - Side.Top => Target.Frame.Y, - Side.Right => Target.Frame.Right, - Side.Bottom => Target.Frame.Bottom, - _ => 0 - }; + { + Side.Left => Target.Frame.X, + Side.Top => Target.Frame.Y, + Side.Right => Target.Frame.Right, + Side.Bottom => Target.Frame.Bottom, + _ => 0 + }; } /// - /// Diagnostics API to determine if this Pos object references other views. + /// Diagnostics API to determine if this Pos object references other views. /// /// - internal override bool ReferencesOtherViews () - { - return true; - } + internal override bool ReferencesOtherViews () { return true; } } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 5765e148e..f1d5e9051 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -260,7 +260,7 @@ public partial class View /// /// /// Changing this property will cause to be updated. If the new value is not of type - /// the will change to . + /// the will change to . /// /// The default value is Dim.Sized (0). /// @@ -274,7 +274,7 @@ public partial class View return; } - if (_height is Dim.DimAuto) + if (_height is DimAuto) { // Reset ContentSize to Viewport _contentSize = null; @@ -306,7 +306,7 @@ public partial class View /// /// /// Changing this property will cause to be updated. If the new value is not of type - /// the will change to . + /// the will change to . /// /// The default value is Dim.Sized (0). /// @@ -320,7 +320,7 @@ public partial class View return; } - if (_width is Dim.DimAuto) + if (_width is DimAuto) { // Reset ContentSize to Viewport _contentSize = null; @@ -357,7 +357,7 @@ public partial class View /// /// /// Setting this property to will cause to determine the - /// size and position of the view. and will be set to + /// size and position of the view. and will be set to /// using . /// /// @@ -365,7 +365,7 @@ public partial class View /// method to size and position of the view. If either of the and /// properties are `null` they will be set to using the current value /// of . If either of the and properties are `null` - /// they will be set to using . + /// they will be set to using . /// /// /// The layout style. @@ -375,8 +375,8 @@ public partial class View { if (_x is PosAbsolute && _y is PosAbsolute - && _width is Dim.DimAbsolute - && _height is Dim.DimAbsolute) + && _width is DimAbsolute + && _height is DimAbsolute) { return LayoutStyle.Absolute; } @@ -806,26 +806,26 @@ public partial class View CheckDimAuto (); int newX, newW, newY, newH; - if (_width is Dim.DimAuto) + if (_width is DimAuto) { - newW = _width.Calculate (0, superviewContentSize.Width, this, Dim.Dimension.Width); - newX = _x.Calculate (superviewContentSize.Width, newW, this, Dim.Dimension.Width); + newW = _width.Calculate (0, superviewContentSize.Width, this, Dimension.Width); + newX = _x.Calculate (superviewContentSize.Width, newW, this, Dimension.Width); } else { - newX = _x.Calculate (superviewContentSize.Width, _width, this, Dim.Dimension.Width); - newW = _width.Calculate (newX, superviewContentSize.Width, this, Dim.Dimension.Width); + newX = _x.Calculate (superviewContentSize.Width, _width, this, Dimension.Width); + newW = _width.Calculate (newX, superviewContentSize.Width, this, Dimension.Width); } - if (_height is Dim.DimAuto) + if (_height is DimAuto) { - newH = _height.Calculate (0, superviewContentSize.Height, this, Dim.Dimension.Height); - newY = _y.Calculate (superviewContentSize.Height, newH, this, Dim.Dimension.Height); + newH = _height.Calculate (0, superviewContentSize.Height, this, Dimension.Height); + newY = _y.Calculate (superviewContentSize.Height, newH, this, Dimension.Height); } else { - newY = _y.Calculate (superviewContentSize.Height, _height, this, Dim.Dimension.Height); - newH = _height.Calculate (newY, superviewContentSize.Height, this, Dim.Dimension.Height); + newY = _y.Calculate (superviewContentSize.Height, _height, this, Dimension.Height); + newH = _height.Calculate (newY, superviewContentSize.Height, this, Dimension.Height); } Rectangle newFrame = new (newX, newY, newW, newH); @@ -846,12 +846,12 @@ public partial class View _y = Frame.Y; } - if (_width is Dim.DimAbsolute) + if (_width is DimAbsolute) { _width = Frame.Width; } - if (_height is Dim.DimAbsolute) + if (_height is DimAbsolute) { _height = Frame.Height; } @@ -889,7 +889,7 @@ public partial class View { switch (dim) { - case Dim.DimView dv: + case DimView dv: // See #2461 //if (!from.InternalSubviews.Contains (dv.Target)) { // throw new InvalidOperationException ($"View {dv.Target} is not a subview of {from}"); @@ -900,7 +900,7 @@ public partial class View } return; - case Dim.DimCombine dc: + case DimCombine dc: CollectDim (dc._left, from, ref nNodes, ref nEdges); CollectDim (dc._right, from, ref nNodes, ref nEdges); @@ -1075,7 +1075,7 @@ public partial class View /// private void CheckDimAuto () { - if (!ValidatePosDim || !IsInitialized || (Width is not Dim.DimAuto && Height is not Dim.DimAuto)) + if (!ValidatePosDim || !IsInitialized || (Width is not DimAuto && Height is not DimAuto)) { return; } @@ -1083,13 +1083,13 @@ public partial class View // Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions. foreach (View view in Subviews) { - if (Width is Dim.DimAuto { _minContentDim: null }) + if (Width is DimAuto { _minContentDim: null }) { ThrowInvalid (view, view.Width, nameof (view.Width)); ThrowInvalid (view, view.X, nameof (view.X)); } - if (Height is Dim.DimAuto { _minContentDim: null }) + if (Height is DimAuto { _minContentDim: null }) { ThrowInvalid (view, view.Height, nameof (view.Height)); ThrowInvalid (view, view.Y, nameof (view.Y)); @@ -1116,15 +1116,15 @@ public partial class View break; - case Dim dim and not Dim.DimAbsolute and not Dim.DimView and not Dim.DimCombine: + case Dim dim and not DimAbsolute and not DimView and not DimCombine: bad = dim; break; - case Dim dim and Dim.DimCombine: + case Dim dim and DimCombine: // Recursively check for not Absolute or not View - ThrowInvalid (view, (dim as Dim.DimCombine)._left, name); - ThrowInvalid (view, (dim as Dim.DimCombine)._right, name); + ThrowInvalid (view, (dim as DimCombine)._left, name); + ThrowInvalid (view, (dim as DimCombine)._right, name); break; } diff --git a/Terminal.Gui/View/ViewContent.cs b/Terminal.Gui/View/ViewContent.cs index 688edc992..a38c92d2c 100644 --- a/Terminal.Gui/View/ViewContent.cs +++ b/Terminal.Gui/View/ViewContent.cs @@ -144,7 +144,7 @@ public partial class View /// to the user. This enables virtual scrolling. /// /// - /// If not , is set to the passed value and the behavior of will be to use the ContentSize + /// If not , is set to the passed value and the behavior of will be to use the ContentSize /// to determine the size of the view. /// /// @@ -335,11 +335,11 @@ public partial class View // // The Frame has not been set yet (e.g. the view has not been added to a SuperView yet). // // // // Use _width & _height instead of Width & Height to avoid debug spew - // Dim.DimAuto widthAuto = _width as Dim.DimAuto; - // Dim.DimAuto heightAuto = _height as Dim.DimAuto; + // DimAuto widthAuto = _width as DimAuto; + // DimAuto heightAuto = _height as DimAuto; - // if ((widthAuto is { } && widthAuto._style.HasFlag (Dim.DimAutoStyle.Text)) - // || (heightAuto is { } && heightAuto._style.HasFlag (Dim.DimAutoStyle.Text))) + // if ((widthAuto is { } && widthAuto._style.HasFlag (DimAutoStyle.Text)) + // || (heightAuto is { } && heightAuto._style.HasFlag (DimAutoStyle.Text))) // { // //if (TextFormatter.NeedsFormat) // { @@ -347,12 +347,12 @@ public partial class View // TextFormatter.AutoSize = false; // var size = TextFormatter.GetAutoSize (); - // if (widthAuto is null || !widthAuto._style.HasFlag (Dim.DimAutoStyle.Text)) + // if (widthAuto is null || !widthAuto._style.HasFlag (DimAutoStyle.Text)) // { // size.Width = _width.Anchor (0); // } - // if (heightAuto is null || !heightAuto._style.HasFlag (Dim.DimAutoStyle.Text)) + // if (heightAuto is null || !heightAuto._style.HasFlag (DimAutoStyle.Text)) // { // size.Height = _height.Anchor (0); // } diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index e30573a74..2af2de432 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -40,7 +40,7 @@ public partial class View /// The text will word-wrap to additional lines if it does not fit horizontally. If 's height /// is 1, the text will be clipped. /// - /// If or are using , + /// If or are using , /// the will be adjusted to fit the text. /// When the text changes, the is fired. /// @@ -84,7 +84,7 @@ public partial class View /// redisplay the . /// /// - /// or are using , the will be adjusted to fit the text. + /// or are using , the will be adjusted to fit the text. /// /// The text alignment. public virtual TextAlignment TextAlignment @@ -103,7 +103,7 @@ public partial class View /// . /// /// - /// or are using , the will be adjusted to fit the text. + /// or are using , the will be adjusted to fit the text. /// /// The text alignment. public virtual TextDirection TextDirection @@ -127,7 +127,7 @@ public partial class View /// the . /// /// - /// or are using , the will be adjusted to fit the text. + /// or are using , the will be adjusted to fit the text. /// /// The text alignment. public virtual VerticalTextAlignment VerticalTextAlignment @@ -184,19 +184,19 @@ public partial class View // TODO: This is a hack. Figure out how to move this into DimDimAuto // Use _width & _height instead of Width & Height to avoid debug spew - Dim.DimAuto widthAuto = _width as Dim.DimAuto; - Dim.DimAuto heightAuto = _height as Dim.DimAuto; - if ((widthAuto is { } && widthAuto._style.HasFlag (Dim.DimAutoStyle.Text)) - || (heightAuto is { } && heightAuto._style.HasFlag (Dim.DimAutoStyle.Text))) + DimAuto widthAuto = _width as DimAuto; + DimAuto heightAuto = _height as DimAuto; + if ((widthAuto is { } && widthAuto._style.HasFlag (DimAutoStyle.Text)) + || (heightAuto is { } && heightAuto._style.HasFlag (DimAutoStyle.Text))) { size = TextFormatter.GetAutoSize (); - if (widthAuto is null || !widthAuto._style.HasFlag (Dim.DimAutoStyle.Text)) + if (widthAuto is null || !widthAuto._style.HasFlag (DimAutoStyle.Text)) { size.Width = ContentSize.Width; } - if (heightAuto is null || !heightAuto._style.HasFlag (Dim.DimAutoStyle.Text)) + if (heightAuto is null || !heightAuto._style.HasFlag (DimAutoStyle.Text)) { size.Height = ContentSize.Height; } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 437d62f38..52c72ab5f 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -45,8 +45,8 @@ public class Button : View _leftDefault = Glyphs.LeftDefaultIndicator; _rightDefault = Glyphs.RightDefaultIndicator; - Width = Dim.Auto (Dim.DimAutoStyle.Text); - Height = Dim.Auto (Dim.DimAutoStyle.Text, minimumContentDim: 1); + Width = Dim.Auto (DimAutoStyle.Text); + Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1); CanFocus = true; HighlightStyle |= HighlightStyle.Pressed; diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index 8b1b9b971..c799c8c0f 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -20,8 +20,8 @@ public class CheckBox : View _charChecked = Glyphs.Checked; _charUnChecked = Glyphs.UnChecked; - Width = Dim.Auto (Dim.DimAutoStyle.Text); - Height = Dim.Auto (Dim.DimAutoStyle.Text, minimumContentDim: 1); + Width = Dim.Auto (DimAutoStyle.Text); + Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1); CanFocus = true; diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 53b1750c2..1f8c37a6c 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -607,7 +607,7 @@ public class ComboBox : View private void ProcessLayout () { - if (Viewport.Height < _minimumHeight && (Height is null || Height is Dim.DimAbsolute)) + if (Viewport.Height < _minimumHeight && (Height is null || Height is DimAbsolute)) { Height = _minimumHeight; } diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 9882e053e..992ea1aca 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -1,6 +1,4 @@ -using System.Reflection.Metadata.Ecma335; - -namespace Terminal.Gui; +namespace Terminal.Gui; /// /// The Label displays a string at a given position and supports multiple lines separated by @@ -15,8 +13,8 @@ public class Label : View /// public Label () { - Height = Dim.Auto (Dim.DimAutoStyle.Text); - Width = Dim.Auto (Dim.DimAutoStyle.Text); + Height = Dim.Auto (DimAutoStyle.Text); + Width = Dim.Auto (DimAutoStyle.Text); // Things this view knows how to do AddCommand (Command.HotKey, FocusNext); diff --git a/Terminal.Gui/Views/ProgressBar.cs b/Terminal.Gui/Views/ProgressBar.cs index f35a76438..4e9c9dcf6 100644 --- a/Terminal.Gui/Views/ProgressBar.cs +++ b/Terminal.Gui/Views/ProgressBar.cs @@ -282,8 +282,8 @@ public class ProgressBar : View private void SetInitialProperties () { - Width = Dim.Auto (Dim.DimAutoStyle.Content); - Height = Dim.Auto (Dim.DimAutoStyle.Content, minimumContentDim: 1); + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 1); CanFocus = false; _fraction = 0; Initialized += ProgressBar_Initialized; diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 710df009f..a42f6d840 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -18,8 +18,8 @@ public class RadioGroup : View { CanFocus = true; - Width = Dim.Auto (Dim.DimAutoStyle.Content); - Height = Dim.Auto (Dim.DimAutoStyle.Content); + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content); // Things this view knows how to do AddCommand ( diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index ca8573ecf..9182605b4 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -242,8 +242,8 @@ public class Slider : View Orientation orientation = Orientation.Horizontal ) { - Width = Dim.Auto (Dim.DimAutoStyle.Content); - Height = Dim.Auto (Dim.DimAutoStyle.Content); + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content); CanFocus = true; CursorVisibility = CursorVisibility.Default; @@ -610,7 +610,7 @@ public class Slider : View /// Adjust the dimensions of the Slider to the best value. public void SetContentSizeBestFit () { - if (!IsInitialized || /*!(Height is Dim.DimAuto && Width is Dim.DimAuto) || */_options.Count == 0) + if (!IsInitialized || /*!(Height is DimAuto && Width is DimAuto) || */_options.Count == 0) { return; } diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index f21c40a64..05ea81d98 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -418,7 +418,7 @@ public partial class Toplevel : View if (sb != null && !top.Subviews.Contains (sb) && ny + top.Frame.Height != superView.Frame.Height - (sb.Visible ? 1 : 0) - && top.Height is Dim.DimFill + && top.Height is DimFill && -top.Height.Anchor (0) < 1) { top.Height = Dim.Fill (sb.Visible ? 1 : 0); diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 0291433fb..4f448edec 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -92,7 +92,7 @@ public class AllViewsTester : Scenario { X = 0, Y = 0, - Width = Dim.Auto (Dim.DimAutoStyle.Content), + Width = Dim.Auto (DimAutoStyle.Content), Height = Dim.Fill (1), // for status bar CanFocus = false, ColorScheme = Colors.ColorSchemes ["TopLevel"], @@ -462,7 +462,7 @@ public class AllViewsTester : Scenario MessageBox.ErrorQuery ("Exception", e.Message, "Ok"); } - if (view.Width is Dim.DimAuto) + if (view.Width is DimAuto) { _wText.Text = $"Auto"; _wText.Enabled = false; @@ -473,7 +473,7 @@ public class AllViewsTester : Scenario _wText.Enabled = true; } - if (view.Height is Dim.DimAuto) + if (view.Height is DimAuto) { _hText.Text = $"Auto"; _hText.Enabled = false; @@ -528,7 +528,7 @@ public class AllViewsTester : Scenario var h = view.Height.ToString (); _wRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => w.Contains (s)).First ()); _hRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => h.Contains (s)).First ()); - if (view.Width is Dim.DimAuto) + if (view.Width is DimAuto) { _wText.Text = $"Auto"; _wText.Enabled = false; @@ -539,7 +539,7 @@ public class AllViewsTester : Scenario _wText.Enabled = true; } - if (view.Height is Dim.DimAuto) + if (view.Height is DimAuto) { _hText.Text = $"Auto"; _hText.Enabled = false; @@ -561,12 +561,12 @@ public class AllViewsTester : Scenario return; } - if (view.Width is not Dim.DimAuto && (view.Width is null || view.Frame.Width == 0)) + if (view.Width is not DimAuto && (view.Width is null || view.Frame.Width == 0)) { view.Width = Dim.Fill (); } - if (view.Height is not Dim.DimAuto && (view.Height is null || view.Frame.Height == 0)) + if (view.Height is not DimAuto && (view.Height is null || view.Frame.Height == 0)) { view.Height = Dim.Fill (); } diff --git a/UICatalog/Scenarios/Sliders.cs b/UICatalog/Scenarios/Sliders.cs index 08b5d6fda..cf0a8db89 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/Sliders.cs @@ -186,8 +186,8 @@ public class Sliders : Scenario if (e.Options.ContainsKey (3)) { - s.Width = Dim.Auto (Dim.DimAutoStyle.Content); - s.Height = Dim.Auto (Dim.DimAutoStyle.Content); + s.Width = Dim.Auto (DimAutoStyle.Content); + s.Height = Dim.Auto (DimAutoStyle.Content); } else { @@ -277,8 +277,8 @@ public class Sliders : Scenario if (optionsSlider.GetSetOptions ().Contains (3)) { - s.Width = Dim.Auto (Dim.DimAutoStyle.Content); - s.Height = Dim.Auto (Dim.DimAutoStyle.Content); + s.Width = Dim.Auto (DimAutoStyle.Content); + s.Height = Dim.Auto (DimAutoStyle.Content); } else { @@ -334,8 +334,8 @@ public class Sliders : Scenario if (optionsSlider.GetSetOptions ().Contains (3)) { - s.Width = Dim.Auto (Dim.DimAutoStyle.Content); - s.Height = Dim.Auto (Dim.DimAutoStyle.Content); + s.Width = Dim.Auto (DimAutoStyle.Content); + s.Height = Dim.Auto (DimAutoStyle.Content); } else { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index bace9fd89..d6865c65a 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -482,12 +482,12 @@ public class ScenarioTests : TestsAllViews return null; } - if (view.Width is not Dim.DimAuto) + if (view.Width is not DimAuto) { view.Width = Dim.Percent (75); } - if (view.Height is not Dim.DimAuto) + if (view.Height is not DimAuto) { view.Height = Dim.Percent (75); } diff --git a/UnitTests/View/Layout/Dim.AutoTests.cs b/UnitTests/View/Layout/Dim.AutoTests.cs index 56f929253..afc97f014 100644 --- a/UnitTests/View/Layout/Dim.AutoTests.cs +++ b/UnitTests/View/Layout/Dim.AutoTests.cs @@ -451,7 +451,7 @@ public class DimAutoTests (ITestOutputHelper output) subView.Height = 0; // Tests nested Combine - subView.Height = 5 + new Dim.DimCombine (true, 3, new Dim.DimCombine (true, Dim.Percent (10), 9)); + subView.Height = 5 + new DimCombine (true, 3, new DimCombine (true, Dim.Percent (10), 9)); Assert.Throws (() => superView.SetRelativeLayout (new (0, 0))); } @@ -662,7 +662,7 @@ public class DimAutoTests (ITestOutputHelper output) Text = new string ('*', textLen), X = subX, Y = 0, - Width = Dim.Auto (Dim.DimAutoStyle.Text), + Width = Dim.Auto (DimAutoStyle.Text), Height = 1, ValidatePosDim = true }; @@ -701,7 +701,7 @@ public class DimAutoTests (ITestOutputHelper output) { X = subX, Y = 0, - Width = Dim.Auto (Dim.DimAutoStyle.Content), + Width = Dim.Auto (DimAutoStyle.Content), Height = 1, ValidatePosDim = true }; @@ -965,9 +965,9 @@ public class DimAutoTests (ITestOutputHelper output) var view = new View (); view.SetContentSize (new (10, 5)); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); Assert.Equal (10, calculatedWidth); } @@ -976,9 +976,9 @@ public class DimAutoTests (ITestOutputHelper output) public void DimAutoStyle_Content_IgnoresText_WhenContentSizeNotSet () { var view = new View () { Text = "This is a test" }; - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); Assert.Equal (0, calculatedWidth); // Assuming 0 is the default when no ContentSize or Subviews are set } @@ -990,9 +990,9 @@ public class DimAutoTests (ITestOutputHelper output) view.Add (new View () { Frame = new Rectangle (0, 0, 5, 5) }); // Smaller subview view.Add (new View () { Frame = new Rectangle (0, 0, 10, 10) }); // Larger subview - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); Assert.Equal (10, calculatedWidth); // Expecting the size of the largest subview } @@ -1016,10 +1016,10 @@ public class DimAutoTests (ITestOutputHelper output) }; view.Add (subview); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height); Assert.Equal (expectedSize, calculatedWidth); Assert.Equal (expectedSize, calculatedHeight); @@ -1044,10 +1044,10 @@ public class DimAutoTests (ITestOutputHelper output) subview.SetRelativeLayout (new (100, 100)); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height); Assert.Equal (expectedSize, calculatedWidth); Assert.Equal (expectedSize, calculatedHeight); @@ -1072,11 +1072,11 @@ public class DimAutoTests (ITestOutputHelper output) subview.SetRelativeLayout (new (100, 100)); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); // Assuming the view's size is 100x100 for calculation purposes - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height); Assert.Equal (expectedSize, calculatedWidth); Assert.Equal (expectedSize, calculatedHeight); @@ -1091,10 +1091,10 @@ public class DimAutoTests (ITestOutputHelper output) subview.SetRelativeLayout (new (100, 100)); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height); Assert.Equal (20, calculatedWidth); Assert.Equal (25, calculatedHeight); @@ -1111,10 +1111,10 @@ public class DimAutoTests (ITestOutputHelper output) subview.SetRelativeLayout (new (100, 100)); - var dim = Dim.Auto (Dim.DimAutoStyle.Content); + var dim = Dim.Auto (DimAutoStyle.Content); - int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height); // Expecting the size to match the subview, which is the largest Assert.Equal (30, calculatedWidth); @@ -1133,8 +1133,8 @@ public class DimAutoTests (ITestOutputHelper output) var dimWidth = Dim.Auto (); var dimHeight = Dim.Auto (); - int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height); // Expecting the size to include the subview's position and size Assert.Equal (30, calculatedWidth); // 10 (X position) + 20 (Width) @@ -1152,8 +1152,8 @@ public class DimAutoTests (ITestOutputHelper output) var dimHeight = Dim.Auto (); // Assuming the calculation is done after layout - int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height); // Expecting the size to include the subview's position as a percentage of the parent view's size plus the subview's size Assert.Equal (70, calculatedWidth); // 50% of 100 (Width) + 20 @@ -1171,8 +1171,8 @@ public class DimAutoTests (ITestOutputHelper output) var dimHeight = Dim.Auto (); // Assuming the calculation is done after layout - int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height); // Expecting the size to include the subview's position at the center of the parent view plus the subview's size Assert.Equal (70, calculatedWidth); // Centered in 100 (Width) + 20 @@ -1201,8 +1201,8 @@ public class DimAutoTests (ITestOutputHelper output) view.Add (subview); // Assuming the calculation is done after layout - int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width); - int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height); + int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width); + int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height); // Expecting the size to include the subview's position at the end of the parent view minus the offset plus the subview's size Assert.Equal (100, calculatedWidth); diff --git a/UnitTests/View/Layout/Dim.CombineTests.cs b/UnitTests/View/Layout/Dim.CombineTests.cs index a036196bc..45798cee5 100644 --- a/UnitTests/View/Layout/Dim.CombineTests.cs +++ b/UnitTests/View/Layout/Dim.CombineTests.cs @@ -14,7 +14,7 @@ public class DimCombineTests (ITestOutputHelper output) var dim1 = new DimAbsolute (10); var dim2 = new DimAbsolute (20); var dim = dim1 + dim2; - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (30, result); } diff --git a/UnitTests/View/Layout/Dim.FillTests.cs b/UnitTests/View/Layout/Dim.FillTests.cs index c4e15e748..ac9b9fa33 100644 --- a/UnitTests/View/Layout/Dim.FillTests.cs +++ b/UnitTests/View/Layout/Dim.FillTests.cs @@ -141,7 +141,7 @@ public class DimFillTests (ITestOutputHelper output) public void DimFill_Calculate_ReturnsCorrectValue () { var dim = Dim.Fill (); - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (100, result); } diff --git a/UnitTests/View/Layout/Dim.FunctionTests.cs b/UnitTests/View/Layout/Dim.FunctionTests.cs index b7c488088..1d4f19ee0 100644 --- a/UnitTests/View/Layout/Dim.FunctionTests.cs +++ b/UnitTests/View/Layout/Dim.FunctionTests.cs @@ -42,7 +42,7 @@ public class DimFunctionTests (ITestOutputHelper output) public void DimFunction_Calculate_ReturnsCorrectValue () { var dim = new DimFunc (() => 10); - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (10, result); } } diff --git a/UnitTests/View/Layout/Dim.PercentTests.cs b/UnitTests/View/Layout/Dim.PercentTests.cs index 7884b6189..75f150bb2 100644 --- a/UnitTests/View/Layout/Dim.PercentTests.cs +++ b/UnitTests/View/Layout/Dim.PercentTests.cs @@ -13,7 +13,7 @@ public class DimPercentTests public void DimFactor_Calculate_ReturnsCorrectValue () { var dim = new DimFactor (0.5f); - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (50, result); } diff --git a/UnitTests/View/Layout/Dim.Tests.cs b/UnitTests/View/Layout/Dim.Tests.cs index 95f4f994d..db7937be6 100644 --- a/UnitTests/View/Layout/Dim.Tests.cs +++ b/UnitTests/View/Layout/Dim.Tests.cs @@ -28,7 +28,7 @@ public class DimTests public void DimAbsolute_Calculate_ReturnsCorrectValue () { var dim = new DimAbsolute (10); - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (10, result); } @@ -38,7 +38,7 @@ public class DimTests { var view = new View { Width = 10 }; var dim = new DimView (view, Dimension.Width); - var result = dim.Calculate (0, 100, null, Dim.Dimension.None); + var result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (10, result); } @@ -345,24 +345,24 @@ public class DimTests [TestRespondersDisposed] public void Internal_Tests () { - var dimFactor = new Dim.DimFactor (0.10F); + var dimFactor = new DimFactor (0.10F); Assert.Equal (10, dimFactor.Anchor (100)); - var dimAbsolute = new Dim.DimAbsolute (10); + var dimAbsolute = new DimAbsolute (10); Assert.Equal (10, dimAbsolute.Anchor (0)); - var dimFill = new Dim.DimFill (1); + var dimFill = new DimFill (1); Assert.Equal (99, dimFill.Anchor (100)); - var dimCombine = new Dim.DimCombine (true, dimFactor, dimAbsolute); + var dimCombine = new DimCombine (true, dimFactor, dimAbsolute); Assert.Equal (dimCombine._left, dimFactor); Assert.Equal (dimCombine._right, dimAbsolute); Assert.Equal (20, dimCombine.Anchor (100)); var view = new View { Frame = new Rectangle (20, 10, 20, 1) }; - var dimViewHeight = new Dim.DimView (view, Dimension.Height); + var dimViewHeight = new DimView (view, Dimension.Height); Assert.Equal (1, dimViewHeight.Anchor (0)); - var dimViewWidth = new Dim.DimView (view, Dimension.Width); + var dimViewWidth = new DimView (view, Dimension.Width); Assert.Equal (20, dimViewWidth.Anchor (0)); view.Dispose (); @@ -584,8 +584,8 @@ public class DimTests v4.Height = Auto (DimAutoStyle.Text); Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Width); Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Height); - Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is Dim.DimAbsolute - Assert.Equal (1, v4.Frame.Height); // 1 because is Dim.DimAbsolute + Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is DimAbsolute + Assert.Equal (1, v4.Frame.Height); // 1 because is DimAbsolute v5.Text = "Button5"; diff --git a/UnitTests/View/TextTests.cs b/UnitTests/View/TextTests.cs index 7c5a15354..09f151e6e 100644 --- a/UnitTests/View/TextTests.cs +++ b/UnitTests/View/TextTests.cs @@ -1207,8 +1207,8 @@ Y { Text = "01234", TextDirection = TextDirection.LeftRight_TopBottom, - Width = Dim.Auto (Dim.DimAutoStyle.Text), - Height = Dim.Auto (Dim.DimAutoStyle.Text) + Width = Dim.Auto (DimAutoStyle.Text), + Height = Dim.Auto (DimAutoStyle.Text) }; Assert.Equal (new (0, 0, 5, 1), view.Frame); Assert.Equal (new (0, 0, 5, 1), view.Viewport); @@ -1229,7 +1229,7 @@ Y TextDirection = TextDirection.LeftRight_TopBottom, TextAlignment = TextAlignment.Centered, Width = 10, - Height = Dim.Auto (Dim.DimAutoStyle.Text) + Height = Dim.Auto (DimAutoStyle.Text) }; view.BeginInit (); view.EndInit (); @@ -1247,8 +1247,8 @@ Y { TextDirection = TextDirection.TopBottom_LeftRight, Text = "01234", - Width = Dim.Auto (Dim.DimAutoStyle.Text), - Height = Dim.Auto (Dim.DimAutoStyle.Text) + Width = Dim.Auto (DimAutoStyle.Text), + Height = Dim.Auto (DimAutoStyle.Text) }; Assert.Equal (new (0, 0, 1, 5), view.Frame); Assert.Equal (new (0, 0, 1, 5), view.Viewport); diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index ea1c8fab3..c7b5e73a5 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -136,8 +136,8 @@ public class CheckBoxTests public void Constructors_Defaults () { var ckb = new CheckBox (); - Assert.True (ckb.Width is Dim.DimAuto); - Assert.True (ckb.Height is Dim.DimAuto); + Assert.True (ckb.Width is DimAuto); + Assert.True (ckb.Height is DimAuto); Assert.False (ckb.Checked); Assert.False (ckb.AllowNullChecked); Assert.Equal (string.Empty, ckb.Text); @@ -146,8 +146,8 @@ public class CheckBoxTests Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame); ckb = new CheckBox { Text = "Test", Checked = true }; - Assert.True (ckb.Width is Dim.DimAuto); - Assert.True (ckb.Height is Dim.DimAuto); + Assert.True (ckb.Width is DimAuto); + Assert.True (ckb.Height is DimAuto); Assert.True (ckb.Checked); Assert.False (ckb.AllowNullChecked); Assert.Equal ("Test", ckb.Text); @@ -156,8 +156,8 @@ public class CheckBoxTests Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame); ckb = new CheckBox { Text = "Test", X = 1, Y = 2 }; - Assert.True (ckb.Width is Dim.DimAuto); - Assert.True (ckb.Height is Dim.DimAuto); + Assert.True (ckb.Width is DimAuto); + Assert.True (ckb.Height is DimAuto); Assert.False (ckb.Checked); Assert.False (ckb.AllowNullChecked); Assert.Equal ("Test", ckb.Text); @@ -166,8 +166,8 @@ public class CheckBoxTests Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame); ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true }; - Assert.True (ckb.Width is Dim.DimAuto); - Assert.True (ckb.Height is Dim.DimAuto); + Assert.True (ckb.Width is DimAuto); + Assert.True (ckb.Height is DimAuto); Assert.True (ckb.Checked); Assert.False (ckb.AllowNullChecked); Assert.Equal ("Test", ckb.Text); diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index afa445ace..66f5837fb 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -180,7 +180,7 @@ public class MenuBarTests menuBar = new MenuBar (); Assert.Equal (0, menuBar.X); Assert.Equal (0, menuBar.Y); - Assert.IsType (menuBar.Width); + Assert.IsType (menuBar.Width); Assert.Equal (1, menuBar.Height); Assert.Empty (menuBar.Menus); Assert.Equal (Colors.ColorSchemes ["Menu"], menuBar.ColorScheme); @@ -190,7 +190,7 @@ public class MenuBarTests menuBar = new MenuBar { Menus = [] }; Assert.Equal (0, menuBar.X); Assert.Equal (0, menuBar.Y); - Assert.IsType (menuBar.Width); + Assert.IsType (menuBar.Width); Assert.Equal (1, menuBar.Height); Assert.Empty (menuBar.Menus); Assert.Equal (Colors.ColorSchemes ["Menu"], menuBar.ColorScheme); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 866417008..2e1b2ae2e 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -394,8 +394,8 @@ public class ScrollViewTests var view = new View { ColorScheme = new ColorScheme { Normal = new Attribute (Color.Blue, Color.Yellow) }, - Width = Dim.Auto (Dim.DimAutoStyle.Text), - Height = Dim.Auto (Dim.DimAutoStyle.Text), + Width = Dim.Auto (DimAutoStyle.Text), + Height = Dim.Auto (DimAutoStyle.Text), Text = text }; sv.Add (view); diff --git a/UnitTests/Views/SliderTests.cs b/UnitTests/Views/SliderTests.cs index 5bbe631e1..7a8cb1a7a 100644 --- a/UnitTests/Views/SliderTests.cs +++ b/UnitTests/Views/SliderTests.cs @@ -156,8 +156,8 @@ public class SliderTests Assert.False (slider.ShowEndSpacing); Assert.Equal (SliderType.Single, slider.Type); Assert.Equal (0, slider.InnerSpacing); - Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Content), slider.Width); - Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Content), slider.Height); + Assert.Equal (Dim.Auto (DimAutoStyle.Content), slider.Width); + Assert.Equal (Dim.Auto (DimAutoStyle.Content), slider.Height); Assert.Equal (0, slider.FocusedOption); } @@ -503,8 +503,8 @@ public class SliderTests { Orientation = Orientation.Vertical, Type = SliderType.Multiple, - Width = Dim.Auto (Dim.DimAutoStyle.Content), - Height = Dim.Auto (Dim.DimAutoStyle.Content) + Width = Dim.Auto (DimAutoStyle.Content), + Height = Dim.Auto (DimAutoStyle.Content) }; view.Add (slider); view.BeginInit (); @@ -537,7 +537,7 @@ public class SliderTests { Orientation = Orientation.Vertical, Type = SliderType.Multiple, - Width = Dim.Auto (Dim.DimAutoStyle.Content), + Width = Dim.Auto (DimAutoStyle.Content), Height = 10 }; view.Add (slider); @@ -572,7 +572,7 @@ public class SliderTests Orientation = Orientation.Vertical, Type = SliderType.Multiple, Width = 10, - Height = Dim.Auto (Dim.DimAutoStyle.Content) + Height = Dim.Auto (DimAutoStyle.Content) }; view.Add (slider); view.BeginInit ();