mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-15 12:57:39 +08:00
Blueprint focusable
This commit is contained in:
@@ -5,10 +5,11 @@ export default class MouseWheel extends Pointing {
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} target
|
||||
* @param {import("../Blueprint").Blueprint} blueprint
|
||||
* @param {import("../Blueprint").default} blueprint
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(target, blueprint, options) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
this.looseTarget = options?.looseTarget ?? true
|
||||
let self = this
|
||||
@@ -18,14 +19,24 @@ export default class MouseWheel extends Pointing {
|
||||
const location = self.getLocation(e)
|
||||
self.wheel(Math.sign(e.deltaY), location)
|
||||
}
|
||||
this.mouseParentWheelHandler = e => e.preventDefault()
|
||||
|
||||
if (this.blueprint.focused) {
|
||||
this.movementSpace.addEventListener('wheel', this.mouseWheelHandler, false)
|
||||
}
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
this.movementSpace.addEventListener('wheel', this.mouseWheelHandler, false)
|
||||
// Prevent movement space from being scrolled
|
||||
this.movementSpace.parentElement?.addEventListener('wheel', e => e.preventDefault())
|
||||
this.movementSpace.parentElement?.addEventListener('wheel', this.mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
blueprintUnfocused() {
|
||||
this.movementSpace.removeEventListener('wheel', this.mouseWheelHandler, false)
|
||||
this.movementSpace.parentElement?.removeEventListener('wheel', this.mouseParentWheelHandler)
|
||||
}
|
||||
|
||||
/* Subclasses will override the following method */
|
||||
wheel(variation, location) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user