Added badge content example to button doctest.
This commit is contained in:
+35
-24
@@ -339,34 +339,12 @@ export default class Button extends PIXI.Container {
|
||||
}
|
||||
|
||||
const badge = new Badge(opts)
|
||||
|
||||
switch (opts.align) {
|
||||
case 'left':
|
||||
badge.x = this.x - badge.width / 2 + opts.offsetLeft
|
||||
break
|
||||
case 'center':
|
||||
badge.x = this.x + this.width / 2 - badge.width / 2 + opts.offsetLeft
|
||||
break
|
||||
case 'right':
|
||||
badge.x = this.x + this.width - badge.width / 2 + opts.offsetLeft
|
||||
}
|
||||
|
||||
switch (opts.verticalAlign) {
|
||||
case 'top':
|
||||
badge.y = this.y - badge.height / 2 + opts.offsetTop
|
||||
break
|
||||
case 'middle':
|
||||
badge.y = this.y + this.height / 2 - badge.height / 2 + opts.offsetTop
|
||||
break
|
||||
case 'bottom':
|
||||
badge.y = this.y + this.height - badge.height / 2 + opts.offsetTop
|
||||
}
|
||||
|
||||
this.addChild(badge)
|
||||
|
||||
this.badge = badge
|
||||
}
|
||||
|
||||
this.layout()
|
||||
|
||||
// set position
|
||||
//-----------------
|
||||
this.position.set(this.opts.x, this.opts.y)
|
||||
@@ -451,6 +429,39 @@ export default class Button extends PIXI.Container {
|
||||
|
||||
this.icon = icon
|
||||
|
||||
// badge
|
||||
//--------------------
|
||||
if (this.badge) {
|
||||
this.removeChild(this.badge)
|
||||
const width = this.width
|
||||
const height = this.height
|
||||
this.addChild(this.badge)
|
||||
|
||||
const badge = this.badge
|
||||
|
||||
switch (badge.opts.align) {
|
||||
case 'left':
|
||||
badge.x = -badge.width / 2 + badge.opts.offsetLeft
|
||||
break
|
||||
case 'center':
|
||||
badge.x = width / 2 - badge.width / 2 + badge.opts.offsetLeft
|
||||
break
|
||||
case 'right':
|
||||
badge.x = width - badge.width / 2 + badge.opts.offsetLeft
|
||||
}
|
||||
|
||||
switch (badge.opts.verticalAlign) {
|
||||
case 'top':
|
||||
badge.y = -badge.height / 2 + badge.opts.offsetTop
|
||||
break
|
||||
case 'middle':
|
||||
badge.y = height / 2 - badge.height / 2 + badge.opts.offsetTop
|
||||
break
|
||||
case 'bottom':
|
||||
badge.y = height - badge.height / 2 + badge.opts.offsetTop
|
||||
}
|
||||
}
|
||||
|
||||
// draw
|
||||
//-----------------
|
||||
this.draw()
|
||||
|
||||
Reference in New Issue
Block a user