Skip to content

Commit 61841ae

Browse files
authored
fix offscreen coordinates (#377)
* fix offscreen coordinates? * fix offscreen coordinates? * add missing bracket
1 parent 3a4d93b commit 61841ae

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/offscreen.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ class OffscreenCanvasView extends DOMWidgetView {
8282
}
8383

8484
const rect = that.el.getBoundingClientRect();
85+
const scaleX = that.el.width / rect.width;
86+
const scaleY = that.el.height / rect.height;
8587
try {
8688
await (globalThis as any).callGlobalReceiver(
8789
_receiver_name(),
8890
'on_mouse_events',
8991
event.type,
90-
event.clientX - rect.left,
91-
event.clientY - rect.top
92+
(event.clientX - rect.left) * scaleX,
93+
(event.clientY - rect.top) * scaleY
9294
);
9395
} catch (e) {
9496
// we want to remove all event listeners if the receiver is not defined
@@ -99,18 +101,19 @@ class OffscreenCanvasView extends DOMWidgetView {
99101
removeAllListeners();
100102
}
101103
}
102-
103104
async function sendTouchEvent(event: TouchEvent): Promise<void> {
104105
const rect = that.el.getBoundingClientRect();
106+
const scaleX = that.el.width / rect.width;
107+
const scaleY = that.el.height / rect.height;
105108
try {
106109
for (let i = 0; i < event.changedTouches.length; i++) {
107110
const touch = event.changedTouches[i];
108111
await (globalThis as any).callGlobalReceiver(
109112
_receiver_name(),
110113
'on_touch_events',
111114
event.type,
112-
touch.clientX - rect.left,
113-
touch.clientY - rect.top,
115+
(touch.clientX - rect.left) * scaleX,
116+
(touch.clientY - rect.top) * scaleY,
114117
touch.identifier
115118
);
116119
}

0 commit comments

Comments
 (0)