diff --git a/Terminal.Gui/View/Layout/Pos.cs b/Terminal.Gui/View/Layout/Pos.cs index 1f04bef15..89881c952 100644 --- a/Terminal.Gui/View/Layout/Pos.cs +++ b/Terminal.Gui/View/Layout/Pos.cs @@ -480,19 +480,38 @@ public class PosCenter : Pos } } -internal class PosCombine (bool add, Pos left, Pos right) : Pos +/// +/// Represents a position that is a combination of two other positions. +/// +/// +/// +/// +public class PosCombine (bool add, Pos left, Pos right) : Pos { - internal bool _add = add; - internal Pos _left = left, _right = right; + /// + /// Gets whether the two positions are added or subtracted. If , the positions are added, otherwise they are subtracted. + /// + public bool Add { get; } = add; - public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } + /// + /// Gets the left position. + /// + public new Pos Left { get; } = left; + + /// + /// Gets the right position. + /// + public new Pos Right { get; } = 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; } @@ -503,10 +522,10 @@ internal class PosCombine (bool add, Pos left, Pos right) : 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; } @@ -514,18 +533,14 @@ internal class PosCombine (bool add, Pos left, Pos right) : Pos return left - right; } - /// - /// Diagnostics API to determine if this Pos object references other views. - /// - /// internal override bool ReferencesOtherViews () { - if (_left.ReferencesOtherViews ()) + if (Left.ReferencesOtherViews ()) { return true; } - if (_right.ReferencesOtherViews ()) + if (Right.ReferencesOtherViews ()) { return true; } @@ -563,13 +578,13 @@ internal class PosView (View view, Side side) : Pos public override string ToString () { string sideString = side switch - { - Side.Left => "left", - Side.Top => "top", - Side.Right => "right", - Side.Bottom => "bottom", - _ => "unknown" - }; + { + Side.Left => "left", + Side.Top => "top", + Side.Right => "right", + Side.Bottom => "bottom", + _ => "unknown" + }; if (Target == null) { @@ -582,13 +597,13 @@ internal class PosView (View view, Side side) : Pos internal override int Anchor (int width) { return side switch - { - Side.Left => Target.Frame.X, - Side.Top => Target.Frame.Y, - Side.Right => Target.Frame.Right, - Side.Bottom => Target.Frame.Bottom, - _ => 0 - }; + { + Side.Left => Target.Frame.X, + Side.Top => Target.Frame.Y, + Side.Right => Target.Frame.Right, + Side.Bottom => Target.Frame.Bottom, + _ => 0 + }; } /// diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 77ff05924..ee5c0f135 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -924,8 +924,8 @@ public partial class View return; case 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; } @@ -1111,8 +1111,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; diff --git a/UnitTests/View/Layout/Pos.Tests.cs b/UnitTests/View/Layout/Pos.Tests.cs index 63e4290d4..3f842c53f 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 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) };