Exemple #1
0
        public void Desktop_MultipleWorkspaces()
        {
            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            bool exited = false;

            desktop.Empty += () => exited = true;

            (var window1, var element1) = CommonMocks.Widget("window");
            (var window2, var element2) = CommonMocks.Widget("window");

            var workspace1 = CreateWorkspace("default", window1.Object);
            var workspace2 = CreateWorkspace("other", window2.Object);

            desktop.PushWorkspace(workspace1);
            desktop.PushWorkspace(workspace2);

            desktop.ActiveWorkspace.Should().BeSameAs(workspace2);
            desktop.WaitForAnimations();
            desktop.ActiveWorkspace.Should().BeSameAs(workspace2);

            desktop.PopWorkspace();

            desktop.ActiveWorkspace.Should().BeSameAs(workspace2, "Active workspace should still be the old one, until the transition out animation is complete.");
            desktop.WaitForAnimations();
            desktop.ActiveWorkspace.Should().BeSameAs(workspace1, "Transition out animation is complete, so the active workspace should be the one underneath.");

            desktop.PopWorkspace();
            desktop.WaitForAnimations();

            exited.Should().BeTrue();
        }
Exemple #2
0
        public void Layout_SetsDisplayHasFocus()
        {
            var widgetsCreated = new List <IWidget>();

            for (int i = 0; i < 10; i++)
            {
                var widget = CommonMocks.Widget("test" + i).Object;

                widgetsCreated.Add(widget);
                WidgetLayout.Add(widget);
            }

            for (int j = 0; j < 10; j++)
            {
                WidgetLayout.Focus = widgetsCreated[j];

                FocusShouldBe(widgetsCreated[j]);

                for (int i = 0; i < 10; i++)
                {
                    if (i == j)
                    {
                        widgetsCreated[i].Display.HasFocus.Should().BeTrue($"item {i} should be told that it has focus");
                    }
                    else
                    {
                        widgetsCreated[i].Display.HasFocus.Should().BeFalse(
                            $"after setting item {j} to have focus, item {i} should be marked as not having focus");
                    }
                }
            }
        }
Exemple #3
0
        public void Desktop_InputIsSentToActiveWorkspaceOnly()
        {
            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            (var w1, var e1) = CommonMocks.Widget("w1", elementCanHaveFocus: true);
            (var w2, var e2) = CommonMocks.Widget("w2", elementCanHaveFocus: true);

            var workspace1 = new Workspace("a", w1.Object);
            var workspace2 = new Workspace("b", w2.Object);

            desktop.PushWorkspace(workspace2);
            desktop.PushWorkspace(workspace1);

            desktop.ClearAnimations();
            int goodCalls = 0;
            int badCalls  = 0;

            e1.Setup(x => x.OnUserInterfaceAction(It.IsAny <UserInterfaceActionEventArgs>()))
            .Callback <UserInterfaceActionEventArgs>(e => ++ goodCalls);

            e2.Setup(x => x.OnUserInterfaceAction(It.IsAny <UserInterfaceActionEventArgs>()))
            .Callback <UserInterfaceActionEventArgs>(e => ++ badCalls);

            desktop.OnUserInterfaceAction(new UserInterfaceActionEventArgs().Reset(UserInterfaceAction.Down));

            goodCalls.Should().Be(1);
            badCalls.Should().Be(0);
        }
        public void FG_ChildSizeWithMarginAndBorder()
        {
            var widget = CommonMocks.Widget("test");

            layout.Add(widget.Object, new Rectangle(0, 0, 16, 8));

            widget.Object.Display.Style.Margin              = new LayoutBox(2, 4, 6, 8);
            widget.Object.Display.Style.Border.Left.Width   = 1;
            widget.Object.Display.Style.Border.Top.Width    = 3;
            widget.Object.Display.Style.Border.Right.Width  = 5;
            widget.Object.Display.Style.Border.Bottom.Width = 7;

            Size actualParentMaxSize = new Size();

            widget.Setup(x => x.ComputeIdealSize(renderContext.Object, It.IsAny <Size>()))
            .Returns <IWidgetRenderContext, Size>((_, maxSize) =>
            {
                actualParentMaxSize = maxSize;

                return(new Size(10, 10));
            });

            gridParentMetrics.IdealContentSize = layout.ComputeIdealSize(
                gridParentMetrics.ParentMaxSize, renderContext.Object);
            layout.ApplyLayout(new Size(1920, 1080), renderContext.Object);

            actualParentMaxSize.Width.Should().Be(1920 - 14);
            actualParentMaxSize.Height.Should().Be(1080 - 22);

            widget.Object.Display.Region.ContentSize.Width.Should().Be(1920 - 14);
            widget.Object.Display.Region.ContentSize.Height.Should().Be(1080 - 22);

            widget.Object.Display.Region.Position.X.Should().Be(3);
            widget.Object.Display.Region.Position.Y.Should().Be(7);
        }
Exemple #5
0
        public void Layout_FirstItemHasFocus()
        {
            WidgetLayout.Clear();

            WidgetLayout.Focus.Should().BeNull();

            var widget = CommonMocks.Widget("widget").Object;

            WidgetLayout.Add(widget);
            WidgetLayout.Focus.Should().Be(widget);
        }
Exemple #6
0
        private void SetLayout(params string[] layoutStrings)
        {
            foreach (var line in layoutStrings)
            {
                line.Length.Should().Be(layoutStrings[0].Length,
                                        "All lines in the layout should be the same length");
            }

            var gridProps = new GridProps()
            {
                GridNavigationWrap = navigationWrap,
                Columns            = layoutStrings[0].Length
            };

            gridProps.GridNavigationWrap = navigationWrap;

            for (int y = 0; y < layoutStrings.Length; y++)
            {
                for (int x = 0; x < layoutStrings[y].Length; x++)
                {
                    bool canHaveFocus = true;

                    if (layoutStrings[y][x] == ' ')
                    {
                        canHaveFocus = false;
                    }

                    (var widget, var element) = CommonMocks.Widget($"{x},{y}", elementCanHaveFocus: canHaveFocus);

                    gridProps.Add(widget.Object);
                }
            }

            (var parentWidget, var parent) = CommonMocks.Widget("parent", elementCanHaveFocus: true);
            this.parent = parent;

            grid = new Grid(gridProps);

            var displaySystem = new Mock <IDisplaySystem>();

            displaySystem.Setup(x => x.ParentOf(grid)).Returns(
                new Func <IRenderElement, IRenderElement>(_ => this.parent.Object));

            grid.Display.System = displaySystem.Object;


            parent.Object.Children.Add(grid);
        }
Exemple #7
0
        public void Desktop_WidgetGetsInstructions()
        {
            var renderContext = new FakeRenderContext();

            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            (var widget, var element) = CommonMocks.Widget("happy");

            Workspace workspace = new Workspace("default", widget.Object);

            desktop.PushWorkspace(workspace);

            desktop.Update(renderContext);

            element.Object.Display.System.Instructions.Should().BeSameAs(desktop.Instructions);
        }
        public void LL_WidgetCapturesInput()
        {
            var inputWidget = CommonMocks.Widget("test");

            int ignoreNext = 3;

            inputWidget
            .Setup(x => x.ProcessEvent(It.IsAny <WidgetEventArgs>()))
            .Callback <WidgetEventArgs>(e =>
            {
                if (e.EventType != WidgetEventType.ButtonDown)
                {
                    return;
                }

                if (ignoreNext > 0)
                {
                    ignoreNext--;
                    e.Handled = true;
                    return;
                }
            });

            ListLayout.Insert(3, inputWidget.Object);
            ListLayout.FocusIndex = 2;
            ListLayout.FocusIndex.Should().Be(2);
            ignoreNext.Should().Be(3);

            NextItem();
            ListLayout.FocusIndex.Should().Be(3);
            ignoreNext.Should().Be(3);

            NextItem();
            ListLayout.FocusIndex.Should().Be(3);
            ignoreNext.Should().Be(2);

            NextItem();
            ListLayout.FocusIndex.Should().Be(3);
            ignoreNext.Should().Be(1);

            NextItem();
            ListLayout.FocusIndex.Should().Be(3);
            ignoreNext.Should().Be(0);

            NextItem();
            ListLayout.FocusIndex.Should().Be(4);
        }
Exemple #9
0
        public void Layout_WidgetAddedEvent()
        {
            var widgetsAdded   = new List <IWidget>();
            var widgetsCreated = new List <IWidget>();

            WidgetLayout.WidgetAdded += w => widgetsAdded.Add(w);

            for (int i = 0; i < 10; i++)
            {
                var widget = CommonMocks.Widget("test" + i).Object;

                widgetsCreated.Add(widget);
                WidgetLayout.Add(widget);
            }

            widgetsAdded.Should().BeEquivalentTo(widgetsCreated);
        }
Exemple #10
0
        public void ApplyDefaultTheme()
        {
            var             fontProvider = CommonMocks.FontProvider("default");
            ThemeCollection themes       = new ThemeCollection
            {
                ["default"] = Theme.CreateDefaultTheme(),
                ["xyz"]     = CreateTestTheme(),
            };

            ThemeStyler styler = new ThemeStyler(fontProvider.Object, themes);

            var widget = CommonMocks.Widget("widget");

            styler.ApplyStyle(widget.Object, "xyz");

            widget.Object.Display.Style.Padding.Left.Should().Be(14);
            widget.Object.Display.Font.Color.Should().Be(Color.Yellow);
        }
        public void FG_SizeMetricsPassedToLargeChild()
        {
            var widget = CommonMocks.Widget("test");

            layout.Add(widget.Object, new Point(4, 4), new Size(3, 2));

            Size actualParentMaxSize = new Size();

            widget.Setup(x => x.ComputeIdealSize(renderContext.Object, It.IsAny <Size>()))
            .Returns <IWidgetRenderContext, Size>((_, maxSize) =>
            {
                actualParentMaxSize = maxSize;
                return(new Size(10, 10));
            });

            gridParentMetrics.IdealContentSize = layout.ComputeIdealSize(
                gridParentMetrics.ParentMaxSize, renderContext.Object);

            actualParentMaxSize.Width.Should().Be(1920 / 16 * 3);
            actualParentMaxSize.Height.Should().Be(1080 / 8 * 2);
        }
        public void ApplyDefaultTheme()
        {
            var             fontProvider = CommonMocks.FontProvider("default");
            ThemeCollection themes       = new ThemeCollection
            {
                ["default"] = Theme.CreateDefaultTheme(),
                ["xyz"]     = CreateTestTheme(),
            };

            ThemeStyler styler = new ThemeStyler(themes);

            (var widget, var element) = CommonMocks.Widget("widget");

            element.Object.Display.ParentFont = fontProvider.Object.Default;

            styler.Apply(element.Object, "xyz");

            element.Object.Style.Update();
            element.Object.Display.Style.Padding.Left.Should().Be(14);
            element.Object.Style.Font.Color.Should().Be(Color.Yellow);
        }
Exemple #13
0
 private void AddWidget(int x, int y)
 {
     layout[x, y] = CommonMocks.Widget($"{x},{y}").Object;
 }