mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 00:46:39 +01:00
PosFactor -> PosPercent (for consistency) and -> public
This commit is contained in:
@@ -303,7 +303,7 @@ public class Pos
|
||||
throw new ArgumentException ("Percent value must be between 0 and 100.");
|
||||
}
|
||||
|
||||
return new PosFactor (percent / 100);
|
||||
return new PosPercent (percent / 100);
|
||||
}
|
||||
|
||||
/// <summary>Creates a <see cref="Pos"/> object that tracks the Top (Y) position of the specified <see cref="View"/>.</summary>
|
||||
@@ -549,13 +549,27 @@ public class PosCombine (bool add, Pos left, Pos right) : Pos
|
||||
}
|
||||
}
|
||||
|
||||
internal class PosFactor (float factor) : Pos
|
||||
/// <summary>
|
||||
/// Represents a position that is a percentage of the width or height of the SuperView.
|
||||
/// </summary>
|
||||
/// <param name="factor"></param>
|
||||
public class PosPercent (float factor) : Pos
|
||||
{
|
||||
private readonly float _factor = factor;
|
||||
public override bool Equals (object other) { return other is PosFactor f && f._factor == _factor; }
|
||||
public override int GetHashCode () { return _factor.GetHashCode (); }
|
||||
public override string ToString () { return $"Factor({_factor})"; }
|
||||
internal override int Anchor (int width) { return (int)(width * _factor); }
|
||||
/// <summary>
|
||||
/// Gets the factor that represents the percentage of the width or height of the SuperView.
|
||||
/// </summary>
|
||||
public float Factor { get; } = factor;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals (object other) { return other is PosPercent f && f.Factor == Factor; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode () { return Factor.GetHashCode (); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString () { return $"Factor({Factor})"; }
|
||||
|
||||
internal override int Anchor (int width) { return (int)(width * Factor); }
|
||||
}
|
||||
|
||||
// Helper class to provide dynamic value by the execution of a function that returns an integer.
|
||||
|
||||
@@ -417,7 +417,7 @@ public class TileView : View
|
||||
/// </summary>
|
||||
public bool SetSplitterPos (int idx, Pos value)
|
||||
{
|
||||
if (!(value is PosAbsolute) && !(value is PosFactor))
|
||||
if (!(value is PosAbsolute) && !(value is PosPercent))
|
||||
{
|
||||
throw new ArgumentException (
|
||||
$"Only Percent and Absolute values are supported. Passed value was {value.GetType ().Name}"
|
||||
@@ -991,11 +991,11 @@ public class TileView : View
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Determines the absolute position of <paramref name="p"/> and returns a <see cref="PosFactor"/> that
|
||||
/// Determines the absolute position of <paramref name="p"/> and returns a <see cref="PosPercent"/> that
|
||||
/// describes the percentage of that.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Effectively turning any <see cref="Pos"/> into a <see cref="PosFactor"/> (as if created with
|
||||
/// Effectively turning any <see cref="Pos"/> into a <see cref="PosPercent"/> (as if created with
|
||||
/// <see cref="Pos.Percent(float)"/>)
|
||||
/// </para>
|
||||
/// </summary>
|
||||
@@ -1007,7 +1007,7 @@ public class TileView : View
|
||||
// calculate position in the 'middle' of the cell at p distance along parentLength
|
||||
float position = p.Anchor (parentLength) + 0.5f;
|
||||
|
||||
return new PosFactor (position / parentLength);
|
||||
return new PosPercent (position / parentLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1025,7 +1025,7 @@ public class TileView : View
|
||||
/// <param name="newValue"></param>
|
||||
private bool FinalisePosition (Pos oldValue, Pos newValue)
|
||||
{
|
||||
if (oldValue is PosFactor)
|
||||
if (oldValue is PosPercent)
|
||||
{
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PosTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void PosFactor_Calculate_ReturnsExpectedValue ()
|
||||
{
|
||||
var posFactor = new PosFactor (0.5f);
|
||||
var posFactor = new PosPercent (0.5f);
|
||||
var result = posFactor.Calculate (10, new DimAbsolute (2), null, Dimension.None);
|
||||
Assert.Equal (5, result);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ public class PosTests (ITestOutputHelper output)
|
||||
[TestRespondersDisposed]
|
||||
public void Internal_Tests ()
|
||||
{
|
||||
var posFactor = new PosFactor (0.10F);
|
||||
var posFactor = new PosPercent (0.10F);
|
||||
Assert.Equal (10, posFactor.Anchor (100));
|
||||
|
||||
var posAnchorEnd = new PosAnchorEnd (1);
|
||||
|
||||
@@ -1959,7 +1959,7 @@ public class TileViewTests
|
||||
{
|
||||
TileView tileView = Get11By3TileView (out LineView line);
|
||||
tileView.SetSplitterPos (0, Pos.Percent (50));
|
||||
Assert.IsType<PosFactor> (tileView.SplitterDistances.ElementAt (0));
|
||||
Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
|
||||
tileView.NewKeyDownEvent (new Key (tileView.ToggleResizable));
|
||||
|
||||
tileView.Draw ();
|
||||
@@ -1983,7 +1983,7 @@ public class TileViewTests
|
||||
TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
||||
|
||||
// Even when moving the splitter location it should stay a Percentage based one
|
||||
Assert.IsType<PosFactor> (tileView.SplitterDistances.ElementAt (0));
|
||||
Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
|
||||
|
||||
// and 2 to the left
|
||||
line.NewKeyDownEvent (Key.CursorLeft);
|
||||
@@ -1998,7 +1998,7 @@ public class TileViewTests
|
||||
TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
||||
|
||||
// Even when moving the splitter location it should stay a Percentage based one
|
||||
Assert.IsType<PosFactor> (tileView.SplitterDistances.ElementAt (0));
|
||||
Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user