diff --git a/Terminal.Gui/View/Layout/PosDim.cs b/Terminal.Gui/View/Layout/PosDim.cs index 58b485b71..f86460c33 100644 --- a/Terminal.Gui/View/Layout/PosDim.cs +++ b/Terminal.Gui/View/Layout/PosDim.cs @@ -7,7 +7,7 @@ namespace Terminal.Gui; /// /// Describes the horizontal or vertical position of a . The position can be an absolute value, /// a percentage, centered, a function, relative to the ending dimension, relative to another View, or aligned with a -/// set of views. +/// set of views. Pos objects enable Computed Layout (see ) to automatically manage the positions views. /// Integer values are implicitly convertible to an absolute . /// objects are created using the static methods provided (e.g. and ). /// The objects can be combined with the addition and subtraction operators. @@ -834,12 +834,15 @@ public class Pos /// public class Dim { + #region Static Methods - Create Dim objects + /// /// Specifies how will compute the dimension. /// [Flags] public enum DimAutoStyle { + // BUGBUG: This should not be a nested enum. Extract it. /// /// The dimension will be computed using both the view's and /// (whichever is larger). @@ -876,26 +879,6 @@ public class Dim 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. /// @@ -930,14 +913,6 @@ public class Dim return new DimAuto (style, min, max); } - /// Determines whether the specified object is equal to the current object. - /// The object to compare with the current object. - /// - /// if the specified object is equal to the current object; otherwise, - /// . - /// - public override bool Equals (object other) { return other is Dim abs && abs == this; } - /// /// Creates a object that fills the dimension, leaving the specified number of columns for a /// margin. @@ -963,48 +938,6 @@ public class Dim /// The view that will be tracked. public static Dim Height (View view) { return new DimView (view, Dimension.Height); } - /// Adds a to a , yielding a new . - /// The first to add. - /// The second to add. - /// The that is the sum of the values of left and right. - public static Dim operator + (Dim left, Dim right) - { - if (left is DimAbsolute && right is DimAbsolute) - { - return new DimAbsolute (left.Anchor (0) + right.Anchor (0)); - } - - var newDim = new DimCombine (true, left, right); - (left as DimView)?.Target.SetNeedsLayout (); - - return newDim; - } - - /// Creates an Absolute from the specified integer value. - /// The Absolute . - /// The value to convert to the pos. - public static implicit operator Dim (int n) { return new DimAbsolute (n); } - - /// - /// Subtracts a from a , yielding a new - /// . - /// - /// The to subtract from (the minuend). - /// The to subtract (the subtrahend). - /// The that is the left minus right. - public static Dim operator - (Dim left, Dim right) - { - if (left is DimAbsolute && right is DimAbsolute) - { - return new DimAbsolute (left.Anchor (0) - right.Anchor (0)); - } - - var newDim = new DimCombine (false, left, right); - (left as DimView)?.Target.SetNeedsLayout (); - - return newDim; - } - /// Creates a percentage object that is a percentage of the width or height of the SuperView. /// The percent object. /// A value between 0 and 100 representing the percentage. @@ -1046,6 +979,32 @@ public class Dim /// The view that will be tracked. public static Dim Width (View view) { return new DimView (view, Dimension.Width); } + #endregion Static Methods - Create Dim objects + + #region Methods + + /// + /// + internal enum Dimension + { + // BUGBUG: This should not be a nested enum. Extract it. + + /// + /// No dimension specified. + /// + None = 0, + + /// + /// The height dimension. + /// + Height = 1, + + /// + /// The width dimension. + /// + Width = 2 + } + /// /// Gets a dimension that is anchored to a certain point in the layout. /// This method is typically used internally by the layout system to determine the size of a View. @@ -1085,6 +1044,66 @@ public class Dim /// internal virtual bool ReferencesOtherViews () { return false; } + #endregion + + #region Operators + + /// Adds a to a , yielding a new . + /// The first to add. + /// The second to add. + /// The that is the sum of the values of left and right. + public static Dim operator + (Dim left, Dim right) + { + if (left is DimAbsolute && right is DimAbsolute) + { + return new DimAbsolute (left.Anchor (0) + right.Anchor (0)); + } + + var newDim = new DimCombine (true, left, right); + (left as DimView)?.Target.SetNeedsLayout (); + + return newDim; + } + + + /// Creates an Absolute from the specified integer value. + /// The Absolute . + /// The value to convert to the pos. + public static implicit operator Dim (int n) { return new DimAbsolute (n); } + + /// + /// Subtracts a from a , yielding a new + /// . + /// + /// The to subtract from (the minuend). + /// The to subtract (the subtrahend). + /// The that is the left minus right. + public static Dim operator - (Dim left, Dim right) + { + if (left is DimAbsolute && right is DimAbsolute) + { + return new DimAbsolute (left.Anchor (0) - right.Anchor (0)); + } + + var newDim = new DimCombine (false, left, right); + (left as DimView)?.Target.SetNeedsLayout (); + + return newDim; + } + #endregion + + #region Overrides + /// Determines whether the specified object is equal to the current object. + /// The object to compare with the current object. + /// + /// if the specified object is equal to the current object; otherwise, + /// . + /// + public override bool Equals (object other) { return other is Dim abs && abs == this; } + + #endregion Overrides + + #region Dim Types internal class DimAbsolute (int n) : Dim { private readonly int _n = n; @@ -1114,7 +1133,7 @@ public class Dim /// /// Specifies the minimum dimension that view will be automatically sized to. /// Specifies the maximum dimension that view will be automatically sized to. NOT CURRENTLY SUPPORTED. - public class DimAuto (DimAutoStyle style, Dim min, Dim max) : Dim + internal class DimAuto (DimAutoStyle style, Dim min, Dim max) : Dim { internal readonly Dim _max = max; internal readonly Dim _min = min; @@ -1359,4 +1378,5 @@ public class Dim internal override bool ReferencesOtherViews () { return true; } } + #endregion Dim Types } diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index 7bc069b02..513b7b813 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -180,6 +180,7 @@ public class CheckBox : View private string GetFormatterText () { + // BUGBUG: DimAuto is internal - do something else here. if (Width is Dim.DimAuto || string.IsNullOrEmpty (Title) || ContentSize?.Width <= 2) { return Text; diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index a3bde6eb2..cd3d7edb2 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -1265,6 +1265,7 @@ public class TabView : View tab.Margin.Thickness = new Thickness (0, 0, 0, 0); } + // BUGBUG: Dim.Anchor is internal. This should do something else to get the width. tab.Width = Math.Max (tab.Width.Anchor (0) - 1, 1); } else @@ -1280,6 +1281,7 @@ public class TabView : View tab.Margin.Thickness = new Thickness (0, 0, 0, 0); } + // BUGBUG: Dim.Anchor is internal. This should do something else to get the width. tab.Width = Math.Max (tab.Width.Anchor (0) - 1, 1); } diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index c4e9a8e3a..74dc5b01a 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -851,6 +851,7 @@ public class TileView : View { Dim spaceDim = Tile.ContentView.Width; + // BUGBUG: Dim.Anchor is internal. This should do something else to get the width. int spaceAbs = spaceDim.Anchor (Parent.Viewport.Width); var title = $" {Tile.Title} "; diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 2b8a6f37e..8e9a2a0d6 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -483,12 +483,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 null || view.Frame.Width == 0) { view.Width = Dim.Fill (); } - if (view.Width is not Dim.DimAuto && (view.Height is null || view.Frame.Height == 0)) + if (view.Height is null || view.Frame.Height == 0) { view.Height = Dim.Fill (); }