Prettified all files.

This commit is contained in:
2019-07-18 12:26:39 +02:00
parent 7744b92771
commit 2d400a18ec
125 changed files with 11184 additions and 8154 deletions
+100 -76
View File
@@ -1443,7 +1443,7 @@ import Button from './button.js'
/**
* Class that represents a PixiJS ButtonGroup.
*
*
* @example
* // Create the button group
* const buttonGroup = new ButtonGroup({
@@ -1464,10 +1464,9 @@ import Button from './button.js'
* @see {@link https://www.iwm-tuebingen.de/iwmbrowser/lib/pixi/buttongroup.html|DocTest}
*/
export default class ButtonGroup extends PIXI.Graphics {
/**
* Creates an instance of a ButtonGroup.
*
*
* @constructor
* @param {object} [opts] - An options object to specify to style and behaviour of the button group.
* @param {number} [opts.id=auto generated] - The id of the button group.
@@ -1514,50 +1513,53 @@ export default class ButtonGroup extends PIXI.Graphics {
* @param {boolean} [opts.visible=true] - Is the button group initially visible (property visible)?
*/
constructor(opts = {}) {
super()
const theme = Theme.fromString(opts.theme)
this.theme = theme
this.opts = Object.assign({}, {
id: PIXI.utils.uid(),
x: 0,
y: 0,
buttons: [],
minWidth: 44,
minHeight: 44,
padding: theme.padding,
margin: theme.margin,
iconPosition: 'left', // left, right
iconColor: theme.iconColor,
iconColorActive: theme.iconColorActive,
fill: theme.fill,
fillAlpha: theme.fillAlpha,
fillActive: theme.fillActive,
fillActiveAlpha: theme.fillActiveAlpha,
stroke: theme.stroke,
strokeWidth: theme.strokeWidth,
strokeAlpha: theme.strokeAlpha,
strokeActive: theme.strokeActive,
strokeActiveWidth: theme.strokeActiveWidth,
strokeActiveAlpha: theme.strokeActiveAlpha,
textStyle: theme.textStyle,
textStyleActive: theme.textStyleActive,
style: 'default',
radius: theme.radius,
disabled: null,
type: 'default', // default, checkbox, radio
orientation: 'horizontal',
align: 'center', // left, center, right
verticalAlign: 'middle', // top, middle, bottom
visible: true
}, opts)
this.opts = Object.assign(
{},
{
id: PIXI.utils.uid(),
x: 0,
y: 0,
buttons: [],
minWidth: 44,
minHeight: 44,
padding: theme.padding,
margin: theme.margin,
iconPosition: 'left', // left, right
iconColor: theme.iconColor,
iconColorActive: theme.iconColorActive,
fill: theme.fill,
fillAlpha: theme.fillAlpha,
fillActive: theme.fillActive,
fillActiveAlpha: theme.fillActiveAlpha,
stroke: theme.stroke,
strokeWidth: theme.strokeWidth,
strokeAlpha: theme.strokeAlpha,
strokeActive: theme.strokeActive,
strokeActiveWidth: theme.strokeActiveWidth,
strokeActiveAlpha: theme.strokeActiveAlpha,
textStyle: theme.textStyle,
textStyleActive: theme.textStyleActive,
style: 'default',
radius: theme.radius,
disabled: null,
type: 'default', // default, checkbox, radio
orientation: 'horizontal',
align: 'center', // left, center, right
verticalAlign: 'middle', // top, middle, bottom
visible: true
},
opts
)
this.buttons = []
this._disabled = null
this.visible = this.opts.visible
// setup
@@ -1568,21 +1570,19 @@ export default class ButtonGroup extends PIXI.Graphics {
//-----------------
this.layout()
}
/**
* Creates children and instantiates everything.
*
*
* @private
* @return {ButtonGroup} A reference to the button group for chaining.
*/
setup() {
// Buttons
//-----------------
let position = 0
for (let it of this.opts.buttons) {
delete it.x
delete it.y
@@ -1604,11 +1604,19 @@ export default class ButtonGroup extends PIXI.Graphics {
it.fillActive = it.fillActive || this.opts.fillActive
it.fillActiveAlpha = it.fillActiveAlpha || this.opts.fillActiveAlpha
it.stroke = it.stroke || this.opts.stroke
it.strokeWidth = it.strokeWidth != null ? it.strokeWidth : this.opts.strokeWidth
it.strokeAlpha = it.strokeAlpha != null ? it.strokeAlpha : this.opts.strokeAlpha
it.strokeWidth =
it.strokeWidth != null ? it.strokeWidth : this.opts.strokeWidth
it.strokeAlpha =
it.strokeAlpha != null ? it.strokeAlpha : this.opts.strokeAlpha
it.strokeActive = it.strokeActive || this.opts.strokeActive
it.strokeActiveWidth = it.strokeActiveWidth != null ? it.strokeActiveWidth : this.opts.strokeActiveWidth
it.strokeActiveAlpha = it.strokeActiveAlpha != null ? it.strokeActiveAlpha : this.opts.strokeActiveAlpha
it.strokeActiveWidth =
it.strokeActiveWidth != null
? it.strokeActiveWidth
: this.opts.strokeActiveWidth
it.strokeActiveAlpha =
it.strokeActiveAlpha != null
? it.strokeActiveAlpha
: this.opts.strokeActiveAlpha
it.textStyle = it.textStyle || this.opts.textStyle
it.textStyleActive = it.textStyleActive || this.opts.textStyleActive
it.style = it.style || this.opts.style
@@ -1627,7 +1635,10 @@ export default class ButtonGroup extends PIXI.Graphics {
it.align = it.align || this.opts.align
it.verticalAlign = it.verticalAlign || this.opts.verticalAlign
it.afterAction = (event, button) => {
if (this.opts.type === 'radio' && button.opts.type === 'default') {
if (
this.opts.type === 'radio' &&
button.opts.type === 'default'
) {
this.buttons.forEach(it => {
if (it.opts.type === 'default') {
it.active = false
@@ -1642,18 +1653,25 @@ export default class ButtonGroup extends PIXI.Graphics {
if (it.tooltip) {
if (typeof it.tooltip === 'string') {
it.tooltip = {content: it.tooltip, container: this}
it.tooltip = { content: it.tooltip, container: this }
} else {
it.tooltip = Object.assign({}, {container: this}, it.tooltip)
it.tooltip = Object.assign(
{},
{ container: this },
it.tooltip
)
}
}
let button = new Button(it)
this.addChild(button)
this.buttons.push(button)
position += (this.opts.orientation === 'horizontal' ? button.width : button.height) + this.opts.margin
position +=
(this.opts.orientation === 'horizontal'
? button.width
: button.height) + this.opts.margin
}
if (this.opts.orientation === 'vertical') {
@@ -1673,14 +1691,13 @@ export default class ButtonGroup extends PIXI.Graphics {
return this
}
/**
* Should be called to refresh the layout of the button group. Can be used after resizing.
*
*
* @return {ButtonGroup} A reference to the button group for chaining.
*/
layout() {
// set position
//-----------------
this.position.set(this.opts.x, this.opts.y)
@@ -1691,26 +1708,38 @@ export default class ButtonGroup extends PIXI.Graphics {
return this
}
/**
* Draws the canvas.
*
*
* @private
* @return {ButtonGroup} A reference to the button group for chaining.
*/
draw() {
if (this.opts.margin === 0) {
this.buttons.forEach(it => it.hide())
this.clear()
this.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha)
this.lineStyle(
this.opts.strokeWidth,
this.opts.stroke,
this.opts.strokeAlpha
)
this.beginFill(this.opts.fill, this.opts.fillAlpha)
this.drawRoundedRect(0, 0, this.width, this.height, this.opts.radius)
this.drawRoundedRect(
0,
0,
this.width,
this.height,
this.opts.radius
)
// Draw borders
this.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha / 2)
this.lineStyle(
this.opts.strokeWidth,
this.opts.stroke,
this.opts.strokeAlpha / 2
)
this.buttons.forEach((it, i) => {
if (i > 0) {
@@ -1721,7 +1750,6 @@ export default class ButtonGroup extends PIXI.Graphics {
} else {
this.lineTo(it.width, it.y)
}
}
})
@@ -1730,10 +1758,10 @@ export default class ButtonGroup extends PIXI.Graphics {
return this
}
/**
* Gets or sets the disabled state. When disabled, no button of the button group can be clicked.
*
*
* @member {boolean}
*/
get disabled() {
@@ -1741,32 +1769,29 @@ export default class ButtonGroup extends PIXI.Graphics {
}
set disabled(value) {
this._disabled = value
this.buttons.forEach(it => it.disabled = value)
this.buttons.forEach(it => (it.disabled = value))
}
/**
* Searches all buttons of the button group and returns the maximum width of one button.
*
*
* @private
* @return {number} The maximum with of a button of the button group.
*/
getMaxButtonWidth() {
let widths = this.buttons.map(it => it.width)
return Math.max(...widths)
}
/**
* Shows the button group (sets his alpha value to 1).
*
*
* @return {ButtonGroup} A reference to the button group for chaining.
*/
show() {
this.alpha = 1
return this
@@ -1774,11 +1799,10 @@ export default class ButtonGroup extends PIXI.Graphics {
/**
* Hides the button group (sets his alpha value to 0).
*
*
* @return {ButtonGroup} A reference to the button group for chaining.
*/
hide() {
this.alpha = 0
return this
@@ -1797,7 +1821,7 @@ export default class ButtonGroup extends PIXI.Graphics {
<footer class="content-size">
<div class="footer">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Wed Jul 10 2019 11:54:25 GMT+0200 (Mitteleuropäische Sommerzeit)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jul 18 2019 12:16:18 GMT+0200 (Mitteleuropäische Sommerzeit)
</div>
</footer>
</div>