diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs
index 72bb1e342..0d2526dcb 100644
--- a/Terminal.Gui/View/Layout/Dim.cs
+++ b/Terminal.Gui/View/Layout/Dim.cs
@@ -1,5 +1,5 @@
+#nullable enable
using System.Diagnostics;
-using System.Drawing;
namespace Terminal.Gui;
@@ -149,7 +149,7 @@ public class Dim
/// Creates an Absolute from the specified integer value.
/// The Absolute .
/// The value to convert to the .
- public static Dim Absolute (int size) { return new DimAbsolute (size); }
+ public static Dim? Absolute (int size) { return new DimAbsolute (size); }
///
/// Creates a object that automatically sizes the view to fit all the view's Content, Subviews, and/or Text.
@@ -175,7 +175,7 @@ public class Dim
///
/// 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 static Dim Auto (DimAutoStyle style = DimAutoStyle.Auto, Dim minimumContentDim = null, Dim maximumContentDim = null)
+ public static Dim? Auto (DimAutoStyle style = DimAutoStyle.Auto, Dim? minimumContentDim = null, Dim? maximumContentDim = null)
{
//if (maximumContentDim != null)
//{
@@ -190,7 +190,7 @@ public class Dim
///
/// The Fill dimension.
/// Margin to use.
- public static Dim Fill (int margin = 0) { return new DimFill (margin); }
+ public static Dim? Fill (int margin = 0) { return new DimFill (margin); }
///
/// Creates a function object that computes the dimension by executing the provided function.
@@ -226,7 +226,7 @@ public class Dim
/// };
///
///
- public static Dim Percent (float percent, bool usePosition = false)
+ public static Dim? Percent (float percent, bool usePosition = false)
{
if (percent is < 0 or > 100)
{
@@ -249,7 +249,7 @@ public class Dim
/// 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).
+ /// 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
@@ -286,7 +286,7 @@ public class Dim
/// 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)
+ public static Dim operator + (Dim? left, Dim? right)
{
if (left is DimAbsolute && right is DimAbsolute)
{
@@ -311,7 +311,7 @@ public class Dim
/// 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)
+ public static Dim operator - (Dim? left, Dim? right)
{
if (left is DimAbsolute && right is DimAbsolute)
{
@@ -335,7 +335,7 @@ public class Dim
internal virtual bool ReferencesOtherViews () { return false; }
///
- public override bool Equals (object other) { return other is Dim abs && abs == this; }
+ public override bool Equals (object? other) { return other is Dim abs && abs == this; }
///
public override int GetHashCode () { return Anchor (0).GetHashCode (); }
@@ -356,7 +356,7 @@ public class Dim
public class DimAbsolute (int size) : Dim
{
///
- public override bool Equals (object other) { return other is DimAbsolute abs && abs.Size == Size; }
+ public override bool Equals (object? other) { return other is DimAbsolute abs && abs.Size == Size; }
///
public override int GetHashCode () { return Size.GetHashCode (); }
@@ -395,10 +395,10 @@ public class DimAbsolute (int size) : Dim
///
/// 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
+public class DimAuto (DimAutoStyle style, Dim? minimumContentDim, Dim? maximumContentDim) : Dim
{
///
- public override bool Equals (object other)
+ public override bool Equals (object? other)
{
return other is DimAuto auto && auto.MinimumContentDim == MinimumContentDim && auto.MaximumContentDim == MaximumContentDim && auto.Style == Style;
}
@@ -409,12 +409,12 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
///
/// Gets the maximum dimension the View's ContentSize will be fit to. NOT CURRENTLY SUPPORTED.
///
- public Dim MaximumContentDim { get; } = maximumContentDim;
+ public Dim? MaximumContentDim { get; } = maximumContentDim;
///
/// Gets the minimum dimension the View's ContentSize will be constrained to.
///
- public Dim MinimumContentDim { get; } = minimumContentDim;
+ public Dim? MinimumContentDim { get; } = minimumContentDim;
///
/// Gets the style of the DimAuto.
@@ -571,7 +571,7 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
///
/// The left dimension.
/// The right dimension.
-public class DimCombine (bool add, Dim left, Dim right) : Dim
+public class DimCombine (bool add, Dim? left, Dim? right) : Dim
{
///
/// Gets whether the two dimensions are added or subtracted.
@@ -581,20 +581,20 @@ public class DimCombine (bool add, Dim left, Dim right) : Dim
///
/// Gets the left dimension.
///
- public Dim Left { get; } = left;
+ public Dim? Left { get; } = left;
///
/// Gets the right dimension.
///
- public Dim Right { get; } = right;
+ public Dim? Right { get; } = right;
///
public override string ToString () { return $"Combine({Left}{(Add ? '+' : '-')}{Right})"; }
internal override int Anchor (int size)
{
- int la = Left.Anchor (size);
- int ra = Right.Anchor (size);
+ int la = Left!.Anchor (size);
+ int ra = Right!.Anchor (size);
if (Add)
{
@@ -606,8 +606,8 @@ public class DimCombine (bool add, Dim left, Dim right) : Dim
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 leftNewDim = Left!.Calculate (location, superviewContentSize, us, dimension);
+ int rightNewDim = Right!.Calculate (location, superviewContentSize, us, dimension);
int newDimension;
@@ -629,12 +629,12 @@ public class DimCombine (bool add, Dim left, Dim right) : Dim
///
internal override bool ReferencesOtherViews ()
{
- if (Left.ReferencesOtherViews ())
+ if (Left!.ReferencesOtherViews ())
{
return true;
}
- if (Right.ReferencesOtherViews ())
+ if (Right!.ReferencesOtherViews ())
{
return true;
}
@@ -659,7 +659,7 @@ public class DimCombine (bool add, Dim left, Dim right) : Dim
public class DimPercent (float percent, bool usePosition = false) : 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.UsePosition == UsePosition; }
///
public override int GetHashCode () { return Percent.GetHashCode (); }
@@ -698,7 +698,7 @@ public class DimPercent (float percent, bool usePosition = false) : Dim
public class DimFill (int margin) : Dim
{
///
- public override bool Equals (object other) { return other is DimFill fill && fill.Margin == Margin; }
+ public override bool Equals (object? other) { return other is DimFill fill && fill.Margin == Margin; }
///
public override int GetHashCode () { return Margin.GetHashCode (); }
@@ -725,7 +725,7 @@ public class DimFill (int margin) : Dim
public class DimFunc (Func dim) : Dim
{
///
- public override bool Equals (object other) { return other is DimFunc f && f.Func () == Func (); }
+ public override bool Equals (object? other) { return other is DimFunc f && f.Func () == Func (); }
///
/// Gets the function that computes the dimension.
@@ -767,7 +767,7 @@ public class DimView : Dim
public Dimension Dimension { get; }
///
- public override bool Equals (object other) { return other is DimView abs && abs.Target == Target && abs.Dimension == Dimension; }
+ public override bool Equals (object? other) { return other is DimView abs && abs.Target == Target && abs.Dimension == Dimension; }
///
public override int GetHashCode () { return Target.GetHashCode (); }
diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs
index d9e4fab95..e0ca37eb4 100644
--- a/Terminal.Gui/View/Layout/ViewLayout.cs
+++ b/Terminal.Gui/View/Layout/ViewLayout.cs
@@ -1,3 +1,4 @@
+#nullable enable
using System.Diagnostics;
using Microsoft.CodeAnalysis;
@@ -240,7 +241,7 @@ public partial class View
}
}
- private Dim _height = Dim.Absolute (0);
+ private Dim? _height = Dim.Absolute (0);
/// Gets or sets the height dimension of the view.
/// The object representing the height of the view (the number of rows).
@@ -264,7 +265,7 @@ public partial class View
///
/// The default value is Dim.Sized (0).
///
- public Dim Height
+ public Dim? Height
{
get => VerifyIsInitialized (_height, nameof (Height));
set
@@ -286,7 +287,7 @@ public partial class View
}
}
- private Dim _width = Dim.Absolute (0);
+ private Dim? _width = Dim.Absolute (0);
/// Gets or sets the width dimension of the view.
/// The object representing the width of the view (the number of columns).
@@ -310,7 +311,7 @@ public partial class View
///
/// The default value is Dim.Sized (0).
///
- public Dim Width
+ public Dim? Width
{
get => VerifyIsInitialized (_width, nameof (Width));
set
@@ -394,7 +395,6 @@ public partial class View
/// if the specified SuperView-relative coordinates are within the View.
public virtual bool Contains (in Point location) { return Frame.Contains (location); }
-#nullable enable
/// Finds the first Subview of that is visible at the provided location.
///
///
@@ -469,8 +469,6 @@ public partial class View
return null;
}
-#nullable restore
-
///
/// Gets a new location of the that is within the Viewport of the 's
/// (e.g. for dragging a Window). The `out` parameters are the new X and Y coordinates.
@@ -501,7 +499,7 @@ public partial class View
{
int maxDimension;
View superView;
- statusBar = null;
+ statusBar = null!;
if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
{
@@ -511,11 +509,11 @@ public partial class View
else
{
// Use the SuperView's Viewport, not Frame
- maxDimension = viewToMove.SuperView.Viewport.Width;
+ maxDimension = viewToMove!.SuperView.Viewport.Width;
superView = viewToMove.SuperView;
}
- if (superView?.Margin is { } && superView == viewToMove.SuperView)
+ if (superView?.Margin is { } && superView == viewToMove!.SuperView)
{
maxDimension -= superView.GetAdornmentsThickness ().Left + superView.GetAdornmentsThickness ().Right;
}
@@ -545,7 +543,7 @@ public partial class View
}
else
{
- View t = viewToMove.SuperView;
+ View t = viewToMove!.SuperView;
while (t is { } and not Toplevel)
{
@@ -572,21 +570,21 @@ public partial class View
if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
{
statusVisible = Application.Top?.StatusBar?.Visible == true;
- statusBar = Application.Top?.StatusBar;
+ statusBar = Application.Top?.StatusBar!;
}
else
{
- View t = viewToMove.SuperView;
+ View t = viewToMove!.SuperView;
while (t is { } and not Toplevel)
{
t = t.SuperView;
}
- if (t is Toplevel toplevel)
+ if (t is Toplevel topLevel)
{
- statusVisible = toplevel.StatusBar?.Visible == true;
- statusBar = toplevel.StatusBar;
+ statusVisible = topLevel.StatusBar?.Visible == true;
+ statusBar = topLevel.StatusBar!;
}
}
@@ -596,7 +594,7 @@ public partial class View
}
else
{
- maxDimension = statusVisible ? viewToMove.SuperView.Viewport.Height - 1 : viewToMove.SuperView.Viewport.Height;
+ maxDimension = statusVisible ? viewToMove!.SuperView.Viewport.Height - 1 : viewToMove!.SuperView.Viewport.Height;
}
if (superView?.Margin is { } && superView == viewToMove?.SuperView)
@@ -620,7 +618,7 @@ public partial class View
//System.Diagnostics.Debug.WriteLine ($"ny:{ny}, rHeight:{rHeight}");
- return superView;
+ return superView!;
}
/// Fired after the View's method has completed.
@@ -868,7 +866,7 @@ public partial class View
internal void CollectAll (View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges)
{
- foreach (View v in from.InternalSubviews)
+ foreach (View? v in from.InternalSubviews)
{
nNodes.Add (v);
@@ -884,7 +882,7 @@ public partial class View
}
}
- internal void CollectDim (Dim dim, View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges)
+ internal void CollectDim (Dim? dim, View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges)
{
switch (dim)
{
@@ -1042,7 +1040,7 @@ public partial class View
}
// Diagnostics to highlight when Width or Height is read before the view has been initialized
- private Dim VerifyIsInitialized (Dim dim, string member)
+ private Dim? VerifyIsInitialized (Dim? dim, string member)
{
//#if DEBUG
// if (dim.ReferencesOtherViews () && !IsInitialized)
@@ -1100,9 +1098,9 @@ public partial class View
return;
- void ThrowInvalid (View view, object checkPosDim, string name)
+ void ThrowInvalid (View view, object? checkPosDim, string name)
{
- object bad = null;
+ object? bad = null;
switch (checkPosDim)
{
@@ -1116,8 +1114,8 @@ public partial class View
case Pos pos and PosCombine:
// Recursively check for not Absolute or not View
- ThrowInvalid (view, (pos as PosCombine).Left, name);
- ThrowInvalid (view, (pos as PosCombine).Right, name);
+ ThrowInvalid (view, (pos as PosCombine)?.Left, name);
+ ThrowInvalid (view, (pos as PosCombine)?.Right, name);
break;
@@ -1134,8 +1132,8 @@ public partial class View
case Dim dim and DimCombine:
// Recursively check for not Absolute or not View
- ThrowInvalid (view, (dim as DimCombine).Left, name);
- ThrowInvalid (view, (dim as DimCombine).Right, name);
+ ThrowInvalid (view, (dim as DimCombine)?.Left, name);
+ ThrowInvalid (view, (dim as DimCombine)?.Right, name);
break;
}
diff --git a/UnitTests/View/Layout/Dim.AutoTests.cs b/UnitTests/View/Layout/Dim.AutoTests.cs
index e020a9305..f33d0744c 100644
--- a/UnitTests/View/Layout/Dim.AutoTests.cs
+++ b/UnitTests/View/Layout/Dim.AutoTests.cs
@@ -1002,7 +1002,6 @@ public class DimAutoTests (ITestOutputHelper output)
[Theory]
[InlineData (0, 15, 15)]
[InlineData (1, 15, 16)]
- [InlineData (0, 15, 15)]
[InlineData (-1, 15, 14)]
public void With_Subview_Using_DimAbsolute (int subViewOffset, int dimAbsoluteSize, int expectedSize)
{
diff --git a/UnitTests/View/Layout/Dim.PercentTests.cs b/UnitTests/View/Layout/Dim.PercentTests.cs
index 6f9f778b1..095a96f0d 100644
--- a/UnitTests/View/Layout/Dim.PercentTests.cs
+++ b/UnitTests/View/Layout/Dim.PercentTests.cs
@@ -7,7 +7,7 @@ namespace Terminal.Gui.LayoutTests;
public class DimPercentTests
{
- private readonly ITestOutputHelper _output;
+ //private readonly ITestOutputHelper _output;
[Fact]
public void DimFactor_Calculate_ReturnsCorrectValue ()
diff --git a/UnitTests/View/Layout/Pos.Tests.cs b/UnitTests/View/Layout/Pos.Tests.cs
index aea3f9b33..00cfecb23 100644
--- a/UnitTests/View/Layout/Pos.Tests.cs
+++ b/UnitTests/View/Layout/Pos.Tests.cs
@@ -4,7 +4,7 @@ using static Terminal.Gui.Pos;
namespace Terminal.Gui.LayoutTests;
-public class PosTests (ITestOutputHelper output)
+public class PosTests ()
{
// Was named AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
// but doesn't actually have anything to do with AutoSize.