[gpu] Fix mobile gestures: long-press reset, double-tap-drag zoom

Long-press uses _web_reset directly with 10px jitter threshold.
Double-tap-drag undoes first tap's animation toggle via
_web_toggle_animation, then preventDefault blocks GLFW from
seeing the second tap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-03-30 10:59:04 -06:00
1 parent 10ca3ef37f
commit 6b111e5ca2
4 files changed
+26 -3

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ em++ \
-sUSE_WEBGL2=1 \
-sFULL_ES3=1 \
-sALLOW_MEMORY_GROWTH=1 \
-sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_reset","_web_pinch","_malloc","_free"]' \
-sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_toggle_animation","_web_reset","_web_pinch","_malloc","_free"]' \
-sEXPORTED_RUNTIME_METHODS='["UTF8ToString","lengthBytesUTF8","stringToUTF8"]' \
--shell-file "$SRCDIR/util/gpu/web/shell.html" \
-o "$OUTDIR/index.html"
+6
View File
@@ -374,6 +374,12 @@ rebuild_buffer (const char *text)
extern "C" {
EMSCRIPTEN_KEEPALIVE void
web_reset ()
{
demo_view_reset (vu);
}
EMSCRIPTEN_KEEPALIVE void
web_load_font (const char *data, int len)
{
+6
View File
@@ -120,6 +120,12 @@ web_get_text ()
return current_text;
}
EMSCRIPTEN_KEEPALIVE void
web_toggle_animation ()
{
demo_view_key_func (vu, 32 /* GLFW_KEY_SPACE */, 0, 1, 0);
}
EMSCRIPTEN_KEEPALIVE void
web_reset ()
{
+13 -2
View File
@@ -196,13 +196,19 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
if (e.touches.length === 1) {
var now = performance.now();
if (now - lastTapTime < 300) {
/* Double-tap: start zoom drag */
/* Double-tap: start zoom drag.
* Undo animation toggle from first tap. */
e.preventDefault();
if (typeof _web_toggle_animation === 'function')
_web_toggle_animation();
doubleTapZoom = true;
doubleTapY = e.touches[0].clientY;
lastTapTime = 0;
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
} else {
lastTapTime = now;
longPressX = e.touches[0].clientX;
longPressY = e.touches[0].clientY;
longPressTimer = setTimeout(function () {
longPressTimer = null;
if (typeof _web_reset === 'function') _web_reset();
@@ -233,8 +239,13 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
}));
}
}, {passive: false});
var longPressX = 0, longPressY = 0;
canvas.addEventListener('touchmove', function (e) {
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
if (longPressTimer && e.touches.length === 1) {
var dx = e.touches[0].clientX - longPressX;
var dy = e.touches[0].clientY - longPressY;
if (dx*dx + dy*dy > 100) { clearTimeout(longPressTimer); longPressTimer = null; }
}
if (doubleTapZoom && e.touches.length === 1) {
e.preventDefault();
var dy = e.touches[0].clientY - doubleTapY;