Edge scroll, minor refactoring

This commit is contained in:
barsdeveloper
2023-02-08 22:15:37 +01:00
parent cb98b85084
commit 319f5af77f
20 changed files with 175 additions and 60 deletions

View File

@@ -74,7 +74,30 @@ export default class IMouseClickDrag extends IPointing {
const movement = [e.movementX, e.movementY]
this.dragTo(location, movement)
if (this.#trackingMouse) {
this.blueprint.mousePosition = this.locationFromEvent(e)
this.blueprint.mousePosition = location
}
if (this.options.scrollGraphEdge) {
const movementNorm = Math.sqrt(movement[0] * movement[0] + movement[1] * movement[1])
const threshold = this.blueprint.scaleCorrect(Configuration.edgeScrollThreshold)
const leftThreshold = this.blueprint.template.gridLeftVisibilityBoundary() + threshold
const rightThreshold = this.blueprint.template.gridRightVisibilityBoundary() - threshold
let scrollX = 0
if (location[0] < leftThreshold) {
scrollX = location[0] - leftThreshold
} else if (location[0] > rightThreshold) {
scrollX = location[0] - rightThreshold
}
const topThreshold = this.blueprint.template.gridTopVisibilityBoundary() + threshold
const bottomThreshold = this.blueprint.template.gridBottomVisibilityBoundary() - threshold
let scrollY = 0
if (location[1] < topThreshold) {
scrollY = location[1] - topThreshold
} else if (location[1] > bottomThreshold) {
scrollY = location[1] - bottomThreshold
}
scrollX = Utility.clamp(this.blueprint.scaleCorrectReverse(scrollX) ** 3 * movementNorm * 0.6, -20, 20)
scrollY = Utility.clamp(this.blueprint.scaleCorrectReverse(scrollY) ** 3 * movementNorm * 0.6, -20, 20)
this.blueprint.scrollDelta(scrollX, scrollY)
}
}
@@ -124,6 +147,7 @@ export default class IMouseClickDrag extends IPointing {
options.moveEverywhere ??= false
options.movementSpace ??= blueprint?.getGridDOMElement()
options.repositionOnClick ??= false
options.scrollGraphEdge ??= false
options.strictTarget ??= false
super(target, blueprint, options)
this.stepSize = parseInt(options?.stepSize ?? Configuration.gridSize)

View File

@@ -3,6 +3,7 @@ import ElementFactory from "../../element/ElementFactory"
import IMouseClickDrag from "./IMouseClickDrag"
/**
* @typedef {import("../../Blueprint").default} Blueprint
* @typedef {import("../../element/LinkElement").default} LinkElement
* @typedef {import("../../element/LinkElement").LinkElementConstructor} LinkElementConstructor
* @typedef {import("../../element/PinElement").default} PinElement
@@ -68,6 +69,16 @@ export default class MouseCreateLink extends IMouseClickDrag {
linkValid = false
/**
* @param {PinElement} target
* @param {Blueprint} blueprint
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {
options.scrollGraphEdge ??= true
super(target, blueprint, options)
}
startDrag(location) {
if (this.target.nodeElement.getType() == Configuration.nodeType.knot) {
this.#knotPin = this.target

View File

@@ -2,7 +2,8 @@ import IMouseClickDrag from "./IMouseClickDrag"
export default class Select extends IMouseClickDrag {
constructor(target, blueprint, options) {
constructor(target, blueprint, options = {}) {
options.scrollGraphEdge ??= true
super(target, blueprint, options)
this.selectorElement = this.blueprint.template.selectorElement
}