public void RelativePositionRelativeSize([Values(0.0, 0.2, 0.5, 1.0)] double relX, [Values(0.0, 0.2, 0.5, 1.0)] double relY, [Values(0.0, 0.2, 0.5, 1.0)] double relHeight, [Values(0.0, 0.2, 0.5, 1.0)] double relWidth) { var abs = new Compatibility.AbsoluteLayout { IsPlatformEnabled = true }; var child = new View { IsPlatformEnabled = true }; abs.Children.Add(child, new Rectangle(relX, relY, relWidth, relHeight), AbsoluteLayoutFlags.All); abs.Layout(new Rectangle(0, 0, 100, 100)); double expectedWidth = Math.Round(100 * relWidth); double expectedHeight = Math.Round(100 * relHeight); double expectedX = Math.Round((100 - expectedWidth) * relX); double expectedY = Math.Round((100 - expectedHeight) * relY); Assert.That(child.X, Is.EqualTo(expectedX).Within(0.0001)); Assert.That(child.Y, Is.EqualTo(expectedY).Within(0.0001)); Assert.That(child.Width, Is.EqualTo(expectedWidth).Within(0.0001)); Assert.That(child.Height, Is.EqualTo(expectedHeight).Within(0.0001)); }
public void AbsolutePositionAndSizeUsingRectangle() { var abs = new Compatibility.AbsoluteLayout { IsPlatformEnabled = true }; var child = new View { IsPlatformEnabled = true }; abs.Children.Add(child, new Rectangle(10, 20, 30, 40)); abs.Layout(new Rectangle(0, 0, 100, 100)); Assert.AreEqual(new Rectangle(10, 20, 30, 40), child.Bounds); }
public void AbsolutePositionRelativeSize() { var abs = new Compatibility.AbsoluteLayout { IsPlatformEnabled = true }; var child = new View { IsPlatformEnabled = true }; abs.Children.Add(child, new Rectangle(10, 20, 0.4, 0.5), AbsoluteLayoutFlags.SizeProportional); abs.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(child.X, Is.EqualTo(10)); Assert.That(child.Y, Is.EqualTo(20)); Assert.That(child.Width, Is.EqualTo(40).Within(0.0001)); Assert.That(child.Height, Is.EqualTo(50).Within(0.0001)); }
public void RelativePositionAbsoluteSize(double width, double height, double relX, double relY) { var abs = new Compatibility.AbsoluteLayout { IsPlatformEnabled = true }; var child = new View { IsPlatformEnabled = true }; abs.Children.Add(child, new Rectangle(relX, relY, width, height), AbsoluteLayoutFlags.PositionProportional); abs.Layout(new Rectangle(0, 0, 100, 100)); double expectedX = Math.Round((100 - width) * relX); double expectedY = Math.Round((100 - height) * relY); Assert.That(child.X, Is.EqualTo(expectedX).Within(0.0001)); Assert.That(child.Y, Is.EqualTo(expectedY).Within(0.0001)); Assert.That(child.Width, Is.EqualTo(width)); Assert.That(child.Height, Is.EqualTo(height)); }