@amoy/components
Version:
40 lines (37 loc) • 1.31 kB
text/typescript
export function bounds(co: any) {
co.on('init', () => {
co.pixiComponents.map((component: any) => {
component.prototype.getRelativeBounds = function() {
if (this.layout) {
return this.layout.rlayout
}
}
component.prototype.getRealBounds = function() {
if (this.layout) {
return this.layout.pixilayout
}
}
component.prototype.getGlobalBounds = function() {
let { x, y, width, height } = this.layout.rlayout
let parent = this.parent
while (parent) {
const relativeBounds = this.getRelativeBounds()
if (relativeBounds) {
x += relativeBounds.x
y += relativeBounds.y
} else {
x += parent.x
y += parent.y
}
parent = parent.parent
}
return {
x: Math.round(x),
y: Math.round(y),
width: Math.round(width),
height: Math.round(height),
}
}
})
})
}