Example #1
0
 public UIElementGroupScroller(IUIElementGroupScrollerConstArg arg) : base(arg)
 {
     thisCursorSize = MakeCursorSizeAtLeastOne(arg.cursorSize);
     thisInitiallyCursoredGroupElementIndex = arg.initiallyCursoredGroupElementIndex;
     thisStartSearchSpeed = MakeSureStartSearchSpeedIsGreaterThanZero(arg.startSearchSpeed);
     thisSwipeToSnapNext  = arg.swipeToSnapNext;
     thisActivatesCursoredElementsOnly = arg.activatesCursoredElementsOnly;
 }
Example #2
0
    public void Construction_StartSearchSpeedNotGreaterThanZero_ThrowException(float startSearchSpeed)
    {
        IUIElementGroupScrollerConstArg arg = CreateMockConstArg();

        arg.startSearchSpeed.Returns(startSearchSpeed);

        Assert.Throws(
            Is.TypeOf(typeof(System.InvalidOperationException)).And.Message.EqualTo("startSearchSpeed must be greater than zero"),
            () => {
            new TestUIElementGroupScroller(arg);
        }
            );
    }
Example #3
0
    public IUIElementGroupScrollerConstArg CreateMockConstArg()
    {
        IUIElementGroupScrollerConstArg arg = CreateMockConstArg(
            initiallyCursoredElementIndex: 0,
            cursorSize: new int[] { 1, 1 },
            relativeCursorPosition: new Vector2(0f, 0f),
            scrollerAxis: ScrollerAxis.Both,
            rubberBandLimitMultiplier: new Vector2(.1f, .1f),
            scrollerLength: new Vector2(200f, 100f),
            elementGroupLength: new Vector2(130f, 130f)
            );

        return(arg);
    }
Example #4
0
    public void Construction_CursorSizeLessThanOne_ReturnsOne(int[] cursorSize, int[] expected)
    {
        IUIElementGroupScrollerConstArg arg = CreateMockConstArg();

        arg.uia.GetRect().Returns(new Rect(Vector2.zero, new Vector2(130f, 130f)));
        arg.cursorSize.Returns(cursorSize);
        TestUIElementGroupScroller scroller = new TestUIElementGroupScroller(arg);

        int[] actual = scroller.thisCursorSize_Test;

        for (int i = 0; i < 2; i++)
        {
            Assert.That(actual[i], Is.EqualTo(expected[i]));
        }
    }
Example #5
0
    public void SortOutCursoredElements_Various(int[] currentCursoredElementsIndex, int[] newCursoredElementsIndex, int[] expectedElementsToDefocusIndex, int[] expectedElementsToFocusIndex)
    {
        IUIElementGroupScrollerConstArg arg = CreateMockConstArg();
        List <IUIElement> elements          = CreateUIElements(10);

        IUIElement[] currentCursoredElements   = GetUIElementsFromIndex(currentCursoredElementsIndex, elements);
        IUIElement[] newCursoredElements       = GetUIElementsFromIndex(newCursoredElementsIndex, elements);
        IUIElement[] expectedElementsToDefocus = GetUIElementsFromIndex(expectedElementsToDefocusIndex, elements);
        IUIElement[] expectedElementsToFocus   = GetUIElementsFromIndex(expectedElementsToFocusIndex, elements);

        IUIElement[] actualElementsToDefocus;
        IUIElement[] actualElementsToFocus;

        TestUIElementGroupScroller scroller = new TestUIElementGroupScroller(arg);

        scroller.SortOutCursoredElements_Test(currentCursoredElements, newCursoredElements, out actualElementsToDefocus, out actualElementsToFocus);

        Assert.That(actualElementsToDefocus, Is.EqualTo(expectedElementsToDefocus));
        Assert.That(actualElementsToFocus, Is.EqualTo(expectedElementsToFocus));
    }
Example #6
0
    public IUIElementGroupScrollerConstArg CreateMockConstArg(
        int initiallyCursoredElementIndex,
        int[] cursorSize,
        Vector2 relativeCursorPosition,
        ScrollerAxis scrollerAxis,
        Vector2 rubberBandLimitMultiplier,
        Vector2 scrollerLength,
        Vector2 elementGroupLength
        )
    {
        IUIElementGroupScrollerConstArg arg = Substitute.For <IUIElementGroupScrollerConstArg>();

        arg.initiallyCursoredGroupElementIndex.Returns(initiallyCursoredElementIndex);
        arg.cursorSize.Returns(cursorSize);
        arg.startSearchSpeed.Returns(1f);
        arg.relativeCursorPosition.Returns(relativeCursorPosition);
        arg.scrollerAxis.Returns(scrollerAxis);
        arg.rubberBandLimitMultiplier.Returns(rubberBandLimitMultiplier);
        arg.isEnabledInertia.Returns(true);
        arg.swipeToSnapNext.Returns(false);
        arg.uim.Returns(Substitute.For <IUIManager>());
        arg.processFactory.Returns(Substitute.For <IUISystemProcessFactory>());
        arg.uiElementFactory.Returns(Substitute.For <IUIElementFactory>());
        IScrollerAdaptor scrollerAdaptor = Substitute.For <IScrollerAdaptor>();

        scrollerAdaptor.GetRect().Returns(new Rect(Vector2.zero, scrollerLength));
        IUIElementGroup uieGroup = Substitute.For <IUIElementGroup>();

        uieGroup.GetGroupElementArrayIndex(Arg.Any <IUIElement>()).Returns(new int[] { 0, 0 });
        IUIElementGroupAdaptor uieGroupAdaptor = Substitute.For <IUIElementGroupAdaptor>();

        uieGroup.GetUIAdaptor().Returns(uieGroupAdaptor);
        uieGroupAdaptor.GetRect().Returns(new Rect(Vector2.zero, elementGroupLength));
        scrollerAdaptor.GetChildUIEs().Returns(new List <IUIElement>(new IUIElement[] { uieGroup }));
        arg.uia.Returns(scrollerAdaptor);
        arg.image.Returns(Substitute.For <IUIImage>());
        return(arg);
    }
Example #7
0
 public TestUIElementGroupScroller(IUIElementGroupScrollerConstArg arg) : base(arg)
 {
 }