Added mousewheel support for PixiJS Lists.

This commit is contained in:
2019-03-29 11:40:01 +01:00
parent 6c2ae3b433
commit 1292fd23f0
116 changed files with 55687 additions and 6 deletions
+48 -2
View File
@@ -13690,6 +13690,8 @@
* left, center and right.
* @param {string} [opts.verticalAlign=middle] - The vertical position of the items. Possible values are
* top, middle and bottom.
* @param {PIXI.Application} [opts.app] - The PixiJS Application. Must be set if you want to use the mousewheel to
* scroll your list.
*/
constructor(items = [], opts = {}) {
@@ -13702,7 +13704,8 @@
align: 'left',
verticalAlign: 'middle',
width: null,
height: null
height: null,
app: null
}, opts);
this.__items = items;
@@ -13748,6 +13751,22 @@
this.on('pointercancel', this.onEnd.bind(this));
this.on('pointerout', this.onEnd.bind(this));
this.on('pointerupoutside', this.onEnd.bind(this));
this.on('scroll', this.onScroll.bind(this));
// mousewheel
//--------------------
if (this.opts.app) {
const app = this.opts.app;
app.view.addEventListener('mousewheel', event => {
event.preventDefault();
const bounds = this.mask ? this.mask.getBounds() : this.getBounds();
const x = event.clientX - app.view.getBoundingClientRect().left;
const y = event.clientY - app.view.getBoundingClientRect().top;
if (bounds.contains(x, y)) {
this.emit('scroll', event);
}
});
}
this.layout();
@@ -13975,13 +13994,40 @@
}
}
/**
*
* @private
* @param {*} event
*/
onScroll(event) {
this.capture(event);
if (this.opts.orientation === 'horizontal') {
this.container.position.x -= event.deltaX;
if (this.container.position.x > 0) {
this.container.position.x = 0;
} else if (this.container.position.x + this.innerWidth < this.opts.width) {
this.container.position.x = this.opts.width - this.innerWidth;
}
} else {
this.container.position.y -= event.deltaY;
if (this.container.position.y > 0) {
this.container.position.y = 0;
} else if (this.container.position.y + this.innerHeight < this.opts.height) {
this.container.position.y = this.opts.height - this.innerHeight;
}
}
}
/**
* Captures an event to inform InteractionMapper about processed events.
*
* @param {event|PIXI.InteractionEvent} event - The PIXI event to capture.
*/
capture(event) {
Events$1.capturedBy(event.data.originalEvent, this);
const originalEvent = event.data && event.data.originalEvent ? event.data.originalEvent : event;
Events$1.capturedBy(originalEvent, this);
}
}