PosFunc -> public

This commit is contained in:
Tig
2024-05-14 19:24:58 -07:00
parent dbd575eb58
commit 643f2a7a43
5 changed files with 38 additions and 25 deletions

View File

@@ -544,7 +544,7 @@ internal class DimFactor (float factor, bool remaining = false) : Dim
public override bool Equals (object other) { return other is DimFactor f && f._factor == _factor && f._remaining == _remaining; }
public override int GetHashCode () { return _factor.GetHashCode (); }
public bool IsFromRemaining () { return _remaining; }
public override string ToString () { return $"Factor({_factor},{_remaining})"; }
public override string ToString () { return $"Percent({_factor},{_remaining})"; }
internal override int Anchor (int width) { return (int)(width * _factor); }
internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension)

View File

@@ -567,19 +567,32 @@ public class PosPercent (float factor) : Pos
public override int GetHashCode () { return Factor.GetHashCode (); }
/// <inheritdoc />
public override string ToString () { return $"Factor({Factor})"; }
public override string ToString () { return $"Percent({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.
internal class PosFunc (Func<int> n) : Pos
/// <summary>
/// Represents a position that is computed by executing a function that returns an integer position.
/// </summary>
/// <param name="pos">The position.</param>
public class PosFunc (Func<int> pos) : Pos
{
private readonly Func<int> _function = n;
public override bool Equals (object other) { return other is PosFunc f && f._function () == _function (); }
public override int GetHashCode () { return _function.GetHashCode (); }
public override string ToString () { return $"PosFunc({_function ()})"; }
internal override int Anchor (int width) { return _function (); }
/// <summary>
/// Gets the function that computes the position.
/// </summary>
public Func<int> Func { get; } = pos;
/// <inheritdoc />
public override bool Equals (object other) { return other is PosFunc f && f.Func () == Func (); }
/// <inheritdoc />
public override int GetHashCode () { return Func.GetHashCode (); }
/// <inheritdoc />
public override string ToString () { return $"PosFunc({Func ()})"; }
internal override int Anchor (int width) { return Func (); }
}
internal class PosView (View view, Side side) : Pos

View File

@@ -163,13 +163,13 @@ public class DimPercentTests
{
float f = 0;
Dim dim = Dim.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
Assert.Equal ($"Percent({f / 100:0.###},{false})", dim.ToString ());
f = 0.5F;
dim = Dim.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
Assert.Equal ($"Percent({f / 100:0.###},{false})", dim.ToString ());
f = 100;
dim = Dim.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
Assert.Equal ($"Percent({f / 100:0.###},{false})", dim.ToString ());
}
}

View File

@@ -468,7 +468,7 @@ public class DimTests
Assert.Equal (100, w.Frame.Width);
Assert.Equal (100, w.Frame.Height);
Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ());
Assert.Equal ("Percent(0.5,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);
@@ -505,8 +505,8 @@ public class DimTests
Assert.Equal (47, v2.Frame.Width); // 49-2=47
Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
Assert.Equal ("Factor(0.1,False)", v3.Width.ToString ());
Assert.Equal ("Factor(0.1,False)", v3.Height.ToString ());
Assert.Equal ("Percent(0.1,False)", v3.Width.ToString ());
Assert.Equal ("Percent(0.1,False)", v3.Height.ToString ());
Assert.Equal (9, v3.Frame.Width); // 98*10%=9
Assert.Equal (9, v3.Frame.Height); // 98*10%=9
@@ -522,8 +522,8 @@ public class DimTests
Assert.Equal (38, v5.Frame.Width); // 47-9=38
Assert.Equal (80, v5.Frame.Height); // 89-9=80
Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ());
Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ());
Assert.Equal ("Percent(0.2,True)", v6.Width.ToString ());
Assert.Equal ("Percent(0.2,True)", v6.Height.ToString ());
Assert.Equal (9, v6.Frame.Width); // 47*20%=9
Assert.Equal (18, v6.Frame.Height); // 89*20%=18
@@ -538,7 +538,7 @@ public class DimTests
Assert.Equal (200, w.Frame.Height);
f1.Text = "Frame1";
Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ());
Assert.Equal ("Percent(0.5,False)", f1.Width.ToString ());
Assert.Equal ("Absolute(5)", f1.Height.ToString ());
Assert.Equal (99, f1.Frame.Width); // 100-1=99
Assert.Equal (5, f1.Frame.Height);
@@ -571,8 +571,8 @@ public class DimTests
Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
v3.Text = "Button3";
Assert.Equal ("Factor(0.1,False)", v3.Width.ToString ());
Assert.Equal ("Factor(0.1,False)", v3.Height.ToString ());
Assert.Equal ("Percent(0.1,False)", v3.Width.ToString ());
Assert.Equal ("Percent(0.1,False)", v3.Height.ToString ());
// 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
Assert.Equal (19, v3.Frame.Width);
@@ -601,8 +601,8 @@ public class DimTests
Assert.Equal (170, v5.Frame.Height); // 189-19=170
v6.Text = "Button6";
Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ());
Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ());
Assert.Equal ("Percent(0.2,True)", v6.Width.ToString ());
Assert.Equal ("Percent(0.2,True)", v6.Height.ToString ());
Assert.Equal (19, v6.Frame.Width); // 99*20%=19
Assert.Equal (38, v6.Frame.Height); // 198-7*20=18
};

View File

@@ -52,13 +52,13 @@ public class PosPercentTests (ITestOutputHelper output)
{
float f = 0;
Pos pos = Pos.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
Assert.Equal ($"Percent({f / 100:0.###})", pos.ToString ());
f = 0.5F;
pos = Pos.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
Assert.Equal ($"Percent({f / 100:0.###})", pos.ToString ());
f = 100;
pos = Pos.Percent (f);
Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
Assert.Equal ($"Percent({f / 100:0.###})", pos.ToString ());
}
[Fact]