Display grab cursor 2 (#9982)

Fixes #9906, but the grab hand appears only when actually moving nodes.

Also changed cursor on some widgets.
This commit is contained in:
Adam Obuchowicz 2024-05-20 09:24:45 +02:00 committed by GitHub
parent fe28c23658
commit e13950ed0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 8 deletions

View File

@ -246,13 +246,13 @@ const transform = computed(() => {
})
const startEpochMs = ref(0)
let significantMove = false
const significantMove = ref(false)
const dragPointer = usePointer(
(pos, event, type) => {
if (type !== 'start') {
if (
!significantMove &&
!significantMove.value &&
(Number(new Date()) - startEpochMs.value >= MAXIMUM_CLICK_LENGTH_MS ||
pos.relative.lengthSquared() >= MAXIMUM_CLICK_DISTANCE_SQ)
) {
@ -260,7 +260,7 @@ const dragPointer = usePointer(
// prevent `click` on widgets.
if (event.currentTarget instanceof Element)
event.currentTarget.setPointerCapture?.(event.pointerId)
significantMove = true
significantMove.value = true
}
const fullOffset = pos.relative
emit('dragging', fullOffset)
@ -268,7 +268,7 @@ const dragPointer = usePointer(
switch (type) {
case 'start':
startEpochMs.value = Number(new Date())
significantMove = false
significantMove.value = false
break
case 'stop': {
startEpochMs.value = 0
@ -280,6 +280,7 @@ const dragPointer = usePointer(
// is not going to be a node drag.
{ pointerCapturedBy: 'target' },
)
const isDragged = computed(() => dragPointer.dragging && significantMove)
const isRecordingOverridden = computed({
get() {
@ -371,13 +372,13 @@ const handlePortClick = useDoubleClick(
const handleNodeClick = useDoubleClick(
(e: MouseEvent) => {
if (!significantMove) {
if (!significantMove.value) {
nodeSelection?.handleSelectionOf(e, new Set([nodeId.value]))
nodeEditHandler(e)
}
},
() => {
if (!significantMove) emit('doubleClick')
if (!significantMove.value) emit('doubleClick')
},
).handleClick
@ -475,6 +476,7 @@ const matchableNodeColors = getNodeColors((node) => node !== nodeId.value)
<Teleport :to="graphNodeSelections">
<GraphNodeSelection
v-if="navigator"
:class="{ dragged: isDragged }"
:nodePosition="props.node.position"
:nodeSize="nodeSize"
:selected
@ -539,7 +541,12 @@ const matchableNodeColors = getNodeColors((node) => node !== nodeId.value)
@createNodes="emit('createNodes', $event)"
/>
<GraphNodeComment v-model:editing="editingComment" :node="node" class="beforeNode" />
<div ref="contentNode" class="content" v-on="dragPointer.events" @click="handleNodeClick">
<div
ref="contentNode"
:class="{ content: true, dragged: isDragged }"
v-on="dragPointer.events"
@click="handleNodeClick"
>
<NodeWidgetTree
:ast="props.node.innerExpr"
:nodeId="nodeId"
@ -802,4 +809,12 @@ const matchableNodeColors = getNodeColors((node) => node !== nodeId.value)
right: 100%;
margin-right: 4px;
}
.draggable {
cursor: grab;
}
.dragged {
cursor: grabbing;
}
</style>

View File

@ -406,6 +406,7 @@ declare module '@/providers/widgetRegistry' {
align-items: center;
position: relative;
min-height: var(--node-port-height);
cursor: pointer;
}
.arrow {

View File

@ -82,7 +82,6 @@ defineExpose({
height: 24px;
appearance: textfield;
-moz-appearance: textfield;
cursor: default;
user-select: all;
box-sizing: content-box;
&:focus {

View File

@ -516,6 +516,7 @@ div {
-2px 0 0 transparent;
transition: box-shadow 0.2s ease;
pointer-events: none;
cursor: grab;
&:before {
content: '';