Prettified badge.js.
This commit is contained in:
+33
-22
@@ -4,7 +4,7 @@ import Tooltip from './tooltip.js'
|
||||
|
||||
/**
|
||||
* Class that represents a PixiJS Badge.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* // Create the app
|
||||
* const app = new PIXIApp({
|
||||
@@ -12,13 +12,13 @@ import Tooltip from './tooltip.js'
|
||||
* width: 900,
|
||||
* height: 250
|
||||
* }).setup().run()
|
||||
*
|
||||
*
|
||||
* // Add an DisplayObject to the app
|
||||
* const circle = new PIXI.Graphics()
|
||||
* circle.beginFill(0x5251a3)
|
||||
* circle.drawCircle(50, 50, 40)
|
||||
* app.scene.addChild(circle)
|
||||
*
|
||||
*
|
||||
* const badge1 = new Badge({
|
||||
* object: circle,
|
||||
* container: app.scene,
|
||||
@@ -30,10 +30,9 @@ import Tooltip from './tooltip.js'
|
||||
* @see {@link https://www.iwm-tuebingen.de/iwmbrowser/lib/pixi/badge.html|DocTest}
|
||||
*/
|
||||
export default class Badge extends AbstractPopup {
|
||||
|
||||
/**
|
||||
* Creates an instance of a Badge.
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
* @param {object} [opts] - An options object to specify to style and behaviour of the badge.
|
||||
* @param {number} [opts.minWidth=0] - The minimum width of the badge.
|
||||
@@ -43,15 +42,18 @@ export default class Badge extends AbstractPopup {
|
||||
* to display.
|
||||
*/
|
||||
constructor(opts = {}) {
|
||||
|
||||
const theme = Theme.fromString(opts.theme)
|
||||
|
||||
opts = Object.assign({}, {
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
padding: theme.padding / 2,
|
||||
tooltip: null
|
||||
}, opts)
|
||||
|
||||
opts = Object.assign(
|
||||
{},
|
||||
{
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
padding: theme.padding / 2,
|
||||
tooltip: null
|
||||
},
|
||||
opts
|
||||
)
|
||||
|
||||
super(opts)
|
||||
|
||||
@@ -65,7 +67,7 @@ export default class Badge extends AbstractPopup {
|
||||
//-----------------
|
||||
this.layout()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates children and instantiates everything.
|
||||
*
|
||||
@@ -74,35 +76,44 @@ export default class Badge extends AbstractPopup {
|
||||
* @return {Badge} A reference to the badge for chaining.
|
||||
*/
|
||||
setup() {
|
||||
|
||||
super.setup()
|
||||
|
||||
// tooltip
|
||||
//-----------------
|
||||
if (this.opts.tooltip) {
|
||||
if (typeof this.opts.tooltip === 'string') {
|
||||
this.tooltip = new Tooltip({object: this, content: this.opts.tooltip})
|
||||
this.tooltip = new Tooltip({
|
||||
object: this,
|
||||
content: this.opts.tooltip
|
||||
})
|
||||
} else {
|
||||
this.opts.tooltip = Object.assign({}, {object: this}, this.opts.tooltip)
|
||||
this.opts.tooltip = Object.assign(
|
||||
{},
|
||||
{ object: this },
|
||||
this.opts.tooltip
|
||||
)
|
||||
this.tooltip = new Tooltip(this.opts.tooltip)
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should be called to refresh the layout of the badge. Can be used after resizing.
|
||||
*
|
||||
*
|
||||
* @override
|
||||
* @return {Badge} A reference to the badge for chaining.
|
||||
*/
|
||||
layout() {
|
||||
|
||||
super.layout()
|
||||
|
||||
this.content.x = this.width / 2 - this.content.width / 2 - this.opts.strokeWidth / 2
|
||||
this.content.y = this.height / 2 - this.content.height / 2 - this.opts.strokeWidth / 2
|
||||
this.content.x =
|
||||
this.width / 2 - this.content.width / 2 - this.opts.strokeWidth / 2
|
||||
this.content.y =
|
||||
this.height / 2 -
|
||||
this.content.height / 2 -
|
||||
this.opts.strokeWidth / 2
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user