diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs
index 2e34dce41..424d165b0 100644
--- a/Terminal.Gui/View/Layout/Dim.cs
+++ b/Terminal.Gui/View/Layout/Dim.cs
@@ -168,14 +168,14 @@ public abstract class Dim
/// };
///
///
- public static Dim? Percent (int percent, bool usePosition = false)
+ public static Dim? Percent (int percent, DimPercentMode mode = DimPercentMode.ContentSize)
{
if (percent is < 0 /*or > 100*/)
{
throw new ArgumentException ("Percent value must be positive.");
}
- return new DimPercent (percent, usePosition);
+ return new DimPercent (percent, mode);
}
/// Creates a object that tracks the Width of the specified .
diff --git a/Terminal.Gui/View/Layout/DimPercent.cs b/Terminal.Gui/View/Layout/DimPercent.cs
index 89eb60729..af849c53f 100644
--- a/Terminal.Gui/View/Layout/DimPercent.cs
+++ b/Terminal.Gui/View/Layout/DimPercent.cs
@@ -9,15 +9,14 @@ namespace Terminal.Gui;
/// methods on the class to create objects instead.
///
/// The percentage.
-///
-/// If the dimension is computed using the View's position ( or
-/// ).
-/// If the dimension is computed using the View's .
+///
+/// If the dimension is computed using the View's position ( or
+/// ); otherwise, the dimension is computed using the View's .
///
-public class DimPercent (int percent, bool usePosition = false) : Dim
+public class DimPercent (int percent, DimPercentMode mode = DimPercentMode.ContentSize) : Dim
{
///
- public override bool Equals (object? other) { return other is DimPercent f && f.Percent == Percent && f.UsePosition == UsePosition; }
+ public override bool Equals (object? other) { return other is DimPercent f && f.Percent == Percent && f.Mode == Mode; }
///
public override int GetHashCode () { return Percent.GetHashCode (); }
@@ -30,17 +29,17 @@ public class DimPercent (int percent, bool usePosition = false) : Dim
///
///
///
- public override string ToString () { return $"Percent({Percent},{UsePosition})"; }
+ public override string ToString () { return $"Percent({Percent},{Mode})"; }
///
/// Gets whether the dimension is computed using the View's position or ContentSize.
///
- public bool UsePosition { get; } = usePosition;
+ public DimPercentMode Mode { get; } = mode;
internal override int GetAnchor (int size) { return (int)(size * (Percent / 100f)); }
internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension)
{
- return UsePosition ? Math.Max (GetAnchor (superviewContentSize - location), 0) : GetAnchor (superviewContentSize);
+ return Mode == DimPercentMode.Position ? Math.Max (GetAnchor (superviewContentSize - location), 0) : GetAnchor (superviewContentSize);
}
}
\ No newline at end of file
diff --git a/Terminal.Gui/View/Layout/DimPercentMode.cs b/Terminal.Gui/View/Layout/DimPercentMode.cs
new file mode 100644
index 000000000..ac4f38f2a
--- /dev/null
+++ b/Terminal.Gui/View/Layout/DimPercentMode.cs
@@ -0,0 +1,17 @@
+namespace Terminal.Gui;
+
+///
+/// Indicates the mode for a object.
+///
+public enum DimPercentMode
+{
+ ///
+ /// The dimension is computed using the View's position ( or ).
+ ///
+ Position = 0,
+
+ ///
+ /// The dimension is computed using the View's .
+ ///
+ ContentSize = 1
+}
\ No newline at end of file
diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs
index 8e012844a..bdc11c14f 100644
--- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs
+++ b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs
@@ -292,7 +292,7 @@ public class TextAlignmentsAndDirections : Scenario
{
X = Pos.Right (txtLabelTC) + 2,
Y = 1,
- Width = Dim.Percent (100, true),
+ Width = Dim.Percent (100, DimPercentMode.Position),
Height = Dim.Percent (33),
TextAlignment = TextAlignment.Right,
VerticalTextAlignment = VerticalTextAlignment.Top,
@@ -331,7 +331,7 @@ public class TextAlignmentsAndDirections : Scenario
{
X = Pos.X (txtLabelTR),
Y = Pos.Bottom (txtLabelTR) + 1,
- Width = Dim.Percent (100, true),
+ Width = Dim.Percent (100, DimPercentMode.Position),
Height = Dim.Percent (33),
TextAlignment = TextAlignment.Right,
VerticalTextAlignment = VerticalTextAlignment.Middle,
@@ -345,7 +345,7 @@ public class TextAlignmentsAndDirections : Scenario
X = Pos.X (txtLabelML),
Y = Pos.Bottom (txtLabelML) + 1,
Width = Dim.Width (txtLabelML),
- Height = Dim.Percent (100, true),
+ Height = Dim.Percent (100, DimPercentMode.Position),
TextAlignment = TextAlignment.Left,
VerticalTextAlignment = VerticalTextAlignment.Bottom,
ColorScheme = color1,
@@ -358,7 +358,7 @@ public class TextAlignmentsAndDirections : Scenario
X = Pos.X (txtLabelMC),
Y = Pos.Bottom (txtLabelMC) + 1,
Width = Dim.Width (txtLabelMC),
- Height = Dim.Percent (100, true),
+ Height = Dim.Percent (100, DimPercentMode.Position),
TextAlignment = TextAlignment.Centered,
VerticalTextAlignment = VerticalTextAlignment.Bottom,
ColorScheme = color1,
@@ -370,8 +370,8 @@ public class TextAlignmentsAndDirections : Scenario
{
X = Pos.X (txtLabelMR),
Y = Pos.Bottom (txtLabelMR) + 1,
- Width = Dim.Percent (100, true),
- Height = Dim.Percent (100, true),
+ Width = Dim.Percent (100, DimPercentMode.Position),
+ Height = Dim.Percent (100, DimPercentMode.Position),
TextAlignment = TextAlignment.Right,
VerticalTextAlignment = VerticalTextAlignment.Bottom,
ColorScheme = color1,
diff --git a/UICatalog/Scenarios/WindowsAndFrameViews.cs b/UICatalog/Scenarios/WindowsAndFrameViews.cs
index aa05aea93..f522420c6 100644
--- a/UICatalog/Scenarios/WindowsAndFrameViews.cs
+++ b/UICatalog/Scenarios/WindowsAndFrameViews.cs
@@ -121,7 +121,7 @@ public class WindowsAndFrameViews : Scenario
{
X = Pos.Percent (50),
Y = 1,
- Width = Dim.Percent (100, true), // Or Dim.Percent (50)
+ Width = Dim.Percent (100, DimPercentMode.Position), // Or Dim.Percent (50)
Height = 5,
ColorScheme = Colors.ColorSchemes ["Base"],
Text = "The Text in the FrameView",
diff --git a/UnitTests/View/Layout/Dim.PercentTests.cs b/UnitTests/View/Layout/Dim.PercentTests.cs
index fa3a7e0c8..d9fa64f8d 100644
--- a/UnitTests/View/Layout/Dim.PercentTests.cs
+++ b/UnitTests/View/Layout/Dim.PercentTests.cs
@@ -43,13 +43,13 @@ public class DimPercentTests
Assert.Equal (dim1, dim2);
n1 = n2 = 30;
- dim1 = Dim.Percent (n1, true);
- dim2 = Dim.Percent (n2, true);
+ dim1 = Dim.Percent (n1, DimPercentMode.Position);
+ dim2 = Dim.Percent (n2, DimPercentMode.Position);
Assert.Equal (dim1, dim2);
n1 = n2 = 30;
dim1 = Dim.Percent (n1);
- dim2 = Dim.Percent (n2, true);
+ dim2 = Dim.Percent (n2, DimPercentMode.Position);
Assert.NotEqual (dim1, dim2);
n1 = 0;
@@ -76,20 +76,20 @@ public class DimPercentTests
}
[Theory]
- [InlineData (0, false, true, 12)]
- [InlineData (0, false, false, 12)]
- [InlineData (1, false, true, 12)]
- [InlineData (1, false, false, 12)]
- [InlineData (2, false, true, 12)]
- [InlineData (2, false, false, 12)]
+ [InlineData (0, DimPercentMode.ContentSize, true, 12)]
+ [InlineData (0, DimPercentMode.ContentSize, false, 12)]
+ [InlineData (1, DimPercentMode.ContentSize, true, 12)]
+ [InlineData (1, DimPercentMode.ContentSize, false, 12)]
+ [InlineData (2, DimPercentMode.ContentSize, true, 12)]
+ [InlineData (2, DimPercentMode.ContentSize, false, 12)]
- [InlineData (0, true, true, 12)]
- [InlineData (0, true, false, 12)]
- [InlineData (1, true, true, 12)]
- [InlineData (1, true, false, 12)]
- [InlineData (2, true, true, 11)]
- [InlineData (2, true, false, 11)]
- public void DimPercent_Position (int position, bool usePosition, bool width, int expected)
+ [InlineData (0, DimPercentMode.Position, true, 12)]
+ [InlineData (0, DimPercentMode.Position, false, 12)]
+ [InlineData (1, DimPercentMode.Position, true, 12)]
+ [InlineData (1, DimPercentMode.Position, false, 12)]
+ [InlineData (2, DimPercentMode.Position, true, 11)]
+ [InlineData (2, DimPercentMode.Position, false, 11)]
+ public void DimPercent_Position (int position, DimPercentMode mode, bool width, int expected)
{
var super = new View { Width = 25, Height = 25 };
@@ -97,8 +97,8 @@ public class DimPercentTests
{
X = width ? position : 0,
Y = width ? 0 : position,
- Width = width ? Dim.Percent (50, usePosition) : 1,
- Height = width ? 1 : Dim.Percent (50, usePosition)
+ Width = width ? Dim.Percent (50, mode) : 1,
+ Height = width ? 1 : Dim.Percent (50, mode)
};
super.Add (view);
@@ -168,7 +168,7 @@ public class DimPercentTests
public void DimPercent_SetsValue (int percent)
{
Dim dim = Dim.Percent (percent);
- Assert.Equal ($"Percent({percent},{false})", dim.ToString ());
+ Assert.Equal ($"Percent({percent},ContentSize)", dim.ToString ());
}
}
diff --git a/UnitTests/View/Layout/Dim.Tests.cs b/UnitTests/View/Layout/Dim.Tests.cs
index 1ac2227a4..9a6ce3e03 100644
--- a/UnitTests/View/Layout/Dim.Tests.cs
+++ b/UnitTests/View/Layout/Dim.Tests.cs
@@ -385,8 +385,8 @@ public class DimTests
{
X = Pos.X (f2),
Y = Pos.Bottom (f2) + 2,
- Width = Dim.Percent (20, true),
- Height = Dim.Percent (20, true),
+ Width = Dim.Percent (20, DimPercentMode.Position),
+ Height = Dim.Percent (20, DimPercentMode.Position),
ValidatePosDim = true,
Text = "v6"
};
@@ -401,7 +401,6 @@ public class DimTests
Assert.Equal (100, w.Frame.Width);
Assert.Equal (100, w.Frame.Height);
- Assert.Equal ("Percent(50,False)", f1.Width.ToString ());
Assert.Equal ("Absolute(5)", f1.Height.ToString ());
Assert.Equal (49, f1.Frame.Width); // 50-1=49
Assert.Equal (5, f1.Frame.Height);