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

fix crosshair on mobiles and keep state on panmove #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 32 additions & 6 deletions src/core/input/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Input {
this.rrId = comp.rrUpdId
this.gridUpdId = comp.gridUpdId
this.gridId = comp.id
this.cursor = {} // TODO: implement
this.cursor = comp.props.cursor
this.oldMeta = {} // TODO: implement
this.range = this.props.range
this.interval = this.props.interval
Expand Down Expand Up @@ -72,9 +72,19 @@ export default class Input {
if (Utils.isMobile) mc.add(new Hammer.Press())

mc.on('panstart', event => {
if (this.cursor.scroll_lock) return
if (this.cursor.scrollLock) return
if (this.cursor.mode === 'aim') {
return this.emitCursorCoord(event)
this.oldMeta.panmoveX = undefined
this.oldMeta.panmoveY = undefined
this.oldMeta.panstartX = this.cursor.x
this.oldMeta.panstartY = this.cursor.y
const e = {
center: {
x: this.cursor.x - this.offsetX,
y: this.cursor.y - this.offsetY,
}
}
return this.emitCursorCoord(e, {visible: true})
}
let scaleId = this.layout.scaleIndex
let tfrm = this.meta.getYtransform(this.gridId, scaleId)
Expand Down Expand Up @@ -114,7 +124,22 @@ export default class Input {
y: event.center.y + this.offsetY
})*/
} else if (this.cursor.mode === 'aim') {
this.emitCursorCoord(event)
if (!(this.oldMeta.panmoveX && this.oldMeta.panmoveY)) {
this.oldMeta.panmoveX = event.center.x
this.oldMeta.panmoveY = event.center.y
return
}

const deltaX = event.center.x - this.oldMeta.panmoveX
const deltaY = event.center.y - this.oldMeta.panmoveY

const e = {
center: {
x: this.oldMeta.panstartX + deltaX - this.offsetX,
y: this.oldMeta.panstartY + deltaY - this.offsetY,
}
}
this.emitCursorCoord(e, { visible: true })
}
})

Expand All @@ -132,7 +157,8 @@ export default class Input {
if (this.fade) this.fade.stop()
this.events.emit('cursor-changed', {})
this.events.emit('cursor-changed', {
mode: 'explore'
mode: 'explore',
visible: false,
})
this.events.emitSpec(this.rrId, 'update-rr')
})
Expand All @@ -157,7 +183,7 @@ export default class Input {
if (!Utils.isMobile) return
if (this.fade) this.fade.stop()
this.calcOffset()
this.emitCursorCoord(event, { mode: 'aim' })
this.emitCursorCoord(event, { mode: 'aim', visible: true })
setTimeout(() => this.events.emitSpec(this.rrId, 'update-rr'))
this.simMousedown(event)
})
Expand Down