Add StyleBox.GetEnvelopBox.

This commit is contained in:
Pieter-Jan Briers
2019-02-25 00:43:48 +01:00
parent 9858004de8
commit 85da2b9a19
3 changed files with 24 additions and 1 deletions

View File

@@ -234,6 +234,24 @@ namespace SS14.Client.Graphics.Drawing
return new UIBox2(left, top, right, bottom);
}
/// <summary>
/// Gets the draw box, positioned at <paramref name="position"/>,
/// that envelops a box with the given dimensions perfectly given this box's content margins.
/// </summary>
/// <remarks>
/// It's basically a reverse <see cref="GetContentBox"/>.
/// </remarks>
/// <param name="position">The position at which the new box should be drawn.</param>
/// <param name="dimensions">The dimensions of the content box inside this new box.</param>
/// <returns>
/// A box that, when ran through <see cref="GetContentBox"/>,
/// has a content box of size <paramref name="dimensions"/>
/// </returns>
public UIBox2 GetEnvelopBox(Vector2 position, Vector2 dimensions)
{
return UIBox2.FromDimensions(position, dimensions + MinimumSize);
}
public void SetContentMarginOverride(Margin margin, float value)
{
if ((margin & Margin.Left) != 0)

View File

@@ -25,7 +25,11 @@ namespace SS14.UnitTesting.Client.Graphics
Assert.That(
styleBox.GetEnvelopBox(Vector2.Zero, new Vector2(50, 50)),
Is.EqualTo(new UIBox2(3, 5, 60, 66)));
Is.EqualTo(new UIBox2(0, 0, 60, 66)));
Assert.That(
styleBox.GetEnvelopBox(new Vector2(10, 10), new Vector2(50, 50)),
Is.EqualTo(new UIBox2(10, 10, 70, 76)));
}
}
}

View File

@@ -105,6 +105,7 @@
<Compile Include="ApproxEqualityConstraint.cs" />
<Compile Include="Client\GameObjects\Components\Transform_Test.cs" />
<Compile Include="Client\GameControllerProxyDummy.cs" />
<Compile Include="Client\Graphics\StyleBoxTest.cs" />
<Compile Include="Client\Graphics\TextureLoadParametersTest.cs" />
<Compile Include="Client\UserInterface\ControlTest.cs" />
<Compile Include="Client\UserInterface\StylesheetTest.cs" />