diff --git a/dist/iwmlib.js b/dist/iwmlib.js index 6d03dc4..3cd4f82 100644 --- a/dist/iwmlib.js +++ b/dist/iwmlib.js @@ -3336,9 +3336,7 @@ } _removeSelfFromScatterContainer() { - /** - Removes self from container when it's closed. - */ + // Removes self from container when it's closed. if (this.container) { this.container.remove(this); } @@ -3937,10 +3935,7 @@ * @memberof DOMScatterContainer */ remove(scatter) { - const element = scatter.element; - if (!this.scatter.has(element)) console.warn(`Try removing element that is not in the scatter.`, element); - - this.scatter.delete(element); + this.scatter.delete(scatter.element); } /** diff --git a/dist/iwmlib.pixi.js b/dist/iwmlib.pixi.js index 526103b..bad2580 100644 --- a/dist/iwmlib.pixi.js +++ b/dist/iwmlib.pixi.js @@ -2963,10 +2963,10 @@ * or a Theme object. * @param {number} [opts.minWidth=44] - Button: The minimum width of one button. * @param {number} [opts.minHeight=44] - Button: The minimum height of one button. - * @param {number} [opts.maxWidth] - The maximum width of the button group. Only used if stacked is true and the orientation is horizontal. - * @param {number} [opts.maxHeight] - The maximum height of the button group. Only used if stacked is true and the orientation is vertical. - * @param {boolean} [opts.stacked=false] - If set to true, the buttons of the button group gets stacked if they are broader or higher than the maximum permitted width or height, depending on orientation. - * @param {PIXI.Application} [opts.app] - The PixiJS Application. Must be set if you want to use the mousewheel to scroll your button group. + * @param {number} [opts.maxWidth] - The maximum width of the button group. If the buttons are wider than the maximum width, the buttons get stacked. Note: The buttons can only be stacked if margin is not zero. + * @param {number} [opts.maxHeight] - The maximum height of the button group. If the buttons are higher than the maximum height, the buttons get stacked. Note: The buttons can only be stacked if margin is not zero. + * @param {number} [opts.stackPadding=10] - The padding for stacked buttons. + * @param {PIXI.Application} [opts.app] - The PixiJS Application. Must be set if you want to use the mousewheel to scroll your button group. Only used when the buttons are stacked (with maxWidth or maxHeight). * @param {number} [opts.padding=Theme.padding] - Button: The inner spacing (distance from icon and/or label) the the border. * @param {number} [opts.margin=Theme.margin] - The outer spacing (distance from one button to the previous/next button). * @param {string} [opts.iconPosition=left] - Button: The position of the icon in relation to the label. Can be left or right. @@ -3017,7 +3017,7 @@ minHeight: 44, maxWidth: null, maxHeight: null, - stacked: false, + stackPadding: 10, app: null, padding: theme.padding, margin: theme.margin, @@ -3080,6 +3080,7 @@ // Buttons //----------------- let position = 0; + let index = 0; for (let it of this.opts.buttons) { delete it.x; @@ -3158,6 +3159,9 @@ }; position += (this.opts.orientation === 'horizontal' ? button.width : button.height) + this.opts.margin; + + button.__initIndex = index; + index++; } if (this.opts.orientation === 'vertical') { @@ -3177,7 +3181,7 @@ // interaction //-------------------- - if (this.opts.stacked) { + if (this.opts.margin > 0 && (this.opts.maxWidth || this.opts.maxHeight)) { this.interactive = true; this.on('pointerdown', this.onStart.bind(this)); this.on('pointermove', this.onMove.bind(this)); @@ -3209,7 +3213,6 @@ this.addChildAt(background, 0); this.__initWidth = this.container.width; - this.__deltaWidth = this.container.width - this.opts.maxWidth; } return this @@ -3229,9 +3232,9 @@ //----------------- this.draw(); - // stacked + // stack //----------------- - if (this.opts.stacked) { + if (this.opts.margin > 0 && (this.opts.maxWidth || this.opts.maxHeight)) { this.stack(); } @@ -3359,9 +3362,7 @@ this.container.position.y = event.data.global.y + this.__delta.y; } - if (this.opts.stacked) { - this.stack(); - } + this.stack(); } } @@ -3436,9 +3437,7 @@ } } - if (this.opts.stacked) { - this.stack(); - } + this.stack(); } /** @@ -3455,36 +3454,107 @@ * */ stack() { + if (this.opts.maxWidth) { + this._stackHorizontal(); + } else if (this.opts.maxHeight) { + this._stackVertical(); + } + } + + /** + * + */ + _stackHorizontal() { + const sorted = []; + + let reverseCounter = this.buttons.length - 1; + this.buttons.forEach((it, index) => { - if (it.__originalPosition.x + this.container.x < 0) { + const leftCorner = it.__originalPosition.x + this.container.x; + const rightCorner = it.__originalPosition.x + it.width; + const paddingLeft = index * this.opts.stackPadding; + const paddingRight = reverseCounter * this.opts.stackPadding; + if (leftCorner < paddingLeft) { // left border - it.x = -this.container.x; - } else if (it.__originalPosition.x + it.width > Math.abs(this.container.x) + this.opts.maxWidth) { + it.x = -this.container.x + paddingLeft; + } else if (rightCorner > -this.container.x + this.opts.maxWidth - paddingRight) { // right border - it.x = Math.abs(this.container.x) + this.opts.maxWidth - it.width; + it.x = -this.container.x + this.opts.maxWidth - it.width - paddingRight; } else { it.x = it.__originalPosition.x; } + + reverseCounter--; + + sorted.push(it); }); - this.buttons.sort((a, b) => { - const delta = Math.abs(this.container.x) + this.opts.maxWidth / 2; - const distanceA = Math.abs(a.x - delta); - const distanceB = Math.abs(b.x - delta); - if (distanceA > distanceB) { - return -1 - } else if (distanceB > distanceA) { - return 1 + const min = Math.min(...sorted.map(it => it.x)); + const max = Math.max(...sorted.map(it => it.x)); + const center = (min + max) / 2; + + // z-index + sorted + .sort((a, b) => { + const distanceA = Math.abs(a.x - center); + const distanceB = Math.abs(b.x - center); + if (distanceA < distanceB) { + return 1 + } else if (distanceA > distanceB) { + return -1 + } else { + return 0 + } + }) + .forEach(it => it.parent.addChild(it)); + } + + /** + * + */ + _stackVertical() { + const sorted = []; + + let reverseCounter = this.buttons.length - 1; + + this.buttons.forEach((it, index) => { + const topCorner = it.__originalPosition.y + this.container.y; + const bottomCorner = it.__originalPosition.y + it.height; + const paddingTop = index * this.opts.stackPadding; + const paddingBottom = reverseCounter * this.opts.stackPadding; + if (topCorner < paddingTop) { + // top border + it.y = -this.container.y + paddingTop; + } else if (bottomCorner > -this.container.y + this.opts.maxHeight - paddingBottom) { + // bottom border + it.y = -this.container.y + this.opts.maxHeight - it.height - paddingBottom; } else { - return 0 + it.y = it.__originalPosition.y; } + + reverseCounter--; + + sorted.push(it); }); - this.buttons.forEach(it => { - const parent = it.parent; - parent.removeChild(it); - parent.addChild(it); - }); + const min = Math.min(...sorted.map(it => it.y)); + const max = Math.max(...sorted.map(it => it.y)); + const center = (min + max) / 2; + + // z-index + sorted + .sort((a, b) => { + const distanceA = Math.abs(a.y - center); + const distanceB = Math.abs(b.y - center); + if (distanceA < distanceB) { + return 1 + } else if (distanceA > distanceB) { + return -1 + } else { + return 0 + } + }) + .forEach(it => it.parent.addChild(it)); } } @@ -6782,9 +6852,7 @@ } _removeSelfFromScatterContainer() { - /** - Removes self from container when it's closed. - */ + // Removes self from container when it's closed. if (this.container) { this.container.remove(this); } diff --git a/doc/out/AbstractPopup.html b/doc/out/AbstractPopup.html index 820f387..2103869 100644 --- a/doc/out/AbstractPopup.html +++ b/doc/out/AbstractPopup.html @@ -263,12 +263,20 @@ Methods +
  • _stackHorizontal
  • + +
  • _stackVertical
  • + +
  • capture
  • +
  • hide
  • layout
  • show
  • +
  • stack
  • +
      @@ -2545,7 +2553,7 @@ export class DeepZoomImage extends PIXI.Container {
      diff --git a/doc/out/pixi_flippable.js.html b/doc/out/pixi_flippable.js.html index 1cbc58e..333e4f9 100644 --- a/doc/out/pixi_flippable.js.html +++ b/doc/out/pixi_flippable.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1533,12 +1541,7 @@ export default class Flippable extends PIXI.projection.Camera3d { // planes //-------------------- - this.setPlanes( - this.opts.focus, - this.opts.near, - this.opts.far, - this.opts.orthographic - ) + this.setPlanes(this.opts.focus, this.opts.near, this.opts.far, this.opts.orthographic) // flipped //-------------------- @@ -1577,9 +1580,7 @@ export default class Flippable extends PIXI.projection.Camera3d { // shadow //-------------------- - const shadow = new PIXI.projection.Sprite3d( - PIXI.Texture.fromImage('../../assets/images/shadow.png') - ) + const shadow = new PIXI.projection.Sprite3d(PIXI.Texture.fromImage('../../assets/images/shadow.png')) shadow.renderable = false shadow.anchor.set(0.5) shadow.scale3d.set(0.98) @@ -1671,21 +1672,11 @@ export default class Flippable extends PIXI.projection.Camera3d { y: this.opts.useBackTransforms ? toCenter.y : fromCenter.y, anchorX: this.opts.useBackTransforms ? toObject.x : fromObject.x, anchorY: this.opts.useBackTransforms ? toObject.y : fromObject.y, - width: this.opts.useBackTransforms - ? toObject.width * 2 - : fromObject.width * 2, - height: this.opts.useBackTransforms - ? toObject.height * 2 - : fromObject.height * 2, - rotation: this.opts.useBackTransforms - ? toObject.rotation - : fromObject.rotation, - skewX: this.opts.useBackTransforms - ? toObject.skew.x - : fromObject.skew.x, - skewY: this.opts.useBackTransforms - ? toObject.skew.y - : fromObject.skew.y + width: this.opts.useBackTransforms ? toObject.width * 2 : fromObject.width * 2, + height: this.opts.useBackTransforms ? toObject.height * 2 : fromObject.height * 2, + rotation: this.opts.useBackTransforms ? toObject.rotation : fromObject.rotation, + skewX: this.opts.useBackTransforms ? toObject.skew.x : fromObject.skew.x, + skewY: this.opts.useBackTransforms ? toObject.skew.y : fromObject.skew.y } // set toObject end values @@ -1771,15 +1762,11 @@ export default class Flippable extends PIXI.projection.Camera3d { // shadow //-------------------- - new TimelineMax() - .to(shadow, half, { alpha: 0.3, ease }) - .to(shadow, half, { alpha: 0.7, ease }) + new TimelineMax().to(shadow, half, { alpha: 0.3, ease }).to(shadow, half, { alpha: 0.7, ease }) // blurfilter //-------------------- - new TimelineMax() - .to(blurFilter, half, { blur: 6, ease }) - .to(blurFilter, half, { blur: 0.2, ease }) + new TimelineMax().to(blurFilter, half, { blur: 6, ease }).to(blurFilter, half, { blur: 0.2, ease }) } /** @@ -1793,8 +1780,7 @@ export default class Flippable extends PIXI.projection.Camera3d { const shadow = this.objects.shadow const inner = this.objects.inner - inner.position3d.z = - -Math.sin(inner.euler.y) * front.texture.baseTexture.width * 2 + inner.position3d.z = -Math.sin(inner.euler.y) * front.texture.baseTexture.width * 2 //this.objects.shadow.euler = this.objects.inner.euler shadow.euler.x = -inner.euler.x @@ -1861,10 +1847,7 @@ export default class Flippable extends PIXI.projection.Camera3d { generateTexture(displayObject) { // renderTexture //-------------------- - const renderTexture = PIXI.RenderTexture.create( - displayObject.width, - displayObject.height - ) + const renderTexture = PIXI.RenderTexture.create(displayObject.width, displayObject.height) // save position const transform = [ @@ -1925,7 +1908,7 @@ export default class Flippable extends PIXI.projection.Camera3d {
      diff --git a/doc/out/pixi_labeledgraphics.js.html b/doc/out/pixi_labeledgraphics.js.html index 8b7cec0..285460d 100644 --- a/doc/out/pixi_labeledgraphics.js.html +++ b/doc/out/pixi_labeledgraphics.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1517,15 +1525,9 @@ export class Hypenate { let first = true let lastPart = '' for (let part of parts) { - let partMetrics = PIXI.TextMetrics.measureText( - part, - pixiStyle - ) + let partMetrics = PIXI.TextMetrics.measureText(part, pixiStyle) if (x + partMetrics.width + space.width > width) { - newWord += - (first || lastPart.endsWith('-') - ? '\n' - : '-\n') + part + newWord += (first || lastPart.endsWith('-') ? '\n' : '-\n') + part x = partMetrics.width } else { newWord += part @@ -1576,12 +1578,7 @@ class TextLabel extends PIXI.Text { * @param {canvas} * @memberof TextLabel */ - constructor( - text, - style = null, - canvas = null, - { minZoom = 0.1, maxZoom = 10 } = {} - ) { + constructor(text, style = null, canvas = null, { minZoom = 0.1, maxZoom = 10 } = {}) { super(text, style, canvas) this.normFontSize = this.style.fontSize this.minZoom = minZoom @@ -1730,21 +1727,11 @@ export class LabeledGraphics extends PIXI.Graphics { const truncatedLines = lines.slice(0, maxLines) const lastLine = truncatedLines[truncatedLines.length - 1] const words = lastLine.split(' ') - const wordMetrics = PIXI.TextMetrics.measureText( - `\u00A0\n...\n${words.join('\n')}`, - pixiStyle - ) - const [ - spaceLength, - dotsLength, - ...wordLengths - ] = wordMetrics.lineWidths + const wordMetrics = PIXI.TextMetrics.measureText(`\u00A0\n...\n${words.join('\n')}`, pixiStyle) + const [spaceLength, dotsLength, ...wordLengths] = wordMetrics.lineWidths const { text: newLastLine } = wordLengths.reduce( (data, wordLength, i) => { - if ( - data.length + wordLength + spaceLength >= - wordWrapWidth - ) { + if (data.length + wordLength + spaceLength >= wordWrapWidth) { return { ...data, length: wordWrapWidth } } return { @@ -1870,7 +1857,7 @@ export class BitmapLabeledGraphics extends LabeledGraphics {
      diff --git a/doc/out/pixi_list.js.html b/doc/out/pixi_list.js.html index 02088ee..2b59843 100644 --- a/doc/out/pixi_list.js.html +++ b/doc/out/pixi_list.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1438,7 +1446,7 @@
      -
      /* globals */
      +            
      /* globals ThrowPropsPlugin, Strong */
       
       /* Imports */
       import Events from '../events.js'
      @@ -1548,9 +1556,7 @@ export default class List extends PIXI.Container {
               if (this.opts.app) {
                   const app = this.opts.app
                   app.view.addEventListener('mousewheel', event => {
      -                const bounds = this.mask
      -                    ? this.mask.getBounds()
      -                    : this.getBounds()
      +                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)) {
      @@ -1607,14 +1613,10 @@ export default class List extends PIXI.Container {
               if (this.opts.orientation === 'vertical') {
                   switch (this.opts.align) {
                       case 'center':
      -                    this.__items.forEach(
      -                        it => (it.x = margin + this.width / 2 - it.width / 2)
      -                    )
      +                    this.__items.forEach(it => (it.x = margin + this.width / 2 - it.width / 2))
                           break
                       case 'right':
      -                    this.__items.forEach(
      -                        it => (it.x = margin + this.width - it.width)
      -                    )
      +                    this.__items.forEach(it => (it.x = margin + this.width - it.width))
                           break
                       default:
                           this.__items.forEach(it => (it.x = margin))
      @@ -1640,14 +1642,10 @@ export default class List extends PIXI.Container {
                           this.__items.forEach(it => (it.y = margin))
                           break
                       case 'bottom':
      -                    this.__items.forEach(
      -                        it => (it.y = margin + this.height - it.height)
      -                    )
      +                    this.__items.forEach(it => (it.y = margin + this.height - it.height))
                           break
                       default:
      -                    this.__items.forEach(
      -                        it => (it.y = margin + this.height / 2 - it.height / 2)
      -                    )
      +                    this.__items.forEach(it => (it.y = margin + this.height / 2 - it.height / 2))
                           break
                   }
       
      @@ -1781,8 +1779,7 @@ export default class List extends PIXI.Container {
                           {
                               throwProps,
                               ease: Strong.easeOut,
      -                        onComplete: () =>
      -                            ThrowPropsPlugin.untrack(this.container.position)
      +                        onComplete: () => ThrowPropsPlugin.untrack(this.container.position)
                           },
                           0.8,
                           0.4
      @@ -1803,20 +1800,14 @@ export default class List extends PIXI.Container {
                   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
      -            ) {
      +            } 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
      -            ) {
      +            } else if (this.container.position.y + this.innerHeight < this.opts.height) {
                       this.container.position.y = this.opts.height - this.innerHeight
                   }
               }
      @@ -1828,10 +1819,7 @@ export default class List extends PIXI.Container {
            * @param {event|PIXI.InteractionEvent} event - The PIXI event to capture.
            */
           capture(event) {
      -        const originalEvent =
      -            event.data && event.data.originalEvent
      -                ? event.data.originalEvent
      -                : event
      +        const originalEvent = event.data && event.data.originalEvent ? event.data.originalEvent : event
               Events.capturedBy(originalEvent, this)
           }
       }
      @@ -1848,7 +1836,7 @@ export default class List extends PIXI.Container {
       
               
      diff --git a/doc/out/pixi_message.js.html b/doc/out/pixi_message.js.html index cd9656f..140564e 100644 --- a/doc/out/pixi_message.js.html +++ b/doc/out/pixi_message.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1531,8 +1539,7 @@ export default class Message extends InteractivePopup { this.x = this.opts.app.size.width / 2 - this.width / 2 break case 'right': - this.x = - this.opts.app.size.width - this.opts.margin - this.width + this.x = this.opts.app.size.width - this.opts.margin - this.width break } @@ -1545,8 +1552,7 @@ export default class Message extends InteractivePopup { this.y = this.opts.app.size.height / 2 - this.height / 2 break case 'bottom': - this.y = - this.opts.app.size.height - this.opts.margin - this.height + this.y = this.opts.app.size.height - this.opts.margin - this.height break } } @@ -1579,7 +1585,7 @@ export default class Message extends InteractivePopup {
      diff --git a/doc/out/pixi_modal.js.html b/doc/out/pixi_modal.js.html index 27ff089..442c323 100644 --- a/doc/out/pixi_modal.js.html +++ b/doc/out/pixi_modal.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1574,10 +1582,7 @@ export default class Modal extends PIXI.Container { // background //----------------- this.background.clear() - this.background.beginFill( - this.opts.backgroundFill, - this.opts.backgroundFillAlpha - ) + this.background.beginFill(this.opts.backgroundFill, this.opts.backgroundFillAlpha) this.background.drawRect(0, 0, width, height) this.background.endFill() @@ -1661,7 +1666,7 @@ export default class Modal extends PIXI.Container {
      diff --git a/doc/out/pixi_popup.js.html b/doc/out/pixi_popup.js.html index 3480ce7..24f4cf7 100644 --- a/doc/out/pixi_popup.js.html +++ b/doc/out/pixi_popup.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1513,10 +1521,7 @@ export class InteractivePopup extends AbstractPopup { // closeButton //----------------- if (this.opts.closeButton) { - let closeButton = PIXI.Sprite.fromImage( - '../../assets/icons/close.png', - true - ) + let closeButton = PIXI.Sprite.fromImage('../../assets/icons/close.png', true) closeButton.width = this.headerStyle.fontSize closeButton.height = closeButton.width closeButton.tint = this.theme.color2 @@ -1540,10 +1545,7 @@ export class InteractivePopup extends AbstractPopup { //----------------- if (this.opts.maxWidth) { const wordWrapWidth = - this.opts.maxWidth - - 2 * this.opts.padding - - this.smallPadding - - this._closeButton.width + this.opts.maxWidth - 2 * this.opts.padding - this.smallPadding - this._closeButton.width if (this._header) { this.headerStyle.wordWrapWidth = wordWrapWidth } else if (this._content) { @@ -1556,18 +1558,10 @@ export class InteractivePopup extends AbstractPopup { //----------------- if (this.opts.button || this.opts.buttonGroup) { if (this.opts.button) { - this._buttons = new Button( - Object.assign( - { textStyle: this.theme.textStyleSmall }, - this.opts.button - ) - ) + this._buttons = new Button(Object.assign({ textStyle: this.theme.textStyleSmall }, this.opts.button)) } else { this._buttons = new ButtonGroup( - Object.assign( - { textStyle: this.theme.textStyleSmall }, - this.opts.buttonGroup - ) + Object.assign({ textStyle: this.theme.textStyleSmall }, this.opts.buttonGroup) ) } this.addChild(this._buttons) @@ -1589,18 +1583,15 @@ export class InteractivePopup extends AbstractPopup { // closeButton //----------------- if (this.opts.closeButton) { - this._closeButton.x = - this.wantedWidth - this.smallPadding - this._closeButton.width + this._closeButton.x = this.wantedWidth - this.smallPadding - this._closeButton.width this._closeButton.y = this.smallPadding } // buttons //----------------- if (this._buttons) { - this._buttons.x = - this.wantedWidth - this.opts.padding - this._buttons.width - this._buttons.y = - this.wantedHeight - this.opts.padding - this._buttons.height + this._buttons.x = this.wantedWidth - this.opts.padding - this._buttons.width + this._buttons.y = this.wantedHeight - this.opts.padding - this._buttons.height } return this @@ -1623,10 +1614,7 @@ export class InteractivePopup extends AbstractPopup { } if (this._buttons) { - size.width = Math.max( - size.width, - this._buttons.x + this._buttons.width - ) + size.width = Math.max(size.width, this._buttons.x + this._buttons.width) size.height += this.innerPadding + this._buttons.height } @@ -1688,7 +1676,7 @@ export default class Popup extends InteractivePopup {
      diff --git a/doc/out/pixi_popupmenu.js.html b/doc/out/pixi_popupmenu.js.html index 459e922..f573773 100644 --- a/doc/out/pixi_popupmenu.js.html +++ b/doc/out/pixi_popupmenu.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1514,10 +1522,7 @@ export default class PopupMenu extends Popup { let object = null if (item.label) { - object = new PIXI.Text( - item.label, - item.textStyle || this.opts.textStyle - ) + object = new PIXI.Text(item.label, item.textStyle || this.opts.textStyle) } else { object = item.content } @@ -1574,7 +1579,7 @@ export default class PopupMenu extends Popup {
      diff --git a/doc/out/pixi_progress.js.html b/doc/out/pixi_progress.js.html index a34a025..9498c91 100644 --- a/doc/out/pixi_progress.js.html +++ b/doc/out/pixi_progress.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1594,10 +1602,7 @@ export default class Progress extends PIXI.Container { //----------------- if (this.opts.background) { this.background.clear() - this.background.beginFill( - this.opts.backgroundFill, - this.opts.backgroundFillAlpha - ) + this.background.beginFill(this.opts.backgroundFill, this.opts.backgroundFillAlpha) this.background.drawRect(0, 0, width, height) this.background.endFill() } @@ -1641,20 +1646,10 @@ export default class Progress extends PIXI.Container { const wantedWidth = this.opts.width || width - 2 * this.opts.margin const wantedHeight = this.opts.height - this.bar.lineStyle( - this.opts.strokeWidth, - this.opts.stroke, - this.opts.strokeAlpha - ) + this.bar.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha) this.bar.beginFill(this.opts.fill, this.opts.fillAlpha) if (this.radius > 1) { - this.bar.drawRoundedRect( - 0, - 0, - wantedWidth, - wantedHeight, - this.radius - ) + this.bar.drawRoundedRect(0, 0, wantedWidth, wantedHeight, this.radius) } else { this.bar.drawRect(0, 0, wantedWidth, wantedHeight) } @@ -1678,24 +1673,11 @@ export default class Progress extends PIXI.Container { const barActiveWidth = (wantedWidth * this._progress) / 100 - this.barActive.lineStyle( - this.opts.strokeActiveWidth, - this.opts.strokeActive, - this.opts.strokeActiveAlpha - ) - this.barActive.beginFill( - this.opts.fillActive, - this.opts.fillActiveAlpha - ) + this.barActive.lineStyle(this.opts.strokeActiveWidth, this.opts.strokeActive, this.opts.strokeActiveAlpha) + this.barActive.beginFill(this.opts.fillActive, this.opts.fillActiveAlpha) if (barActiveWidth > 0) { if (this.radius > 1) { - this.barActive.drawRoundedRect( - 0, - 0, - barActiveWidth, - wantedHeight, - this.radius - ) + this.barActive.drawRoundedRect(0, 0, barActiveWidth, wantedHeight, this.radius) } else { this.barActive.drawRect(0, 0, barActiveWidth, wantedHeight) } @@ -1779,7 +1761,7 @@ export default class Progress extends PIXI.Container {
      diff --git a/doc/out/pixi_scrollview.js.html b/doc/out/pixi_scrollview.js.html index 9d50649..50f249b 100644 --- a/doc/out/pixi_scrollview.js.html +++ b/doc/out/pixi_scrollview.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1512,7 +1520,7 @@ export default class Scrollview extends Scrollbox {
      diff --git a/doc/out/pixi_slider.js.html b/doc/out/pixi_slider.js.html index 5f250f8..19add97 100644 --- a/doc/out/pixi_slider.js.html +++ b/doc/out/pixi_slider.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1616,12 +1624,8 @@ export default class Slider extends PIXI.Container { this.on('pointermove', e => { if (this.control.dragging) { - const moveX = this.control.event.data.getLocalPosition( - this.control.parent - ).x - this._value = this.pixelToValue( - moveX - this.control.delta - this.opts.controlRadius - ) + const moveX = this.control.event.data.getLocalPosition(this.control.parent).x + this._value = this.pixelToValue(moveX - this.control.delta - this.opts.controlRadius) let x = this.valueToPixel(this._value) + this.opts.controlRadius this.control.x = x @@ -1633,16 +1637,8 @@ export default class Slider extends PIXI.Container { if (container instanceof Element) { container.addEventListener('pointerup', e => this.onEnd(e), false) - container.addEventListener( - 'pointercancel', - e => this.onEnd(e), - false - ) - container.addEventListener( - 'pointerleave', - e => this.onEnd(e), - false - ) + container.addEventListener('pointercancel', e => this.onEnd(e), false) + container.addEventListener('pointerleave', e => this.onEnd(e), false) container.addEventListener('pointerout', e => this.onEnd(e), false) container.addEventListener('mouseup', e => this.onEnd(e), false) container.addEventListener('mousecancel', e => this.onEnd(e), false) @@ -1703,9 +1699,7 @@ export default class Slider extends PIXI.Container { if (this.sliderObj.pointerdowned) { this.sliderObj.pointerdowned = false const position = e.data.getLocalPosition(this.control.parent) - this.value = this.pixelToValue( - position.x - this.opts.controlRadius - ) + this.value = this.pixelToValue(position.x - this.opts.controlRadius) TweenLite.to(this.control, this.theme.fast, { alpha: 0.83 }) } }) @@ -1765,11 +1759,7 @@ export default class Slider extends PIXI.Container { this.sliderObj.clear() this.sliderObj.beginFill(0xffffff, 0) this.sliderObj.drawRect(0, 0, x + w + cr, cr * 2) - this.sliderObj.lineStyle( - this.opts.strokeWidth, - this.opts.stroke, - this.opts.strokeAlpha - ) + this.sliderObj.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha) this.sliderObj.beginFill(this.opts.fill, this.opts.fillAlpha) this.sliderObj.moveTo(x, y) this.sliderObj.lineTo(x + w, y) @@ -1783,20 +1773,10 @@ export default class Slider extends PIXI.Container { // Draw control this.control.clear() - this.control.lineStyle( - this.opts.controlStrokeWidth, - this.opts.controlStroke, - this.opts.controlStrokeAlpha - ) - this.control.beginFill( - this.opts.controlFill, - this.opts.controlFillAlpha - ) + this.control.lineStyle(this.opts.controlStrokeWidth, this.opts.controlStroke, this.opts.controlStrokeAlpha) + this.control.beginFill(this.opts.controlFill, this.opts.controlFillAlpha) this.control.drawCircle(0, 0, cr - 1) - this.control.beginFill( - this.opts.controlStroke, - this.opts.controlStrokeAlpha - ) + this.control.beginFill(this.opts.controlStroke, this.opts.controlStrokeAlpha) this.control.drawCircle(0, 0, cr / 6) this.control.endFill() @@ -1834,10 +1814,7 @@ export default class Slider extends PIXI.Container { } else if (value > this.opts.max) { value = this.opts.max } - return ( - (this.opts.width * (value - this.opts.min)) / - (this.opts.max - this.opts.min) - ) + return (this.opts.width * (value - this.opts.min)) / (this.opts.max - this.opts.min) } /** @@ -1853,10 +1830,7 @@ export default class Slider extends PIXI.Container { } else if (pixel > this.opts.width) { pixel = this.opts.width } - return ( - this.opts.min + - ((this.opts.max - this.opts.min) * pixel) / this.opts.width - ) + return this.opts.min + ((this.opts.max - this.opts.min) * pixel) / this.opts.width } /** @@ -1951,7 +1925,7 @@ export default class Slider extends PIXI.Container {
      diff --git a/doc/out/pixi_switch.js.html b/doc/out/pixi_switch.js.html index 1cebd3a..f933c5c 100644 --- a/doc/out/pixi_switch.js.html +++ b/doc/out/pixi_switch.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1592,10 +1600,8 @@ export default class Switch extends PIXI.Container { opts ) - this.opts.controlRadius = - this.opts.controlRadius || this.opts.height / 2 - this.opts.controlRadiusActive = - this.opts.controlRadiusActive || this.opts.controlRadius + this.opts.controlRadius = this.opts.controlRadius || this.opts.height / 2 + this.opts.controlRadiusActive = this.opts.controlRadiusActive || this.opts.controlRadius // Validation //----------------- @@ -1757,32 +1763,15 @@ export default class Switch extends PIXI.Container { draw() { this.switchObj.clear() if (this.active) { - this.switchObj.lineStyle( - this.opts.strokeActiveWidth, - this.opts.strokeActive, - this.opts.strokeActiveAlpha - ) - this.switchObj.beginFill( - this.opts.fillActive, - this.opts.fillActiveAlpha - ) + this.switchObj.lineStyle(this.opts.strokeActiveWidth, this.opts.strokeActive, this.opts.strokeActiveAlpha) + this.switchObj.beginFill(this.opts.fillActive, this.opts.fillActiveAlpha) } else { - this.switchObj.lineStyle( - this.opts.strokeWidth, - this.opts.stroke, - this.opts.strokeAlpha - ) + this.switchObj.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha) this.switchObj.beginFill(this.opts.fill, this.opts.fillAlpha) } this.switchObj.moveTo(this.radius, 0) this.switchObj.lineTo(this.opts.width - this.radius, 0) - this.switchObj.arcTo( - this.opts.width, - 0, - this.opts.width, - this.radius, - this.radius - ) + this.switchObj.arcTo(this.opts.width, 0, this.opts.width, this.radius, this.radius) this.switchObj.lineTo(this.opts.width, this.radius + 1) // BUGFIX: If not specified, there is a small area without a stroke. this.switchObj.arcTo( this.opts.width, @@ -1804,21 +1793,11 @@ export default class Switch extends PIXI.Container { this.opts.controlStrokeActive, this.opts.controlStrokeActiveAlpha ) - this.control.beginFill( - this.opts.controlFillActive, - this.opts.controlFillActiveAlpha - ) + this.control.beginFill(this.opts.controlFillActive, this.opts.controlFillActiveAlpha) this.control.drawCircle(0, 0, this.opts.controlRadiusActive - 1) } else { - this.control.lineStyle( - this.opts.controlStrokeWidth, - this.opts.controlStroke, - this.opts.controlStrokeAlpha - ) - this.control.beginFill( - this.opts.controlFill, - this.opts.controlFillAlpha - ) + this.control.lineStyle(this.opts.controlStrokeWidth, this.opts.controlStroke, this.opts.controlStrokeAlpha) + this.control.beginFill(this.opts.controlFill, this.opts.controlFillAlpha) this.control.drawCircle(0, 0, this.opts.controlRadius - 1) } this.control.endFill() @@ -1834,24 +1813,11 @@ export default class Switch extends PIXI.Container { */ drawAnimated() { this.switchObj.clear() - this.switchObj.lineStyle( - this.tempAnimated.strokeWidth, - this.tempAnimated.stroke, - this.tempAnimated.strokeAlpha - ) - this.switchObj.beginFill( - this.tempAnimated.fill, - this.tempAnimated.fillAlpha - ) + this.switchObj.lineStyle(this.tempAnimated.strokeWidth, this.tempAnimated.stroke, this.tempAnimated.strokeAlpha) + this.switchObj.beginFill(this.tempAnimated.fill, this.tempAnimated.fillAlpha) this.switchObj.moveTo(this.radius, 0) this.switchObj.lineTo(this.opts.width - this.radius, 0) - this.switchObj.arcTo( - this.opts.width, - 0, - this.opts.width, - this.radius, - this.radius - ) + this.switchObj.arcTo(this.opts.width, 0, this.opts.width, this.radius, this.radius) this.switchObj.lineTo(this.opts.width, this.radius + 1) // BUGFIX: If not specified, there is a small area without a stroke. this.switchObj.arcTo( this.opts.width, @@ -1871,10 +1837,7 @@ export default class Switch extends PIXI.Container { this.tempAnimated.controlStroke, this.tempAnimated.controlStrokeAlpha ) - this.control.beginFill( - this.tempAnimated.controlFill, - this.tempAnimated.controlFillAlpha - ) + this.control.beginFill(this.tempAnimated.controlFill, this.tempAnimated.controlFillAlpha) this.control.drawCircle(0, 0, this.tempAnimated.controlRadius - 1) this.control.endFill() @@ -2016,7 +1979,7 @@ export default class Switch extends PIXI.Container {
      diff --git a/doc/out/pixi_theme.js.html b/doc/out/pixi_theme.js.html index 3cb870e..657d49c 100644 --- a/doc/out/pixi_theme.js.html +++ b/doc/out/pixi_theme.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1520,8 +1528,7 @@ export default class Theme { * is used for large actived text. */ constructor(opts = {}) { - const colorPrimary = - opts.primaryColor != null ? opts.primaryColor : 0x5ec7f8 // blue + const colorPrimary = opts.primaryColor != null ? opts.primaryColor : 0x5ec7f8 // blue const color1 = opts.color1 != null ? opts.color1 : 0x282828 // black const color2 = opts.color2 != null ? opts.color2 : 0xf6f6f6 // white @@ -1713,7 +1720,7 @@ export class ThemeRed extends Theme {
      diff --git a/doc/out/pixi_tooltip.js.html b/doc/out/pixi_tooltip.js.html index 2ab5d2e..daf1b70 100644 --- a/doc/out/pixi_tooltip.js.html +++ b/doc/out/pixi_tooltip.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1605,7 +1613,7 @@ export default class Tooltip extends AbstractPopup {
      diff --git a/doc/out/pixi_volatile.js.html b/doc/out/pixi_volatile.js.html index f5914db..5242a27 100644 --- a/doc/out/pixi_volatile.js.html +++ b/doc/out/pixi_volatile.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1609,7 +1617,7 @@ export default class Volatile {
      diff --git a/doc/out/uitest.js.html b/doc/out/uitest.js.html index 96bed1c..3bacbba 100644 --- a/doc/out/uitest.js.html +++ b/doc/out/uitest.js.html @@ -263,12 +263,20 @@ Methods +
    • _stackHorizontal
    • + +
    • _stackVertical
    • + +
    • capture
    • +
    • hide
    • layout
    • show
    • +
    • stack
    • +
      @@ -1634,9 +1642,7 @@ export default class UITest { if (opts.eventType) { opts.eventTypes = opts.eventType } - opts.eventTypes = Array.isArray(opts.eventTypes) - ? opts.eventTypes - : [opts.eventTypes] + opts.eventTypes = Array.isArray(opts.eventTypes) ? opts.eventTypes : [opts.eventTypes] // timeline //-------------------- @@ -1674,14 +1680,8 @@ export default class UITest { if (opts.eventTypes[0]) { // create and dispatch event //-------------------- - const eventStart = Event.create( - elem, - coords, - opts.eventTypes[0], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', eventStart) + const eventStart = Event.create(elem, coords, opts.eventTypes[0], eventOpts) + if (this.opts.debug) console.log('dispatch event', eventStart) elem.dispatchEvent(eventStart) // onStart @@ -1693,14 +1693,8 @@ export default class UITest { // create and dispatch event //-------------------- - const eventComplete = Event.create( - elem, - coords, - opts.eventTypes[1], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', eventComplete) + const eventComplete = Event.create(elem, coords, opts.eventTypes[1], eventOpts) + if (this.opts.debug) console.log('dispatch event', eventComplete) elem.dispatchEvent(eventComplete) // onComplete @@ -1795,14 +1789,8 @@ export default class UITest { onStart: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[0], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[0], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onStart @@ -1814,14 +1802,8 @@ export default class UITest { onUpdate: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[1], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[1], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onUpdate @@ -1833,14 +1815,8 @@ export default class UITest { onComplete: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[2], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[2], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onComplete @@ -1991,66 +1967,39 @@ export default class UITest { onStart: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[0], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[0], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onStart //-------------------- - if ( - opts.onStart && - (opts.doubleCallbacks || key === 0) - ) { + if (opts.onStart && (opts.doubleCallbacks || key === 0)) { opts.onStart.call(this, event) } }, onUpdate: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[1], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[1], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onUpdate //-------------------- - if ( - opts.onUpdate && - (opts.doubleCallbacks || key === 0) - ) { + if (opts.onUpdate && (opts.doubleCallbacks || key === 0)) { opts.onUpdate.call(this, event) } }, onComplete: () => { // create and dispatch event //-------------------- - const event = Event.create( - elem, - from, - opts.eventTypes[2], - eventOpts - ) - if (this.opts.debug) - console.log('dispatch event', event) + const event = Event.create(elem, from, opts.eventTypes[2], eventOpts) + if (this.opts.debug) console.log('dispatch event', event) elem.dispatchEvent(event) // onComplete //-------------------- - if ( - opts.onComplete && - (opts.doubleCallbacks || key === 0) - ) { + if (opts.onComplete && (opts.doubleCallbacks || key === 0)) { opts.onComplete.call(this, event) } } @@ -2168,9 +2117,7 @@ export default class UITest { 'No execution time was specified for this action, and a default interval was not set in the class constructor!' ) } - timelinePosition = - Math.max(...this._timelinePositions) + - (this.opts.defaultInterval || 1) + timelinePosition = Math.max(...this._timelinePositions) + (this.opts.defaultInterval || 1) } if (opts === null) { @@ -2245,12 +2192,8 @@ class Util { * @return {HTMLElement|string} element - The HTML element on which the event is to be executed, e.g. button, document, h2, canvas, etc. or an selector string. If a selector has been specified, it is evaluated immediately before the event is called using the querySelector method. */ static extractElement(context, element) { - const cont = Util.isFrame(context) - ? context.contentDocument - : context.document - const elem = Util.isString(element) - ? cont.querySelector(element) - : element + const cont = Util.isFrame(context) ? context.contentDocument : context.document + const elem = Util.isString(element) ? cont.querySelector(element) : element return elem } @@ -2306,9 +2249,7 @@ class Util { type: 'thru' } } else { - opts.bezier.values = opts.bezier.values.map(it => - Util.extractPosition(it) - ) + opts.bezier.values = opts.bezier.values.map(it => Util.extractPosition(it)) bezier = opts.bezier } @@ -2444,16 +2385,9 @@ class Event { * @param {string} type - The type of the event, see https://developer.mozilla.org/de/docs/Web/Events * @param {object} opts - An options object. Every paramter of the event object can be overridden, see e.g. https://developer.mozilla.org/de/docs/Web/API/MouseEvent for all the properties. */ - static create( - target, - position = { x: 0, y: 0 }, - type = 'pointerup', - opts = {} - ) { + static create(target, position = { x: 0, y: 0 }, type = 'pointerup', opts = {}) { const rect = - typeof target.getBoundingClientRect === 'function' - ? target.getBoundingClientRect() - : { x: 0, y: 0 } + typeof target.getBoundingClientRect === 'function' ? target.getBoundingClientRect() : { x: 0, y: 0 } // EventInit const eventOpts = { @@ -2512,25 +2446,12 @@ class Event { if (type.startsWith('pointer')) { return new PointerEvent( type, - Object.assign( - {}, - eventOpts, - uiEventOpts, - mouseEventOpts, - pointerEventOpts, - opts - ) + Object.assign({}, eventOpts, uiEventOpts, mouseEventOpts, pointerEventOpts, opts) ) } else if (type.startsWith('touch')) { - return new TouchEvent( - type, - Object.assign({}, eventOpts, uiEventOpts, touchEventOpts, opts) - ) + return new TouchEvent(type, Object.assign({}, eventOpts, uiEventOpts, touchEventOpts, opts)) } else { - return new MouseEvent( - type, - Object.assign({}, eventOpts, uiEventOpts, mouseEventOpts, opts) - ) + return new MouseEvent(type, Object.assign({}, eventOpts, uiEventOpts, mouseEventOpts, opts)) } } } @@ -2547,7 +2468,7 @@ class Event { diff --git a/lib/pixi/buttongroup.html b/lib/pixi/buttongroup.html index 2bce155..fe3fe5c 100644 --- a/lib/pixi/buttongroup.html +++ b/lib/pixi/buttongroup.html @@ -245,7 +245,7 @@ const buttonGroup14 = new ButtonGroup({ {label: 'Stacked button 7', action: event => console.log('clicked 7')}, {label: 'Stacked button 8', action: event => console.log('clicked 8')} ], - stacked: true, + stackPadding: 6, maxWidth: 620, app }) @@ -263,18 +263,30 @@ const buttonGroup15 = new ButtonGroup({ {icon: 'battery_charging_full', type: 'checkbox', iconColorActive: 0x9c71b7} ], orientation: 'vertical', - margin: 0, - stacked: true, + margin: 1, maxHeight: 200, app }) +const buttons16 = [] +for (let i = 1; i < 51; i++) { + buttons16.push({label: `Button ${i}`, stroke: Math.floor(Math.random() * 16777215), strokeWidth: 3, radius: 16}) +} +const buttonGroup16 = new ButtonGroup({ + x: 90, + y: 1040, + buttons: buttons16, + stackPadding: 3, + maxWidth: 700, + app +}) + app.scene.addChild(buttonGroup1, buttonGroup2, buttonGroup3) app.scene.addChild(buttonGroup4) app.scene.addChild(buttonGroup5, buttonGroup6) app.scene.addChild(buttonGroup7, buttonGroup8) app.scene.addChild(buttonGroup9, buttonGroup10, buttonGroup11, buttonGroup12, buttonGroup13) -app.scene.addChild(buttonGroup14, buttonGroup15) +app.scene.addChild(buttonGroup14, buttonGroup15, buttonGroup16) diff --git a/lib/pixi/buttongroup.js b/lib/pixi/buttongroup.js index c2419bc..87bc6de 100644 --- a/lib/pixi/buttongroup.js +++ b/lib/pixi/buttongroup.js @@ -42,10 +42,10 @@ export default class ButtonGroup extends PIXI.Container { * or a Theme object. * @param {number} [opts.minWidth=44] - Button: The minimum width of one button. * @param {number} [opts.minHeight=44] - Button: The minimum height of one button. - * @param {number} [opts.maxWidth] - The maximum width of the button group. Only used if stacked is true and the orientation is horizontal. - * @param {number} [opts.maxHeight] - The maximum height of the button group. Only used if stacked is true and the orientation is vertical. - * @param {boolean} [opts.stacked=false] - If set to true, the buttons of the button group gets stacked if they are broader or higher than the maximum permitted width or height, depending on orientation. - * @param {PIXI.Application} [opts.app] - The PixiJS Application. Must be set if you want to use the mousewheel to scroll your button group. + * @param {number} [opts.maxWidth] - The maximum width of the button group. If the buttons are wider than the maximum width, the buttons get stacked. Note: The buttons can only be stacked if margin is not zero. + * @param {number} [opts.maxHeight] - The maximum height of the button group. If the buttons are higher than the maximum height, the buttons get stacked. Note: The buttons can only be stacked if margin is not zero. + * @param {number} [opts.stackPadding=10] - The padding for stacked buttons. + * @param {PIXI.Application} [opts.app] - The PixiJS Application. Must be set if you want to use the mousewheel to scroll your button group. Only used when the buttons are stacked (with maxWidth or maxHeight). * @param {number} [opts.padding=Theme.padding] - Button: The inner spacing (distance from icon and/or label) the the border. * @param {number} [opts.margin=Theme.margin] - The outer spacing (distance from one button to the previous/next button). * @param {string} [opts.iconPosition=left] - Button: The position of the icon in relation to the label. Can be left or right. @@ -96,7 +96,7 @@ export default class ButtonGroup extends PIXI.Container { minHeight: 44, maxWidth: null, maxHeight: null, - stacked: false, + stackPadding: 10, app: null, padding: theme.padding, margin: theme.margin, @@ -159,6 +159,7 @@ export default class ButtonGroup extends PIXI.Container { // Buttons //----------------- let position = 0 + let index = 0 for (let it of this.opts.buttons) { delete it.x @@ -237,6 +238,9 @@ export default class ButtonGroup extends PIXI.Container { } position += (this.opts.orientation === 'horizontal' ? button.width : button.height) + this.opts.margin + + button.__initIndex = index + index++ } if (this.opts.orientation === 'vertical') { @@ -256,7 +260,7 @@ export default class ButtonGroup extends PIXI.Container { // interaction //-------------------- - if (this.opts.stacked) { + if (this.opts.margin > 0 && (this.opts.maxWidth || this.opts.maxHeight)) { this.interactive = true this.on('pointerdown', this.onStart.bind(this)) this.on('pointermove', this.onMove.bind(this)) @@ -288,7 +292,6 @@ export default class ButtonGroup extends PIXI.Container { this.addChildAt(background, 0) this.__initWidth = this.container.width - this.__deltaWidth = this.container.width - this.opts.maxWidth } return this @@ -308,9 +311,9 @@ export default class ButtonGroup extends PIXI.Container { //----------------- this.draw() - // stacked + // stack //----------------- - if (this.opts.stacked) { + if (this.opts.margin > 0 && (this.opts.maxWidth || this.opts.maxHeight)) { this.stack() } @@ -438,9 +441,7 @@ export default class ButtonGroup extends PIXI.Container { this.container.position.y = event.data.global.y + this.__delta.y } - if (this.opts.stacked) { - this.stack() - } + this.stack() } } @@ -515,9 +516,7 @@ export default class ButtonGroup extends PIXI.Container { } } - if (this.opts.stacked) { - this.stack() - } + this.stack() } /** @@ -534,35 +533,106 @@ export default class ButtonGroup extends PIXI.Container { * */ stack() { + if (this.opts.maxWidth) { + this._stackHorizontal() + } else if (this.opts.maxHeight) { + this._stackVertical() + } + } + + /** + * + */ + _stackHorizontal() { + const sorted = [] + + let reverseCounter = this.buttons.length - 1 + this.buttons.forEach((it, index) => { - if (it.__originalPosition.x + this.container.x < 0) { + const leftCorner = it.__originalPosition.x + this.container.x + const rightCorner = it.__originalPosition.x + it.width + const paddingLeft = index * this.opts.stackPadding + const paddingRight = reverseCounter * this.opts.stackPadding + if (leftCorner < paddingLeft) { // left border - it.x = -this.container.x - } else if (it.__originalPosition.x + it.width > Math.abs(this.container.x) + this.opts.maxWidth) { + it.x = -this.container.x + paddingLeft + } else if (rightCorner > -this.container.x + this.opts.maxWidth - paddingRight) { // right border - it.x = Math.abs(this.container.x) + this.opts.maxWidth - it.width + it.x = -this.container.x + this.opts.maxWidth - it.width - paddingRight } else { it.x = it.__originalPosition.x } + + reverseCounter-- + + sorted.push(it) }) - this.buttons.sort((a, b) => { - const delta = Math.abs(this.container.x) + this.opts.maxWidth / 2 - const distanceA = Math.abs(a.x - delta) - const distanceB = Math.abs(b.x - delta) - if (distanceA > distanceB) { - return -1 - } else if (distanceB > distanceA) { - return 1 + const min = Math.min(...sorted.map(it => it.x)) + const max = Math.max(...sorted.map(it => it.x)) + const center = (min + max) / 2 + + // z-index + sorted + .sort((a, b) => { + const distanceA = Math.abs(a.x - center) + const distanceB = Math.abs(b.x - center) + if (distanceA < distanceB) { + return 1 + } else if (distanceA > distanceB) { + return -1 + } else { + return 0 + } + }) + .forEach(it => it.parent.addChild(it)) + } + + /** + * + */ + _stackVertical() { + const sorted = [] + + let reverseCounter = this.buttons.length - 1 + + this.buttons.forEach((it, index) => { + const topCorner = it.__originalPosition.y + this.container.y + const bottomCorner = it.__originalPosition.y + it.height + const paddingTop = index * this.opts.stackPadding + const paddingBottom = reverseCounter * this.opts.stackPadding + if (topCorner < paddingTop) { + // top border + it.y = -this.container.y + paddingTop + } else if (bottomCorner > -this.container.y + this.opts.maxHeight - paddingBottom) { + // bottom border + it.y = -this.container.y + this.opts.maxHeight - it.height - paddingBottom } else { - return 0 + it.y = it.__originalPosition.y } + + reverseCounter-- + + sorted.push(it) }) - this.buttons.forEach(it => { - const parent = it.parent - parent.removeChild(it) - parent.addChild(it) - }) + const min = Math.min(...sorted.map(it => it.y)) + const max = Math.max(...sorted.map(it => it.y)) + const center = (min + max) / 2 + + // z-index + sorted + .sort((a, b) => { + const distanceA = Math.abs(a.y - center) + const distanceB = Math.abs(b.y - center) + if (distanceA < distanceB) { + return 1 + } else if (distanceA > distanceB) { + return -1 + } else { + return 0 + } + }) + .forEach(it => it.parent.addChild(it)) } }