From 56cd7b036b5ce0c004ade5b5ff9fa7f721399f96 Mon Sep 17 00:00:00 2001 From: Tig Date: Sat, 11 May 2024 09:16:17 -0600 Subject: [PATCH] Dim code cleanup - fix warnings --- Terminal.Gui/View/Layout/PosDim.cs | 25 +++++++++++++------------ Terminal.Gui/View/Layout/ViewLayout.cs | 8 ++++---- UICatalog/Scenarios/Dialogs.cs | 13 ------------- UnitTests/View/Layout/Pos.Tests.cs | 8 ++++---- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/Terminal.Gui/View/Layout/PosDim.cs b/Terminal.Gui/View/Layout/PosDim.cs index f86460c33..6466907f2 100644 --- a/Terminal.Gui/View/Layout/PosDim.cs +++ b/Terminal.Gui/View/Layout/PosDim.cs @@ -453,17 +453,18 @@ public class Pos internal class PosCombine (bool add, Pos left, Pos right) : Pos { - internal bool _add = add; - internal Pos _left = left, _right = right; + internal bool Add { get; set; } = add; + internal Pos Left { get; set; } = left; + internal Pos Right { get; set; } = right; - public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } + public override string ToString () { return $"Combine({Left}{(Add ? '+' : '-')}{Right})"; } internal override int Anchor (int width) { - int la = _left.Anchor (width); - int ra = _right.Anchor (width); + int la = Left.Anchor (width); + int ra = Right.Anchor (width); - if (_add) + if (Add) { return la + ra; } @@ -474,10 +475,10 @@ public class Pos internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newDimension = dim.Calculate (0, superviewDimension, us, dimension); - int left = _left.Calculate (superviewDimension, dim, us, dimension); - int right = _right.Calculate (superviewDimension, dim, us, dimension); + int left = Left.Calculate (superviewDimension, dim, us, dimension); + int right = Right.Calculate (superviewDimension, dim, us, dimension); - if (_add) + if (Add) { return left + right; } @@ -491,12 +492,12 @@ public class Pos /// internal override bool ReferencesOtherViews () { - if (_left.ReferencesOtherViews ()) + if (Left.ReferencesOtherViews ()) { return true; } - if (_right.ReferencesOtherViews ()) + if (Right.ReferencesOtherViews ()) { return true; } @@ -758,7 +759,7 @@ public class Pos /// /// -/// A Dim object describes the dimensions of a . Dim is the type of the +/// Describes the horizontal or vertical dimensions of a . Dim is the type of the /// and properties of . Dim objects enable /// Computed Layout (see ) to automatically manage the dimensions of a view. /// diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 5a0366452..5ade78eb2 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -917,8 +917,8 @@ public partial class View return; case Pos.PosCombine pc: - CollectPos (pc._left, from, ref nNodes, ref nEdges); - CollectPos (pc._right, from, ref nNodes, ref nEdges); + CollectPos (pc.Left, from, ref nNodes, ref nEdges); + CollectPos (pc.Right, from, ref nNodes, ref nEdges); break; } @@ -1105,8 +1105,8 @@ public partial class View case Pos pos and Pos.PosCombine: // Recursively check for not Absolute or not View - ThrowInvalid (view, (pos as Pos.PosCombine)._left, name); - ThrowInvalid (view, (pos as Pos.PosCombine)._right, name); + ThrowInvalid (view, (pos as Pos.PosCombine).Left, name); + ThrowInvalid (view, (pos as Pos.PosCombine).Right, name); break; diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 231d1ce70..151380e89 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -132,19 +132,6 @@ public class Dialogs : Scenario }; frame.Add (label); - static IEnumerable GetUniqueEnumNames () where T : Enum - { - var values = new HashSet (); - foreach (var name in Enum.GetNames (typeof (T))) - { - var value = (int)Enum.Parse (typeof (T), name); - if (values.Add (value)) - { - yield return name; - } - } - } - var labels = new [] { "Left", "Centered", "Right", "Justified", "FirstLeftRestRight", "LastRightRestLeft" }; var alignmentGroup = new RadioGroup { diff --git a/UnitTests/View/Layout/Pos.Tests.cs b/UnitTests/View/Layout/Pos.Tests.cs index bf82c4c0e..e95ff6ae1 100644 --- a/UnitTests/View/Layout/Pos.Tests.cs +++ b/UnitTests/View/Layout/Pos.Tests.cs @@ -225,13 +225,13 @@ public class PosTests (ITestOutputHelper output) Assert.Equal (10, posAbsolute.Anchor (0)); var posCombine = new Pos.PosCombine (true, posFactor, posAbsolute); - Assert.Equal (posCombine._left, posFactor); - Assert.Equal (posCombine._right, posAbsolute); + Assert.Equal (posCombine.Left, posFactor); + Assert.Equal (posCombine.Right, posAbsolute); Assert.Equal (20, posCombine.Anchor (100)); posCombine = new (true, posAbsolute, posFactor); - Assert.Equal (posCombine._left, posAbsolute); - Assert.Equal (posCombine._right, posFactor); + Assert.Equal (posCombine.Left, posAbsolute); + Assert.Equal (posCombine.Right, posFactor); Assert.Equal (20, posCombine.Anchor (100)); var view = new View { Frame = new (20, 10, 20, 1) };