Exemplo n.º 1
0
        public void PointTranslationBasicTest()
        {
            TestVisual parent = new TestVisual();
            TestVisual child1 = new TestVisual();
            TestVisual child2 = new TestVisual();

            parent.AddVisualChild(child1);
            child1.AddVisualChild(child2);

            parent.Bounds = new Rect(100, 50, 450, 400);
            child1.Bounds = new Rect(50, 100, 350, 200);
            child2.Bounds = new Rect(100, 50, 150, 100);

            Assert.AreEqual(new Point(100, 50), parent.PointToRoot(new Point(0, 0)));
            Assert.AreEqual(new Point(150, 150), child1.PointToRoot(new Point(0, 0)));
            Assert.AreEqual(new Point(250, 200), child2.PointToRoot(new Point(0, 0)));

            Assert.AreEqual(new Point(0, 0), parent.PointFromRoot(new Point(100, 50)));
            Assert.AreEqual(new Point(0, 0), child1.PointFromRoot(new Point(150, 150)));
            Assert.AreEqual(new Point(0, 0), child2.PointFromRoot(new Point(250, 200)));

            Assert.AreEqual(new Point(300, 250), parent.PointToRoot(new Point(200, 200)));
            Assert.AreEqual(new Point(300, 250), child1.PointToRoot(new Point(150, 100)));
            Assert.AreEqual(new Point(300, 250), child2.PointToRoot(new Point(50, 50)));

            Assert.AreEqual(new Point(200, 200), parent.PointFromRoot(new Point(300, 250)));
            Assert.AreEqual(new Point(150, 100), child1.PointFromRoot(new Point(300, 250)));
            Assert.AreEqual(new Point(50, 50), child2.PointFromRoot(new Point(300, 250)));
        }
Exemplo n.º 2
0
        public void Added_Child_Should_Have_VisualParent_Set()
        {
            var target = new TestVisual();
            var child = new Visual();

            target.AddChild(child);

            Assert.Equal(target, child.GetVisualParent());
        }
Exemplo n.º 3
0
        public void Added_Child_Should_Have_InheritanceParent_Set()
        {
            var target = new TestVisual();
            var child = new TestVisual();

            target.AddChild(child);

            Assert.Equal(target, child.InheritanceParent);
        }
Exemplo n.º 4
0
        public void Removed_Child_Should_Have_VisualParent_Cleared()
        {
            var target = new TestVisual();
            var child = new Visual();

            target.AddChild(child);
            target.RemoveChild(child);

            Assert.Null(child.GetVisualParent());
        }
Exemplo n.º 5
0
        public void Removed_Child_Should_Have_InheritanceParent_Cleared()
        {
            var target = new TestVisual();
            var child = new TestVisual();

            target.AddChild(child);
            target.RemoveChild(child);

            Assert.Null(child.InheritanceParent);
        }
Exemplo n.º 6
0
        public void Adding_Already_Parented_Control_Should_Throw()
        {
            var root1 = new TestRoot();
            var root2 = new TestRoot();
            var child = new TestVisual();

            root1.AddChild(child);

            Assert.Throws<InvalidOperationException>(() => root2.AddChild(child));
            Assert.Equal(0, root2.GetVisualChildren().Count());
        }
Exemplo n.º 7
0
        public void Clearing_Children_Should_Clear_VisualParent()
        {
            var children = new[] { new Visual(), new Visual() };
            var target = new TestVisual();

            target.AddChildren(children);
            target.ClearChildren();

            var result = children.Select(x => x.GetVisualParent()).ToList();

            Assert.Equal(new Visual[] { null, null }, result);
        }
Exemplo n.º 8
0
        public void Added_Child_Should_Notify_VisualParent_Changed()
        {
            var target = new TestVisual();
            var child = new TestVisual();
            var parents = new List<IVisual>();

            child.GetObservable(Visual.VisualParentProperty).Subscribe(x => parents.Add(x));
            target.AddChild(child);
            target.RemoveChild(child);

            Assert.Equal(new IVisual[] { null, target, null }, parents);
        }
Exemplo n.º 9
0
        public void Adding_Children_Should_Fire_OnAttachedToVisualTree()
        {
            var child2 = new TestVisual();
            var child1 = new TestVisual { Child = child2 };
            var root = new TestRoot();
            var called1 = false;
            var called2 = false;

            child1.AttachedToVisualTree += (s, e) => called1 = true;
            child2.AttachedToVisualTree += (s, e) => called2 = true;

            root.Child = child1;

            Assert.True(called1);
            Assert.True(called2);
        }
Exemplo n.º 10
0
        public void ParentChanged_Attached_Methods_Should_Be_Called_In_Right_Order()
        {
            var target = new TestRoot();
            var child = new TestVisual();
            int changed = 0;
            int attched = 0;
            int i = 1;

            child.VisualParentChangedCalled += (s, e) => changed = i++;
            child.AttachedToVisualTreeCalled += (s, e) => attched = i++;

            target.AddChild(child);

            Assert.Equal(1, changed);
            Assert.Equal(2, attched);
        }
Exemplo n.º 11
0
        public void ParentChanged_Detached_Methods_Should_Be_Called_In_Right_Order()
        {
            var target = new TestRoot();
            var child = new TestVisual();
            int changed = 0;
            int detached = 0;
            int i = 1;

            target.AddChild(child);

            child.VisualParentChangedCalled += (s, e) => changed = i++;
            child.DetachedFromVisualTreeCalled += (s, e) => detached = i++;

            target.ClearChildren();

            Assert.Equal(1, changed);
            Assert.Equal(2, detached);
        }
Exemplo n.º 12
0
        public void PointTranslationTransformTest()
        {
            TestVisual parent = new TestVisual();
            TestVisual child1 = new TestVisual();
            TestVisual child2 = new TestVisual();

            parent.AddVisualChild(child1);
            child1.AddVisualChild(child2);

            parent.Bounds = new Rect(100, 50, 500, 400);
            child1.Bounds = new Rect(50, 100, 400, 200);
            child2.Bounds = new Rect(100, 50, 200, 100);

            child1.Transform = Matrix.RotationMatrix(Math.PI / 2, 200, 100);
            child2.Transform = Matrix.ScalingMatrix(2, 0.5, 100, 50);

            Assert.IsTrue(parent.PointToRoot(new Point(0, 0)).IsClose(new Point(100, 50)));
            Assert.IsTrue(child1.PointToRoot(new Point(0, 0)).IsClose(new Point(450, 50)));
            Assert.IsTrue(child2.PointToRoot(new Point(0, 0)).IsClose(new Point(375, 50)));

            Assert.IsTrue(parent.PointFromRoot(new Point(100, 50)).IsClose(new Point(0, 0)));
            Assert.IsTrue(child1.PointFromRoot(new Point(450, 50)).IsClose(new Point(0, 0)));
            Assert.IsTrue(child2.PointFromRoot(new Point(375, 50)).IsClose(new Point(0, 0)));
        }
Exemplo n.º 13
0
        public void Controls_Should_Add_Themselves_To_Root_NameScope()
        {
            var child2 = new TestVisual { Name = "bar" };
            var child1 = new TestVisual { Name = "foo", Child = child2 };
            var root = new TestRoot { Child = child1 };

            Assert.Same(child1, root.Find("foo"));
            Assert.Same(child2, root.Find("bar"));
        }
Exemplo n.º 14
0
        public void Controls_Should_Add_Themselves_To_NameScopes_In_Attached_Property()
        {
            var child2 = new TestVisual { Name = "bar", [NameScope.NameScopeProperty] = new NameScope() };
            var child1 = new TestVisual { Name = "foo", Child = child2};
            var root = new TestRoot { Child = child1 };

            Assert.Same(child1, root.Find("foo"));
            Assert.Null(root.Find("bar"));
            Assert.Same(child2, NameScope.GetNameScope(child2).Find("bar"));
        }
Exemplo n.º 15
0
        public void Controls_Should_Remove_Themselves_From_Root_NameScope()
        {
            var child2 = new TestVisual { Name = "bar" };
            var child1 = new TestVisual { Name = "foo", Child = child2 };
            var root = new TestRoot { Child = child1 };

            root.Child = null;

            Assert.Null(root.Find("foo"));
            Assert.Null(root.Find("bar"));
        }
Exemplo n.º 16
0
        public void Controls_Should_Remove_Themselves_From_NameScopes_In_Attached_Property()
        {
            var child2 = new TestVisual { Name = "bar" };
            var child1 = new TestVisual { Name = "foo", Child = child2,[NameScope.NameScopeProperty] = new NameScope() };
            var root = new TestRoot { Child = child1 };

            root.Child = null;

            Assert.Null(root.Find("foo"));
            Assert.Null(root.Find("bar"));
            Assert.Null(NameScope.GetNameScope(child1).Find("bar"));
        }
 public VisualAffectsRenderBenchmarks()
 {
     _target = new TestVisual();
     _pen    = new Pen(Brushes.Black);
 }
Exemplo n.º 18
0
        public void Removing_Children_Should_Fire_OnDetachedFromVisualTree()
        {
            var child2 = new TestVisual();
            var child1 = new TestVisual { Child = child2 };
            var root = new TestRoot();
            var called1 = false;
            var called2 = false;

            root.Child = child1;
            child1.DetachedFromVisualTree += (s, e) => called1 = true;
            child2.DetachedFromVisualTree += (s, e) => called2 = true;
            root.Child = null;

            Assert.True(called1);
            Assert.True(called2);
        }