Example #1
0
        public void MeasureVertical()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing = 5;
            g.Add(LayoutTestWidget.FixedSize(200, 100));
            g.Add(LayoutTestWidget.FixedSize(150, 50));

            g.Measure(Size.Auto);

            g.DesiredSize.Should().Be(new Size(200, 155));
            g[0].DesiredSize.Should().Be(new Size(200, 100));
            g[1].DesiredSize.Should().Be(new Size(150, 50));
        }
Example #2
0
        public void ArrangeVerticalWithAnchor()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing = 5;
            g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.Full));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.Full));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 155));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 400, 100));
            g[1].LayoutRect.Should().Be(new Rectangle(10, 125, 400, 50));
        }
Example #3
0
        public void ArrangeHorizontal()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 355, 300));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 100));
            g[1].LayoutRect.Should().Be(new Rectangle(215, 20, 150, 50));
        }
Example #4
0
        public void MeasureHorizontal()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(200, 100));
            g.Add(LayoutTestWidget.FixedSize(150, 50));

            g.Measure(Size.Auto);

            g.DesiredSize.Should().Be(new Size(355, 100));
            g[0].DesiredSize.Should().Be(new Size(200, 100));
            g[1].DesiredSize.Should().Be(new Size(150, 50));
        }
Example #5
0
        public void ArrangeHorizontalExpanded()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.Full));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.Full), true);
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.Full));

            g.Arrange(new Rectangle(10, 20, 800, 500));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 800, 500));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 500));
            g[1].LayoutRect.Should().Be(new Rectangle(215, 20, 440, 500));
            g[2].LayoutRect.Should().Be(new Rectangle(660, 20, 150, 500));
        }
Example #6
0
        public void ArrangeVerticalExpanded()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing = 5;
            g.Add(LayoutTestWidget.FixedSize(200, 100));
            g.Add(LayoutTestWidget.FixedSize(150, 50), true);
            g.Add(LayoutTestWidget.FixedSize(150, 50), true);
            g.Add(LayoutTestWidget.FixedSize(150, 50));

            g.Arrange(new Rectangle(10, 20, 400, 1300));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 1300));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 400, 100));
            g[1].LayoutRect.Should().Be(new Rectangle(10, 125, 400, 567));
            g[2].LayoutRect.Should().Be(new Rectangle(10, 697, 400, 568));
            g[3].LayoutRect.Should().Be(new Rectangle(10, 1270, 400, 50));
        }
Example #7
0
        public void ArrangeHugeAnchored()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(2000, 1000).WithAnchorRect(AnchoredRect.CreateCentered(500, 500)));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateFull(10)));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.DesiredSize.Should().Be(new Size(675, 500)); // 500 + 150 + 20 (from full-anchor) + 5
            g[0].DesiredSize.Should().Be(new Size(2000, 1000));
            g[1].DesiredSize.Should().Be(new Size(150, 50));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 675, 300));
            g[0].LayoutRect.Should().Be(new Rectangle(10, -80, 500, 500));
            g[1].LayoutRect.Should().Be(new Rectangle(525, 30, 150, 280));
        }
Example #8
0
        IWidget SetupUi()
        {
            var styleSystem = uiManager.UIStyle;

            var mapX = new TextField(styleSystem);

            mapX.Anchor = AnchoredRect.CreateCentered(100);
            mapX.Content.Document.DocumentModified += (_, _) => navModel.MapXText = mapX.Text;

            var mapY = new TextField(styleSystem);

            mapY.Anchor = AnchoredRect.CreateCentered(100);
            mapY.Content.Document.DocumentModified += (_, _) => navModel.MapYText = mapY.Text;

            var button = new Button(styleSystem, "Go!");

            button.ActionPerformed   += (_, _) => navModel.TryNavigate(GameRendering);
            navModel.PropertyChanged += (_, _) => button.Enabled = navModel.Valid;

            var rotateLeftButton = new Button(styleSystem, "Left");

            rotateLeftButton.ActionPerformed         +=
                (_, _) => GameRendering.RotationSteps = (GameRendering.RotationSteps + 1) % 4;

            var rotateRightButton = new Button(styleSystem, "Right");

            rotateRightButton.ActionPerformed        +=
                (_, _) => GameRendering.RotationSteps = (GameRendering.RotationSteps - 1) % 4;

            var hbox = new BoxGroup(styleSystem, Orientation.Horizontal, 5);

            hbox.Anchor = AnchoredRect.CreateBottomLeftAnchored();
            hbox.AddStyleClass("opaque-root");
            hbox.Add(new Label(styleSystem, "Move to: X: "));
            hbox.Add(mapX);
            hbox.Add(new Label(styleSystem, "Y: "));
            hbox.Add(mapY);
            hbox.Add(button);
            hbox.Add(rotateLeftButton);
            hbox.Add(rotateRightButton);

            group = new Group(styleSystem);
            group.Add(hbox);
            group.Focusable     = true;
            group.MouseDragged += OnMouseDragged;
            group.MouseDown    += OnMouseDragStarted;
            group.MouseUp      += OnMouseDragFinished;
            group.KeyReleased  += Root_KeyReleased;
            group.MouseMoved   += OnMouseMoved;
            group.Focused       = true;
            group.Anchor        = AnchoredRect.Full;
            return(group);
        }
Example #9
0
        public void ValidateWidgetEvents()
        {
            var      style   = LayoutTestStyle.Create();
            BoxGroup backend = new BoxGroup(style);
            var      label   = new Label(style);

            var d = Substitute.For <EventHandler <ContainerEventArgs> >();

            backend.ChildrenChanged += d;

            backend.Add(label);
            d.Received().Invoke(backend, new ContainerEventArgs(0, null, null, label, false));

            backend.Should().BeEquivalentTo(new[] { label });
        }
Example #10
0
        public void BindTo_Conflicts_with_widget_changes()
        {
            // Note: T
            var style   = LayoutTestStyle.Create();
            var backend = new BoxGroup(style);

            var sourceList = new ObservableCollection <WidgetAndConstraint <bool> >();

            sourceList.ToBinding().BindTo(backend);
            try
            {
                backend.Add(new Label(style));
                throw new AssertionException("Expected to raise exception.");
            }
            catch (InvalidOperationException)
            {
                // ok
            }
        }
Example #11
0
        public void CreateBinding()
        {
            var      style   = LayoutTestStyle.Create();
            BoxGroup backend = new BoxGroup(style);
            var      label   = new Label(style);

            var binding = backend.ToBinding();

            using (var monitoredBinding = binding.Monitor <INotifyCollectionChanged>())
            {
                backend.Add(label);
                monitoredBinding.Should().RaiseCollectionChange(
                    binding,
                    new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,
                                                         BindingAssertions.AsList(new WidgetAndConstraint <bool>(label)),
                                                         0));

                backend.WidgetsWithConstraints.Should().BeEquivalentTo(new WidgetAndConstraint <bool>(label));
                binding.Should().BeEquivalentTo(new WidgetAndConstraint <bool>(label));
            }
        }