From 7677d593467e7cc29cf10f28301152776c027bd2 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 28 Jun 2022 22:24:55 +1000 Subject: Use double-taps on mobile --- src/App.vue | 6 ++++-- src/components/Tile.vue | 38 +++++++++++++++++++++++++++++--------- src/components/TutorialPane.vue | 3 +-- src/index.css | 1 + src/lib.ts | 1 + src/util.ts | 4 ++++ 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/App.vue b/src/App.vue index f67cbb1..42a4cd9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,7 +3,7 @@ :style="{backgroundColor: uiOpts.bgColor}">
-

Tilo

+

Tilo (prototype)

@@ -86,7 +86,8 @@ import HelpIcon from './components/icon/HelpIcon.vue'; import {TolNode, TolMap, getServerResponse, Action, UiOptions} from './lib'; import {LayoutNode, LayoutOptions, LayoutTreeChg} from './layout'; import {initLayoutTree, initLayoutMap, tryLayout} from './layout'; -import {getBreakpoint, getScrollBarWidth, arraySum, randWeightedChoice, timeout} from './util'; +import {getBreakpoint, getScrollBarWidth, isTouchDevice, + arraySum, randWeightedChoice, timeout} from './util'; // Type representing auto-mode actions type AutoAction = 'move across' | 'move down' | 'move up' | Action; @@ -162,6 +163,7 @@ function getDefaultUiOpts(lytOpts: LayoutOptions): UiOptions { searchJumpMode: false, tutorialSkip: false, disabledActions: new Set() as Set, + useDblClick: isTouchDevice(), }; } const lytOptPrefix = 'LYT '; // Used when saving to localStorage diff --git a/src/components/Tile.vue b/src/components/Tile.vue index 73a818a..15b1b48 100644 --- a/src/components/Tile.vue +++ b/src/components/Tile.vue @@ -425,17 +425,34 @@ export default defineComponent({ // Click handling onMouseDown(): void { this.highlight = false; - clearTimeout(this.clickHoldTimer); - this.clickHoldTimer = setTimeout(() => { - this.clickHoldTimer = 0; - this.onClickHold(); - }, this.uiOpts.clickHoldDuration); + if (!this.uiOpts.useDblClick){ + // Wait for a mouseup or click-hold + clearTimeout(this.clickHoldTimer); + this.clickHoldTimer = setTimeout(() => { + this.clickHoldTimer = 0; + this.onClickHold(); + }, this.uiOpts.clickHoldDuration); + } else { + // Wait for or recognise a double-click + if (this.clickHoldTimer == 0){ + this.clickHoldTimer = setTimeout(() => { + this.clickHoldTimer = 0; + this.onClick(); + }, this.uiOpts.clickHoldDuration); + } else { + clearTimeout(this.clickHoldTimer) + this.clickHoldTimer = 0; + this.onDblClick(); + } + } }, onMouseUp(): void { - if (this.clickHoldTimer > 0){ - clearTimeout(this.clickHoldTimer); - this.clickHoldTimer = 0; - this.onClick(); + if (!this.uiOpts.useDblClick){ + if (this.clickHoldTimer > 0){ + clearTimeout(this.clickHoldTimer); + this.clickHoldTimer = 0; + this.onClick(); + } } }, onClick(): void { @@ -453,6 +470,9 @@ export default defineComponent({ } this.$emit(this.isLeaf ? 'leaf-click-held' : 'nonleaf-click-held', this.layoutNode); }, + onDblClick(): void { + this.onClickHold(); + }, onInfoIconClick(evt: Event): void { this.$emit('info-click', this.layoutNode.name); }, diff --git a/src/components/TutorialPane.vue b/src/components/TutorialPane.vue index 88e1c66..894d834 100644 --- a/src/components/TutorialPane.vue +++ b/src/components/TutorialPane.vue @@ -8,8 +8,7 @@