AnchoringTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Scenes.Tests.Controls AnchoringTests

Namespace: DeltaEngine.Scenes.Tests.Controls
Assembly: DeltaEngine.Scenes.Tests (in DeltaEngine.Scenes.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class AnchoringTests : TestWithMocksOrVisually

The AnchoringTests type exposes the following members.

Constructors

  NameDescription
Public methodAnchoringTests
Initializes a new instance of the AnchoringTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodAllMargins
Public methodBottomMargin
Public methodConstructor
Public methodDrawControlsAnchoredTogether
Public methodDrawControlsAnchoredToScreenCornersAndEdges
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLeftMargin
Public methodLeftRightMargin
Public methodNoBottomMargin
Public methodNoLeftMargin
Public methodNoRightMargin
Public methodNoTopMargin
Public methodPercentHintLandscapeImageLandscapeScreen
Public methodPercentHintLandscapeImagePortraitScreen
Public methodPercentHintPortraitImageLandscapeScreen
Public methodPercentHintPortraitImagePortraitScreen
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Public methodRightMargin
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetAndGetMargins
Public methodSetUp
Public methodTest
Public methodTopBottomMargin
Public methodTopMargin
Public methodWithNoMarginsDrawAreaIsUnchanged
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void DrawControlsAnchoredToScreenCornersAndEdges()
{
    new Button(ButtonDrawArea, "Left") { LeftMargin = Left };
    new Button(ButtonDrawArea, "Right") { RightMargin = Right };
    new Button(ButtonDrawArea, "Top") { TopMargin = Top };
    new Button(ButtonDrawArea, "Bottom") { BottomMargin = Bottom };
    new Button(ButtonDrawArea, "Top\nLeft") { TopMargin = Top, LeftMargin = Left };
    new Button(ButtonDrawArea, "Top\nRight") { TopMargin = Top, RightMargin = Right };
    new Button(ButtonDrawArea, "Bottom\nLeft") { BottomMargin = Bottom, LeftMargin = Left };
    new Button(ButtonDrawArea, "Bottom\nRight") { BottomMargin = Bottom, RightMargin = Right };
}
[Test]
public void DrawControlsAnchoredTogether()
{
    var centerButton = new Button(ButtonDrawArea, "Click Me");
    var rnd = Randomizer.Current;
    centerButton.Clicked +=
        () => centerButton.TopLeft = new Vector2D(rnd.Get(0.3f, 0.6f), rnd.Get(0.3f, 0.6f));
    new Button(ButtonDrawArea) // button left of center button
    {
        RightMargin = new Margin(centerButton, Edge.Left, 0.01f),
        TopMargin = new Margin(centerButton, Edge.Top, 0.0f)
    };
    new Button(ButtonDrawArea) // button right of center button
    {
        LeftMargin = new Margin(centerButton, Edge.Right, 0.01f),
        TopMargin = new Margin(centerButton, Edge.Top, 0.0f)
    };
    new Button(ButtonDrawArea) // button above center button
    {
        BottomMargin = new Margin(centerButton, Edge.Top, 0.01f),
        LeftMargin = new Margin(centerButton, Edge.Left, 0.0f)
    };
    new Button(ButtonDrawArea) // button below center button
    {
        TopMargin = new Margin(centerButton, Edge.Bottom, 0.01f),
        LeftMargin = new Margin(centerButton, Edge.Left, 0.0f)
    };
    centerButton.Click();
}
[Test]
public void Test()
{
    var centerButton = new Button(ButtonDrawArea, "Click Me");
    var rnd = Randomizer.Current;
    centerButton.Clicked +=
        () => centerButton.TopLeft = new Vector2D(rnd.Get(0.3f, 0.6f), rnd.Get(0.3f, 0.6f));
    new Button(ButtonDrawArea) // button above center button
    {
        BottomMargin = new Margin(centerButton, Edge.Top, 0.01f),
        RightMargin = new Margin(centerButton, Edge.Right, 0.05f)
    };
    centerButton.Click();
}
[Test, CloseAfterFirstFrame]
public void Constructor()
{
    Assert.AreEqual(new Margin(Edge.Left), anchoring.LeftMargin);
    Assert.AreEqual(new Margin(Edge.Right), anchoring.RightMargin);
    Assert.AreEqual(new Margin(Edge.Top), anchoring.TopMargin);
    Assert.AreEqual(new Margin(Edge.Bottom), anchoring.BottomMargin);
    Assert.AreEqual(-1, anchoring.PercentageSpan);
}
[Test, CloseAfterFirstFrame]
public void WithNoMarginsDrawAreaIsUnchanged()
{
    Assert.AreEqual(control.DrawArea, anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void TopMargin()
{
    anchoring.TopMargin = new Margin(Edge.Top, 0.05f);
    AssertNearlyEqual(new Rectangle(0.35f, 0.26875f, 0.3f, 0.4f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void BottomMargin()
{
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.05f);
    AssertNearlyEqual(new Rectangle(0.35f, 0.33125f, 0.3f, 0.4f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void LeftMargin()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.05f);
    AssertNearlyEqual(new Rectangle(0.05f, 0.3f, 0.3f, 0.4f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void RightMargin()
{
    anchoring.RightMargin = new Margin(Edge.Right, 0.05f);
    AssertNearlyEqual(new Rectangle(0.65f, 0.3f, 0.3f, 0.4f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void LeftRightMargin()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.05f);
    anchoring.RightMargin = new Margin(Edge.Right, 0.15f);
    AssertNearlyEqual(new Rectangle(0.05f, -0.0333f, 0.8f, 1.0666f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void TopBottomMargin()
{
    anchoring.TopMargin = new Margin(Edge.Top, 0.05f);
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.15f);
    AssertNearlyEqual(new Rectangle(0.364f, 0.2688f, 0.2719f, 0.3625f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void NoTopMargin()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.02f);
    anchoring.RightMargin = new Margin(Edge.Right, 0.04f);
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.06f);
    AssertNearlyEqual(new Rectangle(0.02f, -0.532f, 0.94f, 1.2533f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void NoBottomMargin()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.02f);
    anchoring.RightMargin = new Margin(Edge.Right, 0.04f);
    anchoring.TopMargin = new Margin(Edge.Top, 0.06f);
    AssertNearlyEqual(new Rectangle(0.02f, 0.2788f, 0.94f, 1.2533f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void NoLeftMargin()
{
    anchoring.RightMargin = new Margin(Edge.Right, 0.02f);
    anchoring.TopMargin = new Margin(Edge.Top, 0.04f);
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.06f);
    AssertNearlyEqual(new Rectangle(0.6331f, 0.2587f, 0.3469f, 0.4625f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void NoRightMargin()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.02f);
    anchoring.TopMargin = new Margin(Edge.Top, 0.04f);
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.06f);
    AssertNearlyEqual(new Rectangle(0.02f, 0.2587f, 0.3469f, 0.4625f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void AllMargins()
{
    anchoring.LeftMargin = new Margin(Edge.Left, 0.02f);
    anchoring.RightMargin = new Margin(Edge.Right, 0.04f);
    anchoring.TopMargin = new Margin(Edge.Top, 0.06f);
    anchoring.BottomMargin = new Margin(Edge.Bottom, 0.08f);
    AssertNearlyEqual(new Rectangle(0.02f, 0.2788f, 0.94f, 0.4225f),
        anchoring.CalculateDrawArea(control));
}
[Test, CloseAfterFirstFrame]
public void PercentHintLandscapeImageLandscapeScreen()
{
    anchoring.PercentageSpan = 0.4f;
    AssertNearlyEqual(new Rectangle(0.365f, 0.3875f, 0.27f, 0.225f),
        anchoring.CalculateDrawArea(landscapeControl));
}
[Test, CloseAfterFirstFrame]
public void PercentHintPortraitImageLandscapeScreen()
{
    anchoring.PercentageSpan = 0.4f;
    AssertNearlyEqual(new Rectangle(0.41f, 0.3875f, 0.18f, 0.225f),
        anchoring.CalculateDrawArea(portraitControl));
}
[Test, CloseAfterFirstFrame]
public void PercentHintLandscapeImagePortraitScreen()
{
    Resolve<Window>().ViewportPixelSize = new Size(600, 800);
    anchoring.PercentageSpan = 0.4f;
    AssertNearlyEqual(new Rectangle(0.35f, 0.375f, 0.3f, 0.25f),
        anchoring.CalculateDrawArea(landscapeControl));
}
[Test, CloseAfterFirstFrame]
public void PercentHintPortraitImagePortraitScreen()
{
    Resolve<Window>().ViewportPixelSize = new Size(600, 800);
    anchoring.PercentageSpan = 0.4f;
    AssertNearlyEqual(new Rectangle(0.35f, 0.3125f, 0.3f, 0.375f),
        anchoring.CalculateDrawArea(portraitControl));
}
[Test, CloseAfterFirstFrame]
public void SetAndGetMargins()
{
    var button = new Button(Rectangle.One)
    {
        LeftMargin = new Margin(Edge.Left, 1),
        RightMargin = new Margin(Edge.Right, 2),
        TopMargin = new Margin(Edge.Top, 3),
        BottomMargin = new Margin(Edge.Bottom, 4)
    };
    Assert.AreEqual(new Margin(Edge.Left, 1), button.LeftMargin);
    Assert.AreEqual(new Margin(Edge.Right, 2), button.RightMargin);
    Assert.AreEqual(new Margin(Edge.Top, 3), button.TopMargin);
    Assert.AreEqual(new Margin(Edge.Bottom, 4), button.BottomMargin);
}
See Also