-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
isDblclickAction
init config (#1710)
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Circle, Group, Text } from '../../../packages/g'; | ||
Check notice Code scanning / CodeQL Unused variable, import, function or class Note test
Unused import Group.
|
||
|
||
export async function dblClick(context) { | ||
const { canvas } = context; | ||
await canvas.ready; | ||
|
||
let DELAY = 200; | ||
canvas.isDblclickAction = (now, lastClickTime) => now - lastClickTime < DELAY; | ||
|
||
// fill | ||
const circle0 = new Circle({ | ||
style: { | ||
cx: 100, | ||
cy: 100, | ||
r: 50, | ||
fill: 'red', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
const circle1 = new Circle({ | ||
style: { | ||
cx: 300, | ||
cy: 100, | ||
r: 50, | ||
fill: 'red', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
const circle2 = new Circle({ | ||
style: { | ||
cx: 500, | ||
cy: 100, | ||
r: 50, | ||
fill: 'red', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
const text0 = new Text({ | ||
style: { x: 0, y: 200, text: `current dblclick delay: ${DELAY}ms` }, | ||
}); | ||
const text1 = new Text({ | ||
style: { x: 0, y: 220, text: `action: ` }, | ||
}); | ||
|
||
circle0.addEventListener('mouseenter', () => { | ||
DELAY = 200; | ||
text0.attr({ text: `current dblclick delay: ${DELAY}ms` }); | ||
text1.attr({ | ||
text: `action: `, | ||
}); | ||
}); | ||
circle1.addEventListener('mouseenter', () => { | ||
DELAY = 500; | ||
text0.attr({ text: `current dblclick delay: ${DELAY}ms` }); | ||
text1.attr({ | ||
text: `action: `, | ||
}); | ||
}); | ||
circle2.addEventListener('mouseenter', () => { | ||
DELAY = 1000; | ||
text0.attr({ text: `current dblclick delay: ${DELAY}ms` }); | ||
text1.attr({ | ||
text: `action: `, | ||
}); | ||
}); | ||
|
||
canvas.addEventListener('click', (event) => { | ||
console.log('click', event.detail); | ||
text1.attr({ | ||
text: `action: ${event.detail === 2 ? 'dblclick' : 'click'}`, | ||
}); | ||
}); | ||
|
||
canvas.appendChild(circle0); | ||
canvas.appendChild(circle1); | ||
canvas.appendChild(circle2); | ||
canvas.appendChild(text0); | ||
canvas.appendChild(text1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters