public void Updates() { MockApplication app = MockApplication.Setup <LayoutTestThing>(); app.SetViewportRect(new Rect(0, 0, 1000f, 1000f)); LayoutTestThing root = (LayoutTestThing)app.RootElement; app.Update(); Assert.AreEqual(Vector2.zero, root.child0.layoutResult.localPosition); Assert.AreEqual(new Vector2(0, 100), root.child1.layoutResult.localPosition); Assert.AreEqual(100, root.child1.layoutResult.actualSize.width); Assert.AreEqual(100, root.child1.layoutResult.actualSize.height); Assert.AreEqual(new Vector2(0, 200), root.child2.layoutResult.localPosition); Assert.AreEqual(100, root.child2.layoutResult.actualSize.width); Assert.AreEqual(100, root.child2.layoutResult.actualSize.height); root.child2.style.SetPreferredWidth(200, StyleState.Normal); app.Update(); Assert.AreEqual(Vector2.zero, root.child0.layoutResult.localPosition); Assert.AreEqual(new Vector2(0, 100), root.child1.layoutResult.localPosition); Assert.AreEqual(100, root.child1.layoutResult.actualSize.width); Assert.AreEqual(100, root.child1.layoutResult.actualSize.height); Assert.AreEqual(new Vector2(0, 200), root.child2.layoutResult.localPosition); Assert.AreEqual(200, root.child2.layoutResult.actualSize.width); Assert.AreEqual(100, root.child2.layoutResult.actualSize.height); }
public void MouseDown_StopPropagationInBubble() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; testView.InputSystem.MouseDown(new Vector2(120, 10)); root.shouldStopPropagation = true; testView.Update(); Assert.AreEqual(-1, root.clickedChildIndex); Assert.IsTrue(root.wasMouseDown); testView.InputSystem.ClearClickState(); testView.Update(); root.wasMouseDown = false; root.shouldStopPropagation = false; testView.InputSystem.MouseDown(new Vector2(120, 10)); testView.Update(); Assert.AreEqual(1, root.clickedChildIndex); Assert.IsTrue(root.wasMouseDown); }
public void DragEnter_FiresForReEnteringElement() { MockApplication testView = MockApplication.Setup <DragHandlerTestThing>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); DragHandlerTestThing root = (DragHandlerTestThing)testView.RootElement; Assert.AreEqual(0, root.dragList.Count); root.ignoreExit = true; testView.InputSystem.MouseDown(new Vector2(10, 10)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(130, 30)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); Assert.AreEqual(3, root.dragList.Count); Assert.AreEqual(new[] { "enter:child0", "enter:child1", "enter:child0" }, root.dragList.ToArray()); }
public void MouseDown_WithPropagation() { MockApplication application = MockApplication.Setup <InputSystemTestThing>(); application.Update(); application.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing root = (InputSystemTestThing)application.RootElement; application.Update(); application.InputSystem.MouseDown(new Vector2(20, 10)); application.Update(); Assert.AreEqual(0, root.clickedChildIndex); Assert.IsTrue(root.wasMouseDown); application.InputSystem.ClearClickState(); application.Update(); application.InputSystem.MouseDown(new Vector2(120, 10)); application.Update(); Assert.AreEqual(1, root.clickedChildIndex); application.InputSystem.ClearClickState(); application.Update(); application.InputSystem.MouseDown(new Vector2(220, 10)); application.Update(); Assert.AreEqual(2, root.clickedChildIndex); }
public void MouseExit_FireAgainWhenReenteredElement() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; root.ignoreExit = false; testView.InputSystem.SetMousePosition(new Vector2(20, 10)); testView.Update(); Assert.AreEqual(new string[0], root.clickList.ToArray()); testView.InputSystem.SetMousePosition(new Vector2(120, 10)); testView.Update(); testView.InputSystem.SetMousePosition(new Vector2(20, 10)); testView.Update(); testView.InputSystem.SetMousePosition(new Vector2(120, 10)); testView.Update(); Assert.AreEqual(new[] { "exit:child0", "exit:child0" }, root.clickList.ToArray()); }
public void MouseHover_DoesNotFireAfterMove() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; root.ignoreHover = false; testView.InputSystem.SetMousePosition(new Vector2(20, 10)); testView.Update(); Assert.AreEqual(new string[0], root.clickList.ToArray()); testView.InputSystem.SetMousePosition(new Vector2(20, 10)); testView.Update(); Assert.AreEqual(new[] { "hover:child0", "hover:root" }, root.clickList.ToArray()); testView.InputSystem.SetMousePosition(new Vector2(21, 10)); testView.Update(); Assert.AreEqual(new[] { "hover:child0", "hover:root" }, root.clickList.ToArray()); }
public void MouseEnter_FiresForReEnteringElement() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; root.ignoreEnter = false; MouseState mouseState = new MouseState(); mouseState.mousePosition = new Vector2(20, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); mouseState.mousePosition = new Vector2(240, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); mouseState.mousePosition = new Vector2(20, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); Assert.AreEqual(new[] { "enter:child0", "enter:root", "enter:child2", "enter:child0" }, root.clickList.ToArray()); }
public void Drag_element_and_update_synced_value_while_not_hovering_draggeed_element() { MockApplication testView = MockApplication.Setup <DragElementWithSyncBindingTestWrapper>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); DragElementWithSyncBindingTestWrapper root = (DragElementWithSyncBindingTestWrapper)testView.RootElement; testView.InputSystem.MouseDown(new Vector2(10, 10)); testView.Update(); // drag move the mouse over to the sibling element testView.InputSystem.MouseDragMove(new Vector2(20, 90)); testView.Update(); Assert.AreEqual(20, root.children[0].layoutResult.screenPosition.x); testView.InputSystem.MouseDragMove(new Vector2(31, 89)); testView.Update(); Assert.AreEqual(31, root.children[0].layoutResult.screenPosition.x); testView.InputSystem.MouseDragMove(new Vector2(30, 75)); testView.Update(); Assert.AreEqual(30, root.children[0].layoutResult.screenPosition.x); testView.InputSystem.MouseDragMove(new Vector2(400, 120)); testView.Update(); Assert.AreEqual(400, root.children[0].layoutResult.screenPosition.x); }
public void MouseMove_FiresAndPropagates() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; root.ignoreMove = false; testView.InputSystem.SetMousePosition(new Vector2(20, 10)); testView.Update(); Assert.AreEqual(new[] { "move:child0", "move:root" }, root.clickList.ToArray()); }
public void MouseUp_FiresAndPropagates() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; MouseState mouseState = new MouseState(); mouseState.leftMouseButtonState.isUpThisFrame = true; mouseState.mousePosition = new Vector2(220, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); Assert.AreEqual(new[] { "up:child2", "up:root" }, root.clickList.ToArray()); }
public void DragCreate_FromChildTemplate_LambdaArg() { MockApplication testView = MockApplication.Setup <DragTestThing_CreateLambdaArg>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); testView.InputSystem.MouseDown(new Vector2(20, 20)); testView.Update(); Assert.IsNull(testView.InputSystem.CurrentDragEvent); testView.InputSystem.MouseDragMove(new Vector2(25, 20)); testView.Update(); Assert.IsInstanceOf <TestDragEvent>(testView.InputSystem.CurrentDragEvent); Assert.AreEqual("child3", As <TestDragEvent>(testView.InputSystem.CurrentDragEvent).sourceName); }
public void Works() { MockApplication app = MockApplication.Setup <LayoutTestThing>(); app.SetViewportRect(new Rect(0, 0, 1000f, 1000f)); LayoutTestThing root = (LayoutTestThing)app.RootElement; app.Update(); Assert.AreEqual(300, root.child0.layoutResult.actualSize.width); Assert.AreEqual(100, root.child0.layoutResult.actualSize.height); Assert.AreEqual(new Vector2(0, 100), root.child1.layoutResult.localPosition); Assert.AreEqual(100, root.child1.layoutResult.actualSize.width); Assert.AreEqual(100, root.child1.layoutResult.actualSize.height); Assert.AreEqual(new Vector2(0, 200), root.child2.layoutResult.localPosition); Assert.AreEqual(100, root.child2.layoutResult.actualSize.width); Assert.AreEqual(100, root.child2.layoutResult.actualSize.height); }
public void MouseUp_OutOfBounds() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; MouseState mouseState = new MouseState(); mouseState.leftMouseButtonState.isUpThisFrame = true; mouseState.mousePosition = new Vector2(1200, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); Assert.AreEqual(new string[0], root.clickList.ToArray()); }
public void CreateAnnotationNoParameter() { MockApplication testView = MockApplication.Setup <DragTestThing_CreateAnnotationNoParameter>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); testView.InputSystem.MouseDown(new Vector2(20, 20)); testView.Update(); Assert.IsNull(testView.InputSystem.CurrentDragEvent); testView.InputSystem.MouseDragMove(new Vector2(25, 20)); testView.Update(); Assert.IsInstanceOf <TestDragEvent>(testView.InputSystem.CurrentDragEvent); Assert.AreEqual("from class", As <TestDragEvent>(testView.InputSystem.CurrentDragEvent).sourceName); }
public void CreateDragAnnotationNull() { MockApplication testView = MockApplication.Setup <DragTestThing_CreateAnnotationNull>(); DragTestThing_CreateAnnotationNull root = testView.RootElement as DragTestThing_CreateAnnotationNull; testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); testView.InputSystem.MouseDown(new Vector2(20, 20)); testView.Update(); Assert.IsNull(testView.InputSystem.CurrentDragEvent); testView.InputSystem.MouseDragMove(new Vector2(25, 20)); testView.Update(); Assert.IsNull(testView.InputSystem.CurrentDragEvent); Assert.IsTrue(root.wasCalled); }
public void MouseDown_BubbleThenCapture() { MockApplication testView = MockApplication.Setup <InputSystemTestThing2>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement; testView.Update(); MouseState mouseState = new MouseState(); mouseState.leftMouseButtonState.isDown = true; mouseState.leftMouseButtonState.isDownThisFrame = true; mouseState.mousePosition = new Vector2(120, 10); testView.InputSystem.SetMouseState(mouseState); testView.Update(); Assert.AreEqual(new[] { "down:root", "down:child1" }, root.clickList.ToArray()); }
public void DragMove_FiresAndPropagatesWithDragEvent() { MockApplication testView = MockApplication.Setup <DragHandlerTestThing_MoveWithDragEvent>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); DragHandlerTestThing_MoveWithDragEvent root = (DragHandlerTestThing_MoveWithDragEvent)testView.RootElement; testView.InputSystem.MouseDown(new Vector2(10, 10)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); Assert.AreEqual(new string[0], root.dragList.ToArray()); testView.InputSystem.MouseDragMove(new Vector2(30, 20)); testView.Update(); Assert.AreEqual(new[] { "move:child0:root" }, root.dragList.ToArray()); }
public void DragMove_DoesNotFireAgainWhenNotMovedAndContains() { MockApplication testView = MockApplication.Setup <DragHandlerTestThing_Move>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); DragHandlerTestThing_Move root = (DragHandlerTestThing_Move)testView.RootElement; testView.InputSystem.MouseDown(new Vector2(10, 10)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(31, 20)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(31, 20)); testView.Update(); Assert.AreEqual(new[] { "move:child0", "hover:child0" }, root.dragList.ToArray()); }
public void DragExit_FireAgainWhenReenteredElement() { MockApplication testView = MockApplication.Setup <DragHandlerTestThing>(); testView.Update(); testView.SetViewportRect(new Rect(0, 0, 1000, 1000)); DragHandlerTestThing root = (DragHandlerTestThing)testView.RootElement; testView.InputSystem.MouseDown(new Vector2(10, 10)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(130, 30)); testView.Update(); testView.InputSystem.MouseDragMove(new Vector2(30, 30)); testView.Update(); Assert.AreEqual(5, root.dragList.Count); Assert.AreEqual(new[] { "enter:child0", "exit:child0", "enter:child1", "exit:child1", "enter:child0" }, root.dragList.ToArray()); }