support panning using wheel

This commit is contained in:
Sanster 2022-04-27 17:25:39 +08:00
parent 390933f0eb
commit bf1e990f00
2 changed files with 23 additions and 2 deletions

View File

@ -21,7 +21,13 @@ import inpaint from '../../adapters/inpainting'
import Button from '../shared/Button'
import Slider from './Slider'
import SizeSelector from './SizeSelector'
import { downloadImage, isRightClick, loadImage, useImage } from '../../utils'
import {
downloadImage,
isMidClick,
isRightClick,
loadImage,
useImage,
} from '../../utils'
import { settingState } from '../../store/Atoms'
const TOOLBAR_SIZE = 200
@ -341,7 +347,11 @@ export default function Editor(props: EditorProps) {
drawOnCurrentRender(lineGroup)
}
const onPointerUp = () => {
const onPointerUp = (ev: SyntheticEvent) => {
if (isMidClick(ev)) {
setIsPanning(false)
}
if (isPanning) {
return
}
@ -389,6 +399,12 @@ export default function Editor(props: EditorProps) {
if (isRightClick(ev)) {
return
}
if (isMidClick(ev)) {
setIsPanning(true)
return
}
setIsDraging(true)
let lineGroup: LineGroup = []

View File

@ -187,3 +187,8 @@ export function isRightClick(ev: SyntheticEvent) {
const mouseEvent = ev.nativeEvent as MouseEvent
return mouseEvent.button === 2
}
export function isMidClick(ev: SyntheticEvent) {
const mouseEvent = ev.nativeEvent as MouseEvent
return mouseEvent.button === 1
}