Exemplo n.º 1
0
        public void HitTest_Should_Return_Top_Controls_First()
        {
            using (TestApplication())
            {
                Panel container;
                var   root = new TestRoot
                {
                    Child = container = new Panel
                    {
                        Width    = 200,
                        Height   = 200,
                        Children = new Controls.Controls
                        {
                            new Border
                            {
                                Width               = 100,
                                Height              = 100,
                                Background          = Brushes.Red,
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment   = VerticalAlignment.Center
                            },
                            new Border
                            {
                                Width               = 50,
                                Height              = 50,
                                Background          = Brushes.Red,
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment   = VerticalAlignment.Center
                            }
                        }
                    }
                };

                root.Renderer = new ImmediateRenderer(root);
                root.Measure(Size.Infinity);
                root.Arrange(new Rect(container.DesiredSize));
                root.Renderer.Paint(new Rect(root.ClientSize));

                var result = root.Renderer.HitTest(new Point(100, 100), null);

                Assert.Equal(new[] { container.Children[1], container.Children[0], container, root }, result);
            }
        }
        public void Should_Render_Child_In_Parent_With_RenderTransform2()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var targetMock = new Mock <Control>()
                {
                    CallBase = true
                };
                var target = targetMock.Object;

                target.Width  = 100;
                target.Height = 50;
                target.HorizontalAlignment = HorizontalAlignment.Center;
                target.VerticalAlignment   = VerticalAlignment.Center;

                var child = new Panel()
                {
                    RenderTransform = new RotateTransform()
                    {
                        Angle = 90
                    },
                    Children = { new Panel()
                                 {
                                     Children ={ target                }
                                 } }
                };

                var visualTarget = targetMock.As <IVisual>();
                int rendered     = 0;
                visualTarget.Setup(v => v.Render(It.IsAny <DrawingContext>())).Callback(() => rendered++);

                var root = new TestRoot(child);
                root.Renderer = new ImmediateRenderer(root);

                root.LayoutManager.ExecuteInitialLayoutPass();

                root.Measure(new Size(300, 100));
                root.Arrange(new Rect(new Size(300, 100)));
                root.Renderer.Paint(root.Bounds);

                Assert.Equal(1, rendered);
            }
        }
Exemplo n.º 3
0
        public void ClipBounds_Should_Be_Intersection_With_Parent_ClipBounds()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Border border;
                var    tree = new TestRoot
                {
                    Width  = 200,
                    Height = 300,
                    Child  = new Canvas
                    {
                        ClipToBounds        = true,
                        Width               = 100,
                        Height              = 100,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Children            =
                        {
                            (border          = new Border
                            {
                                Background   = Brushes.AliceBlue,
                                ClipToBounds = true,
                                Width        =               100,
                                Height       =               100,
                                [Canvas.LeftProperty] = 50,
                                [Canvas.TopProperty] = 50,
                            })
                        }
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(tree.DesiredSize));

                var scene        = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(scene);

                var borderNode = scene.FindNode(border);
                Assert.Equal(new Rect(50, 50, 50, 50), borderNode.ClipBounds);
            }
        }
Exemplo n.º 4
0
        public void Should_Update_When_Control_Made_Invisible()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Decorator decorator;
                Border    border;
                Canvas    canvas;
                var       tree = new TestRoot
                {
                    Width  = 100,
                    Height = 100,
                    Child  = decorator = new Decorator
                    {
                        Child = border = new Border
                        {
                            Background = Brushes.Red,
                            Child      = canvas = new Canvas(),
                        }
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(tree.DesiredSize));

                var initial      = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(initial);

                border.IsVisible = false;
                var result = initial.CloneScene();

                Assert.True(sceneBuilder.Update(result, border));
                Assert.False(sceneBuilder.Update(result, canvas));

                var decoratorNode = (VisualNode)result.Root.Children[0];
                Assert.Equal(0, decoratorNode.Children.Count);

                Assert.Null(result.FindNode(border));
                Assert.Null(result.FindNode(canvas));
                Assert.Equal(new Rect(0, 0, 100, 100), result.Layers.Single().Dirty.Single());
            }
        }
Exemplo n.º 5
0
        public void Added_Container_Should_Have_LogicalParent_Set_To_ItemsControl()
        {
            var item  = new Border();
            var items = new ObservableCollection <Border>();

            var target = new ItemsControl
            {
                Template = GetTemplate(),
                Items    = items,
            };

            var root = new TestRoot(true, target);

            root.Measure(new Size(100, 100));
            root.Arrange(new Rect(0, 0, 100, 100));

            items.Add(item);

            Assert.Equal(target, item.Parent);
        }
Exemplo n.º 6
0
        public void Transform_For_Control_With_RenderTransform_Should_Be_Correct_After_Update()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Border border;
                var    tree = new TestRoot
                {
                    Width  = 400,
                    Height = 200,
                    Child  = new Decorator
                    {
                        Width  = 200,
                        Height = 100,
                        Child  = border = new Border
                        {
                            Background          = Brushes.Red,
                            HorizontalAlignment = HorizontalAlignment.Right,
                            Width           = 100,
                            RenderTransform = new ScaleTransform(0.5, 1),
                        }
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(tree.DesiredSize));

                var scene        = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(scene);

                var expectedTransform = Matrix.CreateScale(0.5, 1) * Matrix.CreateTranslation(225, 50);
                var borderNode        = scene.FindNode(border);
                Assert.Equal(expectedTransform, borderNode.Transform);

                scene = scene.CloneScene();
                Assert.True(sceneBuilder.Update(scene, border));

                borderNode = scene.FindNode(border);
                Assert.Equal(expectedTransform, borderNode.Transform);
            }
        }
Exemplo n.º 7
0
        public void Should_Not_Find_Sibling_Control()
        {
            using (TestApplication())
            {
                Border target;
                var    root = new TestRoot
                {
                    Width  = 200,
                    Height = 200,
                    Child  = new StackPanel
                    {
                        Background = Brushes.White,
                        Children   =
                        {
                            (target        = new Border
                            {
                                Width      =           100,
                                Height     =           200,
                                Background = Brushes.Red,
                            }),
                            new Border
                            {
                                Width      =           100,
                                Height     =           200,
                                Background = Brushes.Green,
                            }
                        },
                        Orientation = Orientation.Horizontal,
                    }
                };

                root.Renderer = new DeferredRenderer(root, null);
                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));

                var result = target.GetVisualsAt(new Point(150, 50));

                Assert.Empty(result);
            }
        }
Exemplo n.º 8
0
        public void Horizontal_Keyboard_Input_Can_Move_Splitter(Key key, double expectedWidthFirst, double expectedWidthSecond)
        {
            var control1 = new Border {
                [Grid.ColumnProperty] = 0
            };
            var splitter = new GridSplitter {
                [Grid.ColumnProperty] = 1, KeyboardIncrement = 10d
            };
            var control2 = new Border {
                [Grid.ColumnProperty] = 2
            };

            var columnDefinitions = new ColumnDefinitions
            {
                new ColumnDefinition(1, GridUnitType.Star),
                new ColumnDefinition(GridLength.Auto),
                new ColumnDefinition(1, GridUnitType.Star)
            };

            var grid = new Grid {
                ColumnDefinitions = columnDefinitions, Children = { control1, splitter, control2 }
            };

            var root = new TestRoot
            {
                Child = grid
            };

            root.Measure(new Size(200, 200));
            root.Arrange(new Rect(0, 0, 200, 200));

            splitter.RaiseEvent(new KeyEventArgs
            {
                RoutedEvent = InputElement.KeyDownEvent,
                Key         = key
            });

            Assert.Equal(columnDefinitions[0].Width, new GridLength(expectedWidthFirst, GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(expectedWidthSecond, GridUnitType.Star));
        }
Exemplo n.º 9
0
        public void Replacing_Control_Releases_DrawOperation_Reference()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var bitmap = RefCountable.Create(Mock.Of <IBitmapImpl>(
                                                     x => x.PixelSize == new PixelSize(100, 100) &&
                                                     x.Dpi == new Vector(96, 96)));

                Image img;
                var   tree = new TestRoot
                {
                    Child = img = new Image
                    {
                        Source = new Bitmap(bitmap),
                        Width  = 100,
                        Height = 100
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(new Size(100, 100)));

                var scene        = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(scene);

                var operation = scene.FindNode(img).DrawOperations[0];

                tree.Child = new Decorator();

                using (var result = scene.CloneScene())
                {
                    sceneBuilder.Update(result, img);
                    scene.Dispose();

                    Assert.Equal(0, operation.RefCount);
                    Assert.Equal(2, bitmap.RefCount);
                }
            }
        }
Exemplo n.º 10
0
        public void Should_Create_And_Delete_Layers_For_Controls_With_Animated_Opacity()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Border border;

                var root = new TestRoot
                {
                    Width  = 100,
                    Height = 100,
                    Child  = new Border
                    {
                        Background = Brushes.Red,
                        Child      = border = new Border
                        {
                            Background = Brushes.Green, Child = new Canvas(), Opacity = 0.9,
                        }
                    }
                };

                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));

                var timer  = new Mock <IRenderTimer>();
                var target = CreateTargetAndRunFrame(root, timer);

                Assert.Equal(new[] { root }, target.Layers.Select(x => x.LayerRoot));

                var animation = new BehaviorSubject <double>(0.5);
                border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);
                RunFrame(target);

                Assert.Equal(new IVisual[] { root, border }, target.Layers.Select(x => x.LayerRoot));

                animation.OnCompleted();
                RunFrame(target);

                Assert.Equal(new[] { root }, target.Layers.Select(x => x.LayerRoot));
            }
        }
Exemplo n.º 11
0
        public void TransformToVisual_Should_Work()
        {
            var child = new Decorator {
                Width = 100, Height = 100
            };
            var root = new TestRoot()
            {
                Child = child, Width = 400, Height = 400
            };

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(new Point(), root.DesiredSize));

            var tr = child.TransformToVisual(root);

            Assert.NotNull(tr);

            var point = root.Bounds.TopLeft * tr;

            //child is centered (400 - 100)/2
            Assert.Equal(new Point(150, 150), point);
        }
Exemplo n.º 12
0
        public void In_First_Position_Doesnt_Throw_Exception()
        {
            GridSplitter splitter;
            var          grid = new Grid
            {
                ColumnDefinitions = new ColumnDefinitions("Auto,*,*"),
                RowDefinitions    = new RowDefinitions("*,*"),
                Children          =
                {
                    (splitter = new GridSplitter {
                        [Grid.ColumnProperty] = 0
                    }),
                    new Border {
                        [Grid.ColumnProperty] = 1
                    },
                    new Border {
                        [Grid.ColumnProperty] = 2
                    },
                }
            };

            var root = new TestRoot {
                Child = grid
            };

            root.Measure(new Size(100, 300));
            root.Arrange(new Rect(0, 0, 100, 300));

            splitter.RaiseEvent(
                new VectorEventArgs {
                RoutedEvent = Thumb.DragStartedEvent
            });

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent, Vector = new Vector(100, 1000)
            });
        }
Exemplo n.º 13
0
        public void Should_Respect_Margin_For_ClipBounds()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Canvas canvas;
                var    tree = new TestRoot
                {
                    Width  = 200,
                    Height = 300,
                    Child  = new Border
                    {
                        Margin = new Thickness(10, 20, 30, 40),
                        Child  = canvas = new Canvas
                        {
                            ClipToBounds = true,
                            Background   = Brushes.AliceBlue,
                        }
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(tree.DesiredSize));

                var result       = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(result);

                var canvasNode = result.FindNode(canvas);
                Assert.Equal(new Rect(10, 20, 160, 240), canvasNode.ClipBounds);

                // Initial ClipBounds are correct, make sure they're still correct after updating canvas.
                result = result.CloneScene();
                Assert.True(sceneBuilder.Update(result, canvas));

                canvasNode = result.FindNode(canvas);
                Assert.Equal(new Rect(10, 20, 160, 240), canvasNode.ClipBounds);
            }
        }
Exemplo n.º 14
0
        public void HitTest_Should_Respect_Geometry_Clip()
        {
            using (TestApplication())
            {
                Border border;
                Canvas canvas;
                var    root = new TestRoot
                {
                    Width  = 400,
                    Height = 400,
                    Child  = border = new Border
                    {
                        Background = Brushes.Red,
                        Clip       = StreamGeometry.Parse("M100,0 L0,100 100,100"),
                        Width      = 200,
                        Height     = 200,
                        Child      = canvas = new Canvas
                        {
                            Background = Brushes.Yellow,
                            Margin     = new Thickness(10),
                        }
                    }
                };

                root.Renderer = new DeferredRenderer(root, null);
                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));
                Assert.Equal(new Rect(100, 100, 200, 200), border.Bounds);

                var context = new DrawingContext(Mock.Of <IDrawingContextImpl>());

                var result = root.Renderer.HitTest(new Point(200, 200), root, null);
                Assert.Equal(new IVisual[] { canvas, border }, result);

                result = root.Renderer.HitTest(new Point(110, 110), root, null);
                Assert.Empty(result);
            }
        }
Exemplo n.º 15
0
        public void Detaching_Then_Reattaching_To_Logical_Tree_Twice_Does_Not_Throw()
        {
            // # Issue 3487
            var target = new ItemsControl
            {
                Template     = GetTemplate(),
                Items        = new[] { "foo", "bar" },
                ItemTemplate = new FuncDataTemplate <string>((_, __) => new Canvas()),
            };

            var root = new TestRoot(target);

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(root.DesiredSize));

            root.Child = null;
            root.Child = target;

            target.Measure(Size.Infinity);

            root.Child = null;
            root.Child = target;
        }
Exemplo n.º 16
0
        public void Should_Push_Opacity_For_Controls_With_Less_Than_1_Opacity()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var root = new TestRoot
                {
                    Width = 100, Height = 100, Child = new Border {
                        Background = Brushes.Red, Opacity = 0.5,
                    }
                };

                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));

                var target    = CreateTargetAndRunFrame(root);
                var context   = GetLayerContext(target, root);
                var animation = new BehaviorSubject <double>(0.5);

                context.Verify(x => x.PushOpacity(0.5), Times.Once);
                context.Verify(x => x.DrawRectangle(Brushes.Red, null, new Rect(0, 0, 100, 100), default), Times.Once);
                context.Verify(x => x.PopOpacity(), Times.Once);
            }
        }
Exemplo n.º 17
0
        public void TransformToVisual_With_NonInvertible_RenderTransform_Should_Work()
        {
            var child = new Decorator
            {
                Width           = 100,
                Height          = 100,
                RenderTransform = new ScaleTransform()
                {
                    ScaleX = 0, ScaleY = 0
                }
            };
            var root = new TestRoot()
            {
                Child = child, Width = 400, Height = 400
            };

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(new Point(), root.DesiredSize));

            var tr = root.TransformToVisual(child);

            Assert.Null(tr);
        }
Exemplo n.º 18
0
        public void AutoScrollToSelectedItem_On_Reset_Works()
        {
            // Issue #3148
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var items = new ResettingCollection(100);

                var target = new ListBox
                {
                    Items        = items,
                    ItemTemplate = new FuncDataTemplate <string>((x, _) =>
                                                                 new TextBlock
                    {
                        Text   = x,
                        Width  = 100,
                        Height = 10
                    }),
                    AutoScrollToSelectedItem = true,
                    VirtualizationMode       = ItemVirtualizationMode.Simple,
                };

                var root = new TestRoot(true, target);
                root.Measure(new Size(100, 100));
                root.Arrange(new Rect(0, 0, 100, 100));

                Assert.True(target.Presenter.Panel.Children.Count > 0);
                Assert.True(target.Presenter.Panel.Children.Count < 100);

                target.SelectedItem = "Item99";

                // #3148 triggered here.
                items.Reset(new[] { "Item99" });

                Assert.Equal(0, target.SelectedIndex);
                Assert.Equal(1, target.Presenter.Panel.Children.Count);
            }
        }
Exemplo n.º 19
0
        public void Should_Push_Opacity_Mask()
        {
            var root = new TestRoot
            {
                Width  = 100,
                Height = 100,
                Child  = new Border
                {
                    Background  = Brushes.Red,
                    OpacityMask = Brushes.Green,
                }
            };

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(root.DesiredSize));

            var target    = CreateTargetAndRunFrame(root);
            var context   = GetLayerContext(target, root);
            var animation = new BehaviorSubject <double>(0.5);

            context.Verify(x => x.PushOpacityMask(Brushes.Green, new Rect(0, 0, 100, 100)), Times.Once);
            context.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            context.Verify(x => x.PopOpacityMask(), Times.Once);
        }
        public void HitTest_Should_Not_Find_Invisible_Controls_At_Point()
        {
            using (TestApplication())
            {
                Border visible;
                var    root = new TestRoot
                {
                    Width  = 200,
                    Height = 200,
                    Child  = new Border
                    {
                        Width               = 100,
                        Height              = 100,
                        Background          = Brushes.Red,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        IsVisible           = false,
                        Child               = visible = new Border
                        {
                            Background          = Brushes.Red,
                            HorizontalAlignment = HorizontalAlignment.Stretch,
                            VerticalAlignment   = VerticalAlignment.Stretch,
                        }
                    }
                };

                root.Renderer = new ImmediateRenderer(root);
                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));
                root.Renderer.Paint(new Rect(root.ClientSize));

                var result = root.Renderer.HitTest(new Point(100, 100), root, null);

                Assert.Equal(new[] { root }, result);
            }
        }
Exemplo n.º 21
0
        public void Horizontal_Stays_Within_Constraints()
        {
            var cursorFactoryImpl = new Mock<IStandardCursorFactory>();
            PerspexLocator.CurrentMutable.Bind<IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object);

            var control1 = new Border { [Grid.RowProperty] = 0 };
            var splitter = new GridSplitter
            {
                Orientation = Orientation.Horizontal,
                [Grid.RowProperty] = 1,
            };
            var control2 = new Border { [Grid.RowProperty] = 2 };

            var rowDefinitions = new RowDefinitions()
            {
                new RowDefinition(1, GridUnitType.Star) {MinHeight = 70, MaxHeight = 110},
                new RowDefinition(GridLength.Auto),
                new RowDefinition(1, GridUnitType.Star) { MinHeight = 10, MaxHeight =  140},
            };

            var grid = new Grid()
            {
                RowDefinitions = rowDefinitions,
                Children = new Controls()
                {
                    control1, splitter, control2
                }
            };

            var root = new TestRoot { Child = grid };
            Assert.Equal(splitter.Orientation, Orientation.Horizontal);
            root.Measure(new Size(100, 200));
            root.Arrange(new Rect(0, 0, 100, 200));

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector = new Vector(0, -100)
            });
            Assert.Equal(rowDefinitions[0].Height, new GridLength(70, GridUnitType.Star));
            Assert.Equal(rowDefinitions[2].Height, new GridLength(130, GridUnitType.Star));
            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector = new Vector(0, 100)
            });
            Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star));
            Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star));
        }
Exemplo n.º 22
0
        public void Horizontal_Stays_Within_Constraints(bool showsPreview)
        {
            var control1 = new Border {
                [Grid.RowProperty] = 0
            };
            var splitter = new GridSplitter {
                [Grid.RowProperty] = 1, ShowsPreview = showsPreview
            };
            var control2 = new Border {
                [Grid.RowProperty] = 2
            };

            var rowDefinitions = new RowDefinitions
            {
                new RowDefinition(1, GridUnitType.Star)
                {
                    MinHeight = 70, MaxHeight = 110
                },
                new RowDefinition(GridLength.Auto),
                new RowDefinition(1, GridUnitType.Star)
                {
                    MinHeight = 10, MaxHeight = 140
                },
            };

            var grid = new Grid {
                RowDefinitions = rowDefinitions, Children = { control1, splitter, control2 }
            };

            var root = new TestRoot
            {
                Child = new VisualLayerManager
                {
                    Child = grid
                }
            };

            root.Measure(new Size(100, 200));
            root.Arrange(new Rect(0, 0, 100, 200));

            splitter.RaiseEvent(
                new VectorEventArgs {
                RoutedEvent = Thumb.DragStartedEvent
            });

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(0, -100)
            });

            if (showsPreview)
            {
                Assert.Equal(rowDefinitions[0].Height, new GridLength(1, GridUnitType.Star));
                Assert.Equal(rowDefinitions[2].Height, new GridLength(1, GridUnitType.Star));
            }
            else
            {
                Assert.Equal(rowDefinitions[0].Height, new GridLength(70, GridUnitType.Star));
                Assert.Equal(rowDefinitions[2].Height, new GridLength(130, GridUnitType.Star));
            }

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(0, 100)
            });

            if (showsPreview)
            {
                Assert.Equal(rowDefinitions[0].Height, new GridLength(1, GridUnitType.Star));
                Assert.Equal(rowDefinitions[2].Height, new GridLength(1, GridUnitType.Star));
            }
            else
            {
                Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star));
                Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star));
            }

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragCompletedEvent
            });

            Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star));
            Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star));
        }
Exemplo n.º 23
0
        public void Vertical_Stays_Within_Constraints(bool showsPreview)
        {
            var control1 = new Border {
                [Grid.ColumnProperty] = 0
            };
            var splitter = new GridSplitter {
                [Grid.ColumnProperty] = 1, ShowsPreview = showsPreview
            };
            var control2 = new Border {
                [Grid.ColumnProperty] = 2
            };

            var columnDefinitions = new ColumnDefinitions
            {
                new ColumnDefinition(1, GridUnitType.Star)
                {
                    MinWidth = 10, MaxWidth = 190
                },
                new ColumnDefinition(GridLength.Auto),
                new ColumnDefinition(1, GridUnitType.Star)
                {
                    MinWidth = 80, MaxWidth = 120
                },
            };

            var grid = new Grid {
                ColumnDefinitions = columnDefinitions, Children = { control1, splitter, control2 }
            };

            var root = new TestRoot
            {
                Child = new VisualLayerManager
                {
                    Child = grid
                }
            };

            root.Measure(new Size(200, 100));
            root.Arrange(new Rect(0, 0, 200, 100));

            splitter.RaiseEvent(
                new VectorEventArgs {
                RoutedEvent = Thumb.DragStartedEvent
            });

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(-100, 0)
            });

            if (showsPreview)
            {
                Assert.Equal(columnDefinitions[0].Width, new GridLength(1, GridUnitType.Star));
                Assert.Equal(columnDefinitions[2].Width, new GridLength(1, GridUnitType.Star));
            }
            else
            {
                Assert.Equal(columnDefinitions[0].Width, new GridLength(80, GridUnitType.Star));
                Assert.Equal(columnDefinitions[2].Width, new GridLength(120, GridUnitType.Star));
            }

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(100, 0)
            });

            if (showsPreview)
            {
                Assert.Equal(columnDefinitions[0].Width, new GridLength(1, GridUnitType.Star));
                Assert.Equal(columnDefinitions[2].Width, new GridLength(1, GridUnitType.Star));
            }
            else
            {
                Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star));
                Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star));
            }

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragCompletedEvent
            });

            Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star));
        }
Exemplo n.º 24
0
        public void Should_Not_Render_Clipped_Child_With_RenderTransform_When_Not_In_Bounds()
        {
            const int RootWidth  = 300;
            const int RootHeight = 300;

            var rootGrid = new Grid
            {
                Width        = RootWidth,
                Height       = RootHeight,
                ClipToBounds = true
            };

            var stackPanel = new StackPanel
            {
                Orientation         = Orientation.Horizontal,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 10, 0, 0),
                RenderTransformOrigin = new RelativePoint(new Point(0, 0), RelativeUnit.Relative),
                RenderTransform       = new TransformGroup
                {
                    Children =
                    {
                        new RotateTransform    {
                            Angle = 90
                        },
                        new TranslateTransform {
                            X = 280
                        }
                    }
                }
            };

            rootGrid.Children.Add(stackPanel);

            TestControl CreateControl()
            => new TestControl
            {
                Width        = 160,
                Height       = 40,
                Margin       = new Thickness(0, 0, 5, 0),
                ClipToBounds = true
            };

            var control1 = CreateControl();
            var control2 = CreateControl();
            var control3 = CreateControl();

            stackPanel.Children.Add(control1);
            stackPanel.Children.Add(control2);
            stackPanel.Children.Add(control3);

            var root = new TestRoot(rootGrid);

            root.Renderer = new ImmediateRenderer(root);
            root.LayoutManager.ExecuteInitialLayoutPass(root);

            var rootSize = new Size(RootWidth, RootHeight);

            root.Measure(rootSize);
            root.Arrange(new Rect(rootSize));

            root.Renderer.Paint(root.Bounds);

            Assert.True(control1.Rendered);
            Assert.True(control2.Rendered);
            Assert.False(control3.Rendered);
        }
Exemplo n.º 25
0
        public void HitTest_Should_Not_Find_Control_Outside_Scroll_Viewport()
        {
            using (TestApplication())
            {
                Border target;
                Border item1;
                Border item2;
                ScrollContentPresenter scroll;
                Panel container;
                var   root = new TestRoot
                {
                    Child = container = new Panel
                    {
                        Width      = 100,
                        Height     = 200,
                        Background = Brushes.Red,
                        Children   =
                        {
                            (target                        = new Border()
                            {
                                Name                       = "b1",
                                Width                      =             100,
                                Height                     =             100,
                                Background                 = Brushes.Red,
                            }),
                            new Border()
                            {
                                Name       = "b2",
                                Width      =             100,
                                Height     =             100,
                                Background = Brushes.Red,
                                Margin     = new Thickness(0, 100, 0, 0),
                                Child      = scroll = new ScrollContentPresenter()
                                {
                                    CanHorizontallyScroll = true,
                                    CanVerticallyScroll   = true,
                                    Content                = new StackPanel()
                                    {
                                        Children           =
                                        {
                                            (item1         = new Border()
                                            {
                                                Name       = "b3",
                                                Width      =             100,
                                                Height     =             100,
                                                Background = Brushes.Red,
                                            }),
                                            (item2         = new Border()
                                            {
                                                Name       = "b4",
                                                Width      =             100,
                                                Height     =             100,
                                                Background = Brushes.Red,
                                            }),
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                scroll.UpdateChild();

                root.Renderer = new DeferredRenderer(root, null);
                root.Measure(Size.Infinity);
                root.Arrange(new Rect(container.DesiredSize));

                root.Renderer.Paint(Rect.Empty);
                var result = root.Renderer.HitTest(new Point(50, 150), root, null).First();

                Assert.Equal(item1, result);

                result = root.Renderer.HitTest(new Point(50, 50), root, null).First();

                Assert.Equal(target, result);

                scroll.Offset = new Vector(0, 100);

                // We don't have LayoutManager set up so do the layout pass manually.
                scroll.Parent.InvalidateArrange();
                container.InvalidateArrange();
                container.Arrange(new Rect(container.DesiredSize));

                root.Renderer.Paint(Rect.Empty);
                result = root.Renderer.HitTest(new Point(50, 150), root, null).First();
                Assert.Equal(item2, result);

                result = root.Renderer.HitTest(new Point(50, 50), root, null).First();
                Assert.Equal(target, result);
            }
        }
Exemplo n.º 26
0
        public void Should_Create_And_Delete_Layers_For_Transparent_Controls()
        {
            Border border;
            var    root = new TestRoot
            {
                Width  = 100,
                Height = 100,
                Child  = new Border
                {
                    Background = Brushes.Red,
                    Child      = border = new Border
                    {
                        Background = Brushes.Green,
                    }
                }
            };

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(root.DesiredSize));

            var loop         = new Mock <IRenderLoop>();
            var layerFactory = new MockRenderLayerFactory(new Dictionary <IVisual, IRenderTargetBitmapImpl>
            {
                { root, CreateLayer() },
                { border, CreateLayer() },
            });

            var target = new DeferredRenderer(
                root,
                loop.Object,
                layerFactory: layerFactory,
                dispatcher: new ImmediateDispatcher());

            root.Renderer = target;

            target.Start();
            RunFrame(loop);

            var rootContext   = layerFactory.GetMockDrawingContext(root);
            var borderContext = layerFactory.GetMockDrawingContext(border);

            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
            borderContext.Verify(x => x.FillRectangle(It.IsAny <IBrush>(), It.IsAny <Rect>(), It.IsAny <float>()), Times.Never);

            rootContext.ResetCalls();
            borderContext.ResetCalls();
            border.Opacity = 0.5;
            RunFrame(loop);

            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Never);
            borderContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);

            rootContext.ResetCalls();
            borderContext.ResetCalls();
            border.Opacity = 1;
            RunFrame(loop);

            layerFactory.GetMockBitmap(border).Verify(x => x.Dispose());
            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
            borderContext.Verify(x => x.FillRectangle(It.IsAny <IBrush>(), It.IsAny <Rect>(), It.IsAny <float>()), Times.Never);
        }
Exemplo n.º 27
0
        public void Replacing_Transitions_During_Animation_Does_Not_Throw_KeyNotFound()
        {
            // Issue #4059
            using (Start())
            {
                Border target;
                var    clock = new TestClock();
                var    root  = new TestRoot
                {
                    Clock  = clock,
                    Styles =
                    {
                        new Style(x => x.OfType <Border>())
                        {
                            Setters =
                            {
                                new Setter(Border.TransitionsProperty,
                                           new Transitions
                                {
                                    new DoubleTransition
                                    {
                                        Property = Border.OpacityProperty,
                                        Duration = TimeSpan.FromSeconds(1),
                                    },
                                }),
                            },
                        },
                        new Style(x => x.OfType <Border>().Class("foo"))
                        {
                            Setters =
                            {
                                new Setter(Border.TransitionsProperty,
                                           new Transitions
                                {
                                    new DoubleTransition
                                    {
                                        Property = Border.OpacityProperty,
                                        Duration = TimeSpan.FromSeconds(1),
                                    },
                                }),
                                new Setter(Border.OpacityProperty, 0.0),
                            },
                        },
                    },
                    Child = target = new Border
                    {
                        Background = Brushes.Red,
                    }
                };

                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));

                target.Classes.Add("foo");
                clock.Step(TimeSpan.FromSeconds(0));
                clock.Step(TimeSpan.FromSeconds(0.5));

                Assert.Equal(0.5, target.Opacity);

                target.Classes.Remove("foo");
            }
        }
Exemplo n.º 28
0
        public void Vertical_Stays_Within_Constraints()
        {
            var cursorFactoryImpl = new Mock <IStandardCursorFactory>();

            AvaloniaLocator.CurrentMutable.Bind <IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object);

            var control1 = new Border {
                [Grid.ColumnProperty] = 0
            };
            var splitter = new GridSplitter
            {
                Orientation           = Orientation.Vertical,
                [Grid.ColumnProperty] = 1,
            };
            var control2 = new Border {
                [Grid.ColumnProperty] = 2
            };

            var columnDefinitions = new ColumnDefinitions()
            {
                new ColumnDefinition(1, GridUnitType.Star)
                {
                    MinWidth = 10, MaxWidth = 190
                },
                new ColumnDefinition(GridLength.Auto),
                new ColumnDefinition(1, GridUnitType.Star)
                {
                    MinWidth = 80, MaxWidth = 120
                },
            };

            var grid = new Grid()
            {
                ColumnDefinitions = columnDefinitions,
                Children          = new Controls()
                {
                    control1, splitter, control2
                }
            };

            var root = new TestRoot {
                Child = grid
            };

            Assert.Equal(splitter.Orientation, Orientation.Vertical);

            root.Measure(new Size(200, 100));
            root.Arrange(new Rect(0, 0, 200, 100));

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(-100, 0)
            });
            Assert.Equal(columnDefinitions[0].Width, new GridLength(80, GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(120, GridUnitType.Star));
            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(100, 0)
            });
            Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star));
        }
Exemplo n.º 29
0
        public void Should_Update_When_Control_Moved_Causing_Layout_Change()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                Decorator moveFrom;
                Decorator moveTo;
                Canvas    moveMe;
                var       tree = new TestRoot
                {
                    Width  = 100,
                    Height = 100,
                    Child  = new DockPanel
                    {
                        Children =
                        {
                            (moveFrom      = new Decorator
                            {
                                Child      = moveMe = new Canvas
                                {
                                    Width  = 100,
                                    Height =        100,
                                },
                            }),
                            (moveTo        = new Decorator()),
                        }
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(tree.DesiredSize));

                var scene        = new Scene(tree);
                var sceneBuilder = new SceneBuilder();
                sceneBuilder.UpdateAll(scene);

                var moveFromNode = (VisualNode)scene.FindNode(moveFrom);
                var moveToNode   = (VisualNode)scene.FindNode(moveTo);

                Assert.Equal(1, moveFromNode.Children.Count);
                Assert.Same(moveMe, moveFromNode.Children[0].Visual);
                Assert.Empty(moveToNode.Children);

                moveFrom.Child = null;
                moveTo.Child   = moveMe;
                tree.LayoutManager.ExecuteLayoutPass();

                scene        = scene.CloneScene();
                moveFromNode = (VisualNode)scene.FindNode(moveFrom);
                moveToNode   = (VisualNode)scene.FindNode(moveTo);

                moveFromNode.SortChildren(scene);
                moveToNode.SortChildren(scene);
                sceneBuilder.Update(scene, moveFrom);
                sceneBuilder.Update(scene, moveTo);
                sceneBuilder.Update(scene, moveMe);

                Assert.Empty(moveFromNode.Children);
                Assert.Equal(1, moveToNode.Children.Count);
                Assert.Same(moveMe, moveToNode.Children[0].Visual);
            }
        }
Exemplo n.º 30
0
        public void Horizontal_Stays_Within_Constraints()
        {
            var cursorFactoryImpl = new Mock <IStandardCursorFactory>();

            AvaloniaLocator.CurrentMutable.Bind <IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object);

            var control1 = new Border {
                [Grid.RowProperty] = 0
            };
            var splitter = new GridSplitter
            {
                Orientation        = Orientation.Horizontal,
                [Grid.RowProperty] = 1,
            };
            var control2 = new Border {
                [Grid.RowProperty] = 2
            };

            var rowDefinitions = new RowDefinitions()
            {
                new RowDefinition(1, GridUnitType.Star)
                {
                    MinHeight = 70, MaxHeight = 110
                },
                new RowDefinition(GridLength.Auto),
                new RowDefinition(1, GridUnitType.Star)
                {
                    MinHeight = 10, MaxHeight = 140
                },
            };

            var grid = new Grid()
            {
                RowDefinitions = rowDefinitions,
                Children       = new Controls()
                {
                    control1, splitter, control2
                }
            };

            var root = new TestRoot {
                Child = grid
            };

            Assert.Equal(splitter.Orientation, Orientation.Horizontal);
            root.Measure(new Size(100, 200));
            root.Arrange(new Rect(0, 0, 100, 200));

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(0, -100)
            });
            Assert.Equal(rowDefinitions[0].Height, new GridLength(70, GridUnitType.Star));
            Assert.Equal(rowDefinitions[2].Height, new GridLength(130, GridUnitType.Star));
            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector      = new Vector(0, 100)
            });
            Assert.Equal(rowDefinitions[0].Height, new GridLength(110, GridUnitType.Star));
            Assert.Equal(rowDefinitions[2].Height, new GridLength(90, GridUnitType.Star));
        }
Exemplo n.º 31
0
        public void Should_Create_And_Delete_Layers_For_Transparent_Controls()
        {
            Border border;
            var    root = new TestRoot
            {
                Width  = 100,
                Height = 100,
                Child  = new Border
                {
                    Background = Brushes.Red,
                    Child      = border = new Border
                    {
                        Background = Brushes.Green,
                    }
                }
            };

            root.Measure(Size.Infinity);
            root.Arrange(new Rect(root.DesiredSize));

            var rootLayer           = CreateLayer();
            var borderLayer         = CreateLayer();
            var renderTargetContext = Mock.Get(root.CreateRenderTarget().CreateDrawingContext(null));

            renderTargetContext.SetupSequence(x => x.CreateLayer(It.IsAny <Size>()))
            .Returns(rootLayer)
            .Returns(borderLayer);

            var loop   = new Mock <IRenderLoop>();
            var target = new DeferredRenderer(
                root,
                loop.Object,
                dispatcher: new ImmediateDispatcher());

            root.Renderer = target;

            target.Start();
            RunFrame(loop);

            var rootContext   = Mock.Get(rootLayer.CreateDrawingContext(null));
            var borderContext = Mock.Get(borderLayer.CreateDrawingContext(null));

            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
            borderContext.Verify(x => x.FillRectangle(It.IsAny <IBrush>(), It.IsAny <Rect>(), It.IsAny <float>()), Times.Never);

            rootContext.ResetCalls();
            borderContext.ResetCalls();
            border.Opacity = 0.5;
            RunFrame(loop);

            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Never);
            borderContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);

            rootContext.ResetCalls();
            borderContext.ResetCalls();
            border.Opacity = 1;
            RunFrame(loop);

            Mock.Get(borderLayer).Verify(x => x.Dispose());
            rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
            rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
            borderContext.Verify(x => x.FillRectangle(It.IsAny <IBrush>(), It.IsAny <Rect>(), It.IsAny <float>()), Times.Never);
        }
Exemplo n.º 32
-1
        public void Vertical_Stays_Within_Constraints()
        {
            var cursorFactoryImpl = new Mock<IStandardCursorFactory>();
            PerspexLocator.CurrentMutable.Bind<IStandardCursorFactory>().ToConstant(cursorFactoryImpl.Object);

            var control1 = new Border { [Grid.ColumnProperty] = 0 };
            var splitter = new GridSplitter
            {
                Orientation = Orientation.Vertical,
                [Grid.ColumnProperty] = 1,
            };
            var control2 = new Border { [Grid.ColumnProperty] = 2 };

            var columnDefinitions = new ColumnDefinitions()
            {
                new ColumnDefinition(1, GridUnitType.Star) {MinWidth = 10, MaxWidth = 190},
                new ColumnDefinition(GridLength.Auto),
                new ColumnDefinition(1, GridUnitType.Star) {MinWidth = 80, MaxWidth =  120},
            };

            var grid = new Grid()
            {
                ColumnDefinitions = columnDefinitions,
                Children = new Controls()
                {
                    control1, splitter, control2
                }
            };

            var root = new TestRoot { Child = grid };
            Assert.Equal(splitter.Orientation, Orientation.Vertical);

            root.Measure(new Size(200, 100));
            root.Arrange(new Rect(0, 0, 200, 100));

            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector = new Vector(-100,0)
            });
            Assert.Equal(columnDefinitions[0].Width, new GridLength(80,GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(120,GridUnitType.Star));
            splitter.RaiseEvent(new VectorEventArgs
            {
                RoutedEvent = Thumb.DragDeltaEvent,
                Vector = new Vector(100, 0)
            });
            Assert.Equal(columnDefinitions[0].Width, new GridLength(120, GridUnitType.Star));
            Assert.Equal(columnDefinitions[2].Width, new GridLength(80, GridUnitType.Star));
        }