Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ END TEMPLATE-->

### Breaking changes

*None yet*
* Add validation to `UiBox2` to ensure the size is >= 0.

### New features

Expand Down
16 changes: 16 additions & 0 deletions Robust.Client.Tests/Graphics/StyleBoxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,21 @@ public void TestGetEnvelopBox()
styleBox.GetEnvelopBox(new Vector2(10, 10), new Vector2(50, 50), 2.0f),
Is.EqualTo(new UIBox2(10, 10, 80, 92)));
}

[Test]
public void TestGetContentBoxClampsWhenMarginsExceedBaseBox()
{
var styleBox = new StyleBoxFlat
{
ContentMarginLeftOverride = 10,
ContentMarginTopOverride = 20,
ContentMarginRightOverride = 30,
ContentMarginBottomOverride = 40,
};

var contentBox = styleBox.GetContentBox(new UIBox2(0, 0, 5, 5), 1);

Assert.That(contentBox, Is.EqualTo(new UIBox2(10, 20, 10, 20)));
}
}
}
6 changes: 3 additions & 3 deletions Robust.Client/Graphics/Drawing/StyleBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ public Vector2 GetContentOffset(Vector2 basePosition, float uiScale)
/// Gets the box considered the "contents" of this style box, when drawn at a specific size. Input and output
/// boxes are in virtual pixels, though virtual pixels can also be used if the ui scale is set to 1.
/// </summary>
/// <exception cref="ArgumentException">
/// <paramref name="baseBox"/> is too small and the resultant box would have negative dimensions.
/// </exception>
public UIBox2 GetContentBox(UIBox2 baseBox, float uiScale)
{
var left = baseBox.Left + GetContentMargin(Margin.Left) * uiScale;
var top = baseBox.Top + GetContentMargin(Margin.Top) * uiScale;
var right = baseBox.Right - GetContentMargin(Margin.Right) * uiScale;
var bottom = baseBox.Bottom - GetContentMargin(Margin.Bottom) * uiScale;

right = MathF.Max(left, right);
bottom = MathF.Max(top, bottom);

return new UIBox2(left, top, right, bottom);
}

Expand Down
26 changes: 26 additions & 0 deletions Robust.Shared.Maths.Tests/UIBox2_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ public void Box2EdgesConstructor([ValueSource(nameof(Sources))] (float, float, f
Assert.That(box.Bottom, Is.EqualTo(bottom));
}

[Test]
public void Box2ValidatesConstruction()
{
Assert.Multiple(() =>
{
Assert.Throws<ArgumentException>(() => new UIBox2(3, 4, -1, -2));
Assert.Throws<ArgumentException>(() => new UIBox2(new Vector2(3, 4), new Vector2(-1, -2)));
});
}

[Test]
public void Box2ValidatesProperties()
{
var box = new UIBox2(-1, -2, 3, 4);

Assert.Multiple(() =>
{
Assert.Throws<ArgumentOutOfRangeException>(() => box.Left = 4);
Assert.Throws<ArgumentOutOfRangeException>(() => box.Top = 5);
Assert.Throws<ArgumentOutOfRangeException>(() => box.Right = -2);
Assert.Throws<ArgumentOutOfRangeException>(() => box.Bottom = -3);
Assert.Throws<ArgumentOutOfRangeException>(() => box.TopLeft = new Vector2(4, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => box.BottomRight = new Vector2(0, -3));
});
}

[Test]
public void Box2CornerVectorProperties([ValueSource(nameof(Sources))] (float, float, float, float) test)
{
Expand Down
Loading
Loading