diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs index 33af8f7fa..960c2302c 100644 --- a/Terminal.Gui/View/Layout/Dim.cs +++ b/Terminal.Gui/View/Layout/Dim.cs @@ -94,7 +94,7 @@ public enum Dimension /// /// /// -/// +/// /// /// /// Creates a object that computes the dimension by executing the provided @@ -143,8 +143,10 @@ public enum Dimension /// public class Dim { + #region static Dim creation methods + /// - /// Creates a object that automatically sizes the view to fit all the view's SubViews and/or Text. + /// Creates a object that automatically sizes the view to fit all the view's Content, Subviews, and/or Text. /// /// /// @@ -191,7 +193,7 @@ public class Dim /// /// The function to be executed. /// The returned from the function. - public static Dim Function (Func function) { return new DimFunc (function); } + public static Dim Func (Func function) { return new DimFunc (function); } /// Creates a object that tracks the Height of the specified . /// The height of the other . @@ -239,6 +241,47 @@ public class Dim /// The view that will be tracked. public static Dim Width (View view) { return new DimView (view, Dimension.Width); } + #endregion static Dim creation methods + + #region virtual methods + + /// + /// 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. + /// + /// The width of the area where the View is being sized (Superview.ContentSize). + /// + /// An integer representing the calculated dimension. The way this dimension is calculated depends on the specific + /// subclass of Dim that is used. For example, DimAbsolute returns a fixed dimension, DimFactor returns a + /// dimension that is a certain percentage of the super view's size, and so on. + /// + internal virtual int Anchor (int size) { return 0; } + + /// + /// 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. + /// + /// + /// The starting point from where the size calculation begins. It could be the left edge for width calculation or the + /// top edge for height calculation. + /// + /// The size of the SuperView's content. It could be width or height. + /// The View that holds this Pos object. + /// Width or Height + /// + /// The calculated size of the View. The way this size is calculated depends on the specific subclass of Dim that + /// is used. + /// + internal virtual int Calculate (int location, int superviewContentSize, View us, Dimension dimension) + { + return Math.Max (Anchor (superviewContentSize - location), 0); + } + + #endregion virtual methods + + #region operators + /// Adds a to a , yielding a new . /// The first to add. /// The second to add. @@ -281,38 +324,9 @@ public class Dim return newDim; } - /// - /// 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. - /// - /// The width of the area where the View is being sized (Superview.ContentSize). - /// - /// An integer representing the calculated dimension. The way this dimension is calculated depends on the specific - /// subclass of Dim that is used. For example, DimAbsolute returns a fixed dimension, DimFactor returns a - /// dimension that is a certain percentage of the super view's size, and so on. - /// - internal virtual int Anchor (int size) { return 0; } + #endregion operators - /// - /// 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. - /// - /// - /// The starting point from where the size calculation begins. It could be the left edge for width calculation or the - /// top edge for height calculation. - /// - /// The size of the SuperView's content. It could be width or height. - /// The View that holds this Pos object. - /// Width or Height - /// - /// The calculated size of the View. The way this size is calculated depends on the specific subclass of Dim that - /// is used. - /// - internal virtual int Calculate (int location, int superviewContentSize, View us, Dimension dimension) - { - return Math.Max (Anchor (superviewContentSize - location), 0); - } + #region overrides /// /// Diagnostics API to determine if this Dim object references other views. @@ -325,6 +339,8 @@ public class Dim /// public override int GetHashCode () { return Anchor (0).GetHashCode (); } + + #endregion overrides } /// @@ -332,8 +348,8 @@ public class Dim /// /// /// -/// This is a low-level API that is typically used internally by the layout system. Use the various static -/// methods on the class to create objects instead. +/// This is a low-level API that is typically used internally by the layout system. Use the various static +/// methods on the class to create objects instead. /// /// /// @@ -370,8 +386,8 @@ public class DimAbsolute (int size) : Dim /// See . /// /// -/// This is a low-level API that is typically used internally by the layout system. Use the various static -/// methods on the class to create objects instead. +/// This is a low-level API that is typically used internally by the layout system. Use the various static +/// methods on the class to create objects instead. /// /// /// diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 83b7d3da8..6ba57e02f 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -420,7 +420,7 @@ public class Buttons : Scenario // TODO: Use Dim.Auto for the Width and Height Height = 1; - Width = Dim.Function (() => Digits + 2); // button + 3 for number + button + Width = Dim.Func (() => Digits + 2); // button + 3 for number + button _down = new () { @@ -438,7 +438,7 @@ public class Buttons : Scenario Text = Value.ToString (), X = Pos.Right (_down), Y = Pos.Top (_down), - Width = Dim.Function (() => Digits), + Width = Dim.Func (() => Digits), Height = 1, TextAlignment = TextAlignment.Centered, CanFocus = true diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index da0768f4f..d76c0e1b2 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -627,7 +627,7 @@ public class DynamicMenuBar : Scenario X = Pos.Right (_btnPrevious) + 1, Y = Pos.Top (_btnPrevious), - Width = Dim.Fill () - Dim.Function (() => _btnAdd.Frame.Width + 1), + Width = Dim.Fill () - Dim.Func (() => _btnAdd.Frame.Width + 1), Height = 1 }; _frmMenu.Add (_lblMenuBar); diff --git a/UnitTests/View/Layout/Dim.AutoTests.cs b/UnitTests/View/Layout/Dim.AutoTests.cs index 276c79017..6221d1957 100644 --- a/UnitTests/View/Layout/Dim.AutoTests.cs +++ b/UnitTests/View/Layout/Dim.AutoTests.cs @@ -1086,7 +1086,7 @@ public class DimAutoTests (ITestOutputHelper output) public void With_Subview_Using_DimFunc () { var view = new View (); - var subview = new View () { Width = Dim.Function (() => 20), Height = Dim.Function (() => 25) }; + var subview = new View () { Width = Dim.Func (() => 20), Height = Dim.Func (() => 25) }; view.Add (subview); subview.SetRelativeLayout (new (100, 100)); diff --git a/UnitTests/View/Layout/Dim.FunctionTests.cs b/UnitTests/View/Layout/Dim.FunctionTests.cs index 1d4f19ee0..43207631c 100644 --- a/UnitTests/View/Layout/Dim.FunctionTests.cs +++ b/UnitTests/View/Layout/Dim.FunctionTests.cs @@ -14,12 +14,12 @@ public class DimFunctionTests (ITestOutputHelper output) Func f1 = () => 0; Func f2 = () => 0; - Dim dim1 = Dim.Function (f1); - Dim dim2 = Dim.Function (f2); + Dim dim1 = Dim.Func (f1); + Dim dim2 = Dim.Func (f2); Assert.Equal (dim1, dim2); f2 = () => 1; - dim2 = Dim.Function (f2); + dim2 = Dim.Func (f2); Assert.NotEqual (dim1, dim2); } @@ -27,7 +27,7 @@ public class DimFunctionTests (ITestOutputHelper output) public void DimFunction_SetsValue () { var text = "Test"; - Dim dim = Dim.Function (() => text.Length); + Dim dim = Dim.Func (() => text.Length); Assert.Equal ("DimFunc(4)", dim.ToString ()); text = "New Test"; diff --git a/UnitTests/View/Layout/Pos.AnchorEndTests.cs b/UnitTests/View/Layout/Pos.AnchorEndTests.cs index 7b8a7d218..16bba2cc6 100644 --- a/UnitTests/View/Layout/Pos.AnchorEndTests.cs +++ b/UnitTests/View/Layout/Pos.AnchorEndTests.cs @@ -204,7 +204,7 @@ public class PosAnchorEndTests (ITestOutputHelper output) // Dim.Fill (1) fills remaining space minus 1 (16 - 1 = 15) // Dim.Function (Btn_Width) is 6 // Width should be 15 - 6 = 9 - Width = Dim.Fill (1) - Dim.Function (Btn_Width), + Width = Dim.Fill (1) - Dim.Func (Btn_Width), Height = 1 }; diff --git a/UnitTests/View/Layout/SetRelativeLayoutTests.cs b/UnitTests/View/Layout/SetRelativeLayoutTests.cs index 7efbf1fba..f54772687 100644 --- a/UnitTests/View/Layout/SetRelativeLayoutTests.cs +++ b/UnitTests/View/Layout/SetRelativeLayoutTests.cs @@ -418,7 +418,7 @@ public class SetRelativeLayoutTests Assert.Equal (1, view.Frame.Height); var tf = new TextField { Text = "01234567890123456789" }; - tf.Width = Dim.Fill (1) - Dim.Function (GetViewWidth); + tf.Width = Dim.Fill (1) - Dim.Func (GetViewWidth); // tf will fill the screen minus 1 minus the width of view (3). // so it's width will be 26 (30 - 1 - 3).