feat(ui): port retained widget foundations
This commit is contained in:
parent
44f9ec13d9
commit
d825572e31
44 changed files with 84813 additions and 292 deletions
132
tests/AcDream.App.Tests/UI/UiLayoutPolicyTests.cs
Normal file
132
tests/AcDream.App.Tests/UI/UiLayoutPolicyTests.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
using AcDream.App.UI;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public sealed class UiLayoutPolicyTests
|
||||
{
|
||||
private static readonly UiPixelRect OriginalParent =
|
||||
UiPixelRect.FromPositionAndSize(0, 0, 800, 600);
|
||||
private static readonly UiPixelRect OriginalChild =
|
||||
UiPixelRect.FromPositionAndSize(100, 50, 200, 100);
|
||||
|
||||
[Fact]
|
||||
public void ModeZero_PreservesEveryCurrentEdge()
|
||||
{
|
||||
var current = new UiPixelRect(111, 66, 333, 177);
|
||||
var resizedParent = UiPixelRect.FromPositionAndSize(0, 0, 1600, 900);
|
||||
|
||||
var result = UiLayoutPolicy.Apply(
|
||||
0, 0, 0, 0,
|
||||
OriginalChild,
|
||||
OriginalParent,
|
||||
current,
|
||||
resizedParent);
|
||||
|
||||
Assert.Equal(current, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModeOne_KeepsNearEdgesAndAddsParentDeltaToFarEdges()
|
||||
{
|
||||
var resizedParent = UiPixelRect.FromPositionAndSize(0, 0, 1000, 700);
|
||||
|
||||
var result = UiLayoutPolicy.Apply(
|
||||
1, 1, 1, 1,
|
||||
OriginalChild,
|
||||
OriginalParent,
|
||||
OriginalChild,
|
||||
resizedParent);
|
||||
|
||||
Assert.Equal(new UiPixelRect(100, 50, 499, 249), result);
|
||||
Assert.Equal(400, result.Width);
|
||||
Assert.Equal(200, result.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MixedModeTwoAndOne_MovesFixedSizeChildWithFarSide()
|
||||
{
|
||||
var resizedParent = UiPixelRect.FromPositionAndSize(0, 0, 1000, 700);
|
||||
|
||||
var result = UiLayoutPolicy.Apply(
|
||||
2, 2, 1, 1,
|
||||
OriginalChild,
|
||||
OriginalParent,
|
||||
OriginalChild,
|
||||
resizedParent);
|
||||
|
||||
Assert.Equal(new UiPixelRect(300, 150, 499, 249), result);
|
||||
Assert.Equal(OriginalChild.Width, result.Width);
|
||||
Assert.Equal(OriginalChild.Height, result.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModeThree_UsesInclusivePixelCenterFormula()
|
||||
{
|
||||
var resizedParent = UiPixelRect.FromPositionAndSize(0, 0, 1001, 701);
|
||||
|
||||
var result = UiLayoutPolicy.Apply(
|
||||
3, 3, 3, 3,
|
||||
OriginalChild,
|
||||
OriginalParent,
|
||||
OriginalChild,
|
||||
resizedParent);
|
||||
|
||||
Assert.Equal(new UiPixelRect(400, 300, 599, 399), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModeFour_ScalesEachCoordinateWithTruncationTowardZero()
|
||||
{
|
||||
var originalParent = UiPixelRect.FromPositionAndSize(0, 0, 10, 10);
|
||||
var originalChild = new UiPixelRect(-3, -3, -1, -1);
|
||||
var resizedParent = UiPixelRect.FromPositionAndSize(0, 0, 15, 15);
|
||||
|
||||
var result = UiLayoutPolicy.Apply(
|
||||
4, 4, 4, 4,
|
||||
originalChild,
|
||||
originalParent,
|
||||
originalChild,
|
||||
resizedParent);
|
||||
|
||||
Assert.Equal(new UiPixelRect(-4, -4, -1, -1), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AssigningCompatibilityAnchors_OptsOutOfImportedPolicy()
|
||||
{
|
||||
var element = new UiPanel
|
||||
{
|
||||
LayoutPolicy = new UiLayoutPolicy(
|
||||
1, 1, 1, 1,
|
||||
OriginalChild,
|
||||
OriginalParent),
|
||||
};
|
||||
|
||||
element.Anchors = AnchorEdges.Left | AnchorEdges.Top;
|
||||
|
||||
Assert.Null(element.LayoutPolicy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyAnchor_UsesImportedPolicyInsteadOfCompatibilityMargins()
|
||||
{
|
||||
var element = new UiPanel
|
||||
{
|
||||
Left = 100,
|
||||
Top = 50,
|
||||
Width = 200,
|
||||
Height = 100,
|
||||
LayoutPolicy = new UiLayoutPolicy(
|
||||
1, 1, 1, 1,
|
||||
OriginalChild,
|
||||
OriginalParent),
|
||||
};
|
||||
|
||||
element.ApplyAnchor(1000, 700);
|
||||
|
||||
Assert.Equal(100f, element.Left);
|
||||
Assert.Equal(50f, element.Top);
|
||||
Assert.Equal(400f, element.Width);
|
||||
Assert.Equal(200f, element.Height);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue