diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs index cfb286b6c..7a9b47ef8 100644 --- a/Terminal.Gui/View/Layout/Dim.cs +++ b/Terminal.Gui/View/Layout/Dim.cs @@ -119,12 +119,18 @@ public abstract record Dim : IEqualityOperators Style: style); } + /// + /// Creates a object that fills the dimension, leaving no margin. + /// + /// The Fill dimension. + public static Dim? Fill () { return new DimFill (0); } + /// /// Creates a object that fills the dimension, leaving the specified margin. /// /// The Fill dimension. /// Margin to use. - public static Dim? Fill (int margin = 0) { return new DimFill (margin); } + public static Dim? Fill (Dim margin) { return new DimFill (margin); } /// /// Creates a function object that computes the dimension by executing the provided function. diff --git a/Terminal.Gui/View/Layout/DimFill.cs b/Terminal.Gui/View/Layout/DimFill.cs index 7550b87db..a32031ca5 100644 --- a/Terminal.Gui/View/Layout/DimFill.cs +++ b/Terminal.Gui/View/Layout/DimFill.cs @@ -9,10 +9,10 @@ namespace Terminal.Gui; /// methods on the class to create objects instead. /// /// The margin to not fill. -public record DimFill (int Margin) : Dim +public record DimFill (Dim Margin) : Dim { /// public override string ToString () { return $"Fill({Margin})"; } - internal override int GetAnchor (int size) { return size - Margin; } + internal override int GetAnchor (int size) { return size - Margin.GetAnchor(0); } } \ No newline at end of file diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index f8d28d471..1a9eec41d 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -32,7 +32,7 @@ internal class KeyBindingsDialog : Dialog _commandsListView = new ListView { Width = Dim.Percent (50), - Height = Dim.Fill () - Dim.Func (() => IsInitialized ? Subviews.First (view => view.Y.Has (out _)).Frame.Height : 1), + Height = Dim.Fill (Dim.Func (() => IsInitialized ? Subviews.First (view => view.Y.Has (out _)).Frame.Height : 1)), Source = new ListWrapper (_commands), SelectedItem = 0 }; diff --git a/UnitTests/View/Layout/Dim.FillTests.cs b/UnitTests/View/Layout/Dim.FillTests.cs index cdda3088d..9defdf8aa 100644 --- a/UnitTests/View/Layout/Dim.FillTests.cs +++ b/UnitTests/View/Layout/Dim.FillTests.cs @@ -127,15 +127,28 @@ public class DimFillTests (ITestOutputHelper output) { var testMargin = 0; Dim dim = Dim.Fill (); - Assert.Equal ($"Fill({testMargin})", dim.ToString ()); + Assert.Equal (testMargin, dim!.GetAnchor(0)); testMargin = 0; dim = Dim.Fill (testMargin); - Assert.Equal ($"Fill({testMargin})", dim.ToString ()); + Assert.Equal (testMargin, dim!.GetAnchor (0)); testMargin = 5; dim = Dim.Fill (testMargin); - Assert.Equal ($"Fill({testMargin})", dim.ToString ()); + Assert.Equal (-testMargin, dim!.GetAnchor (0)); + } + + [Fact] + public void DimFill_Margin_Is_Dim_SetsValue () + { + Dim testMargin = Dim.Func (() => 0); + Dim dim = Dim.Fill (testMargin); + Assert.Equal (0, dim!.GetAnchor (0)); + + + testMargin = Dim.Func (() => 5); + dim = Dim.Fill (testMargin); + Assert.Equal (-5, dim!.GetAnchor (0)); } [Fact] diff --git a/UnitTests/View/Layout/Dim.Tests.cs b/UnitTests/View/Layout/Dim.Tests.cs index a133ac27f..2ea62f244 100644 --- a/UnitTests/View/Layout/Dim.Tests.cs +++ b/UnitTests/View/Layout/Dim.Tests.cs @@ -315,7 +315,7 @@ public class DimTests Assert.Equal (49, f1.Frame.Width); // 50-1=49 Assert.Equal (5, f1.Frame.Height); - Assert.Equal ("Fill(0)", f2.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ()); Assert.Equal ("Absolute(5)", f2.Height.ToString ()); Assert.Equal (49, f2.Frame.Width); // 50-1=49 Assert.Equal (5, f2.Frame.Height); @@ -325,7 +325,7 @@ public class DimTests #else Assert.Equal ($"Combine(View(Width,FrameView(){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ()); #endif - Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ()); + Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ()); Assert.Equal (47, v1.Frame.Width); // 49-2=47 Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89 @@ -340,7 +340,7 @@ public class DimTests #endif ); #if DEBUG - Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); + Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ()); #else Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); #endif @@ -380,7 +380,7 @@ public class DimTests Assert.Equal (5, f1.Frame.Height); f2.Text = "Frame2"; - Assert.Equal ("Fill(0)", f2.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ()); Assert.Equal ("Absolute(5)", f2.Height.ToString ()); Assert.Equal (99, f2.Frame.Width); // 100-1=99 Assert.Equal (5, f2.Frame.Height); @@ -391,7 +391,7 @@ public class DimTests #else Assert.Equal ($"Combine(View(Width,FrameView(){f1.Frame})-Absolute(2))", v1.Width.ToString ()); #endif - Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ()); + Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ()); Assert.Equal (97, v1.Frame.Width); // 99-2=97 Assert.Equal (189, v1.Frame.Height); // 198-2-7=189 @@ -402,7 +402,7 @@ public class DimTests #else Assert.Equal ($"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))", v2.Width.ToString ()); #endif - Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); + Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ()); Assert.Equal (97, v2.Frame.Width); // 99-2=97 Assert.Equal (189, v2.Frame.Height); // 198-2-7=189 diff --git a/UnitTests/View/Layout/SetRelativeLayoutTests.cs b/UnitTests/View/Layout/SetRelativeLayoutTests.cs index 20fb45be8..60a47435a 100644 --- a/UnitTests/View/Layout/SetRelativeLayoutTests.cs +++ b/UnitTests/View/Layout/SetRelativeLayoutTests.cs @@ -37,11 +37,11 @@ public class SetRelativeLayoutTests Assert.Equal ("Absolute(1)", view.X.ToString ()); Assert.Equal ("Absolute(2)", view.Y.ToString ()); - Assert.Equal ("Fill(0)", view.Width.ToString ()); - Assert.Equal ("Fill(0)", view.Height.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Height.ToString ()); view.SetRelativeLayout (screen); - Assert.Equal ("Fill(0)", view.Width.ToString ()); - Assert.Equal ("Fill(0)", view.Height.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Height.ToString ()); } [Fact] @@ -50,7 +50,7 @@ public class SetRelativeLayoutTests var view = new View { X = 1, Y = 1, Width = Dim.Fill (), Height = Dim.Fill () }; view.SetRelativeLayout (new Size (80, 25)); - Assert.Equal ("Fill(0)", view.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Width.ToString ()); Assert.Equal (1, view.Frame.X); Assert.Equal (1, view.Frame.Y); Assert.Equal (79, view.Frame.Width); @@ -63,7 +63,7 @@ public class SetRelativeLayoutTests view.X = 0; view.Y = 0; Assert.Equal ("Absolute(0)", view.X.ToString ()); - Assert.Equal ("Fill(0)", view.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", view.Width.ToString ()); view.SetRelativeLayout (new Size (80, 25)); Assert.Equal (0, view.Frame.X); Assert.Equal (0, view.Frame.Y); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index ea6e656d8..ad758d752 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -10,8 +10,8 @@ public partial class ToplevelTests (ITestOutputHelper output) var top = new Toplevel (); Assert.Equal (Colors.ColorSchemes ["TopLevel"], top.ColorScheme); - Assert.Equal ("Fill(0)", top.Width.ToString ()); - Assert.Equal ("Fill(0)", top.Height.ToString ()); + Assert.Equal ("Fill(Absolute(0))", top.Width.ToString ()); + Assert.Equal ("Fill(Absolute(0))", top.Height.ToString ()); Assert.False (top.Running); Assert.False (top.Modal); Assert.Null (top.MenuBar);