enso/app/gui2/stories/SelectionBrushWrapper.vue
Paweł Grabarz c996707027
Add support for touch-based graph navigation and selection (#11056)
Fixes #9493

Tested on windows desktop (standard mouse), macbook touchpad and iphone, which should behave similarily to windows touchscreen devices.
2024-09-20 16:31:45 +00:00

37 lines
1.1 KiB
Vue

<script setup lang="ts">
import { computed, ref, shallowRef } from 'vue'
import { usePointer } from '@/composables/events'
import { useKeyboard } from '@/composables/keyboard'
import { useNavigator } from '@/composables/navigator'
import type { Vec2 } from '@/util/data/vec2'
const viewportNode = ref<HTMLElement>()
const keyboard = useKeyboard()
const navigator = useNavigator(viewportNode, keyboard)
const selectionAnchor = shallowRef<Vec2>()
const selection = usePointer((_, __, eventType) => {
if (selection.dragging && selectionAnchor.value == null) {
selectionAnchor.value = navigator.sceneMousePos?.copy()
} else if (eventType === 'stop') {
selectionAnchor.value = undefined
}
})
const scaledMousePos = computed(() => navigator.sceneMousePos?.scale(navigator.scale))
const scaledSelectionAnchor = computed(() => selectionAnchor.value?.scale(navigator.scale))
</script>
<template>
<div ref="viewportNode" style="cursor: none; height: 100%" v-on="selection.events">
<slot
:scaledMousePos="scaledMousePos"
:scaledSelectionAnchor="scaledSelectionAnchor"
:navigator="navigator"
></slot>
</div>
</template>