Fixed button group bug.

This commit is contained in:
2019-08-07 14:57:07 +02:00
parent 141d27d4f1
commit caffee4b15
2 changed files with 133 additions and 172 deletions
+28 -14
View File
@@ -292,6 +292,7 @@ export default class ButtonGroup extends PIXI.Container {
this.addChildAt(background, 0)
this.__initWidth = this.container.width
this.__initHeight = this.container.height
}
return this
@@ -462,7 +463,6 @@ export default class ButtonGroup extends PIXI.Container {
onMove(event) {
if (this.__dragging) {
this.capture(event)
if (this.opts.orientation === 'horizontal') {
this.container.position.x = event.data.global.x + this.__delta.x
} else {
@@ -487,20 +487,34 @@ export default class ButtonGroup extends PIXI.Container {
const throwProps = { x: { velocity: 'auto' }, y: { velocity: 'auto' } }
if (this.opts.orientation === 'horizontal') {
const distanceToLeft = this.container.x
const distanceToRight = this.opts.maxWidth - this.container.x - this.__initWidth
if (distanceToLeft > 0 && distanceToLeft > distanceToRight) {
if (this.__initWidth > this.opts.maxWidth) {
// stack!
const distanceToLeft = this.container.x
const distanceToRight = this.opts.maxWidth - this.container.x - this.__initWidth
if (distanceToLeft > 0) {
throwProps.x.end = 0
} else if (distanceToRight > 0) {
throwProps.x.end = this.opts.maxWidth - this.__initWidth
}
} else {
// just magnetize
throwProps.x.end = 0
} else if (distanceToRight > 0 && distanceToRight > distanceToLeft) {
throwProps.x.end = this.opts.maxWidth - this.__initWidth
}
} else {
const distanceToTop = this.container.y
const distanceToBottom = this.opts.maxHeight - this.container.y - this.container.height
if (distanceToTop > 0 && distanceToTop > distanceToBottom) {
if (this.__initHeight > this.opts.maxHeight) {
// stack!
const distanceToTop = this.container.y
const distanceToBottom = this.opts.maxHeight - this.container.y - this.container.height
if (distanceToTop > 0) {
throwProps.y.end = 0
} else if (distanceToBottom > 0) {
throwProps.y.end = this.opts.maxHeight - this.__initHeight
}
} else {
// just magnetize
throwProps.y.end = 0
} else if (distanceToBottom > 0 && distanceToBottom > distanceToTop) {
throwProps.y.end = this.opts.maxHeight - this.container.height
}
}
@@ -564,7 +578,7 @@ export default class ButtonGroup extends PIXI.Container {
}
/**
*
* @private
*/
stack() {
if (this.opts.maxWidth) {
@@ -575,7 +589,7 @@ export default class ButtonGroup extends PIXI.Container {
}
/**
*
* @private
*/
_stackHorizontal() {
const sorted = []
@@ -632,7 +646,7 @@ export default class ButtonGroup extends PIXI.Container {
}
/**
*
* @private
*/
_stackVertical() {
const sorted = []