Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sdk ui enter-leave pointer events #2907

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public VisualElement Transform

internal EventCallback<PointerDownEvent> currentOnPointerDownCallback;
internal EventCallback<PointerUpEvent> currentOnPointerUpCallback;
internal EventCallback<PointerEnterEvent> currentOnPointerEnterCallback;
internal EventCallback<PointerLeaveEvent> currentOnPointerLeaveCallback;


private VisualElement rootTransform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public void SetUp()
[Test]
[TestCase(PointerEventType.PetDown)]
[TestCase(PointerEventType.PetUp)]
[TestCase(PointerEventType.PetHoverEnter)]
[TestCase(PointerEventType.PetHoverLeave)]
public void TriggerPointerEvents(PointerEventType eventType)
{
// Arrange
Expand All @@ -49,6 +51,16 @@ public void TriggerPointerEvents(PointerEventType eventType)
EventType = PointerEventType.PetUp,
EventInfo = new PBPointerEvents.Types.Info(),
});
input.PointerEvents.Add(new PBPointerEvents.Types.Entry
{
EventType = PointerEventType.PetHoverEnter,
EventInfo = new PBPointerEvents.Types.Info(),
});
input.PointerEvents.Add(new PBPointerEvents.Types.Entry
{
EventType = PointerEventType.PetHoverLeave,
EventInfo = new PBPointerEvents.Types.Info(),
});

world.Add(entity, input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,26 @@ public static void RegisterPointerCallbacks(this UITransformComponent uiTransfor
{
EventCallback<PointerDownEvent> newOnPointerDownCallback = _ => uiTransformComponent.PointerEventTriggered = PointerEventType.PetDown;
EventCallback<PointerUpEvent> newOnPointerUpCallback = _ => uiTransformComponent.PointerEventTriggered = PointerEventType.PetUp;
EventCallback<PointerEnterEvent> newOnPointerEnterCallback = _ => uiTransformComponent.PointerEventTriggered = PointerEventType.PetHoverEnter;
EventCallback<PointerLeaveEvent> newOnPointerLeaveCallback = _ => uiTransformComponent.PointerEventTriggered = PointerEventType.PetHoverLeave;

uiTransformComponent.UnregisterPointerCallbacks();
uiTransformComponent.Transform.RegisterCallback(newOnPointerDownCallback);
uiTransformComponent.currentOnPointerDownCallback = newOnPointerDownCallback;
uiTransformComponent.Transform.RegisterCallback(newOnPointerUpCallback);
uiTransformComponent.currentOnPointerUpCallback = newOnPointerUpCallback;
uiTransformComponent.Transform.RegisterCallback(newOnPointerEnterCallback);
uiTransformComponent.currentOnPointerEnterCallback = newOnPointerEnterCallback;
uiTransformComponent.Transform.RegisterCallback(newOnPointerLeaveCallback);
uiTransformComponent.currentOnPointerLeaveCallback = newOnPointerLeaveCallback;
}

public static void UnregisterPointerCallbacks(this UITransformComponent uiTransformComponent)
{
uiTransformComponent.Transform.UnregisterCallback(uiTransformComponent.currentOnPointerDownCallback);
uiTransformComponent.Transform.UnregisterCallback(uiTransformComponent.currentOnPointerUpCallback);
uiTransformComponent.Transform.UnregisterCallback(uiTransformComponent.currentOnPointerEnterCallback);
uiTransformComponent.Transform.UnregisterCallback(uiTransformComponent.currentOnPointerLeaveCallback);
}

public static void RegisterInputCallbacks(this UIInputComponent uiInputComponent, IInputBlock inputBlock)
Expand Down
Loading