Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit dcfa9fa

Browse files
committed
pointer hover bug fix
1 parent 2d097cb commit dcfa9fa

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

Runtime/gestures/binding.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ void _handlePointerEvent(PointerEvent evt) {
6060
return;
6161
}
6262

63-
if (evt is PointerHoverEvent) {
64-
this._handlePointerHoverEvent(evt);
65-
}
66-
6763
HitTestResult hitTestResult = null;
6864
if (evt is PointerDownEvent) {
6965
D.assert(!this._hitTests.ContainsKey(evt.pointer));

Runtime/gestures/events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public PointerExitEvent(
148148
down: false) {
149149
}
150150

151-
public static PointerExitEvent fromHoverEvent(PointerHoverEvent hover) {
151+
public static PointerExitEvent fromHoverEvent(PointerEvent hover) {
152152
return new PointerExitEvent(
153153
timeStamp: hover.timeStamp,
154154
pointer: hover.pointer,

Runtime/gestures/mouse_tracking.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public void collectMousePositions() {
133133
void exitAnnotation(_TrackedAnnotation trackedAnnotation, int deviceId) {
134134
if (trackedAnnotation.annotation?.onExit != null &&
135135
trackedAnnotation.activeDevices.Contains(deviceId)) {
136-
trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent((PointerHoverEvent)this._lastMouseEvent[deviceId]));
136+
trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent(this._lastMouseEvent[deviceId]));
137+
trackedAnnotation.activeDevices.Remove(deviceId);
137138
}
138139
}
139140

Runtime/rendering/binding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void _handlePersistentFrameCallback(TimeSpan timeStamp) {
7272
MouseTracker _createMouseTracker() {
7373
return new MouseTracker(this.pointerRouter, (Offset offset) => {
7474
return this.renderView.layer.find<MouseTrackerAnnotation>(
75-
offset * Window.instance.devicePixelRatio
75+
offset
7676
);
7777
});
7878
}

Tests/Editor/MouseHover.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
using Unity.UIWidgets.foundation;
33
using Unity.UIWidgets.painting;
44
using Unity.UIWidgets.rendering;
5-
using Unity.UIWidgets.ui;
65
using Unity.UIWidgets.widgets;
6+
using UnityEngine;
7+
using Color = Unity.UIWidgets.ui.Color;
78

89
namespace UIWidgets.Tests {
910
public class MouseHoverWidget : StatefulWidget {
@@ -20,14 +21,14 @@ public static Widget createRow(bool canHover = true, bool nest = false) {
2021
Widget result = new Container(width: 200, height: 60, color: Color.fromARGB(255, 255, 0, 255));
2122
if (canHover) {
2223
result = new HoverTrackWidget(null,
23-
result);
24+
result, "inner");
2425
}
2526

2627
if (nest) {
2728
result = new Container(child: result, padding: EdgeInsets.all(40),
2829
color: Color.fromARGB(255, 255, 0, 0));
2930
result = new HoverTrackWidget(null,
30-
result);
31+
result, "outer");
3132
}
3233

3334
return result;
@@ -50,9 +51,11 @@ public override Widget build(BuildContext context) {
5051

5152
public class HoverTrackWidget : StatefulWidget {
5253
public readonly Widget child;
54+
public readonly string name;
5355

54-
public HoverTrackWidget(Key key, Widget child) : base(key) {
56+
public HoverTrackWidget(Key key, Widget child, string name) : base(key) {
5557
this.child = child;
58+
this.name = name;
5659
}
5760

5861
public override State createState() {
@@ -73,11 +76,13 @@ public override Widget build(BuildContext context) {
7376
),
7477
onPointerEnter: (evt) => {
7578
if (this.mounted) {
79+
Debug.Log(this.widget.name + " pointer enter");
7680
this.setState(() => { this.hover = true; });
7781
}
7882
},
7983
onPointerExit: (evt) => {
8084
if (this.mounted) {
85+
Debug.Log(this.widget.name + " pointer exit");
8186
this.setState(() => { this.hover = false; });
8287
}
8388
}

0 commit comments

Comments
 (0)