UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.18 kB
import{Vec2 as e}from"../../../core/math/vec2.js";import{Vec4 as t}from"../../../core/math/vec4.js";import{Component as i}from"../component.js";import{ComponentSystem as o}from"../system.js";import{LayoutGroupComponent as n}from"./component.js";import{LayoutGroupComponentData as r}from"./data.js";const s=["enabled"];class a extends o{constructor(e){super(e),this.id="layoutgroup",this.ComponentType=n,this.DataType=r,this.schema=s,this._reflowQueue=[],this.on("beforeremove",this._onRemoveComponent,this),this.app.systems.on("postUpdate",this._onPostUpdate,this)}initializeComponentData(i,o,n){void 0!==o.enabled&&(i.enabled=o.enabled),void 0!==o.orientation&&(i.orientation=o.orientation),void 0!==o.reverseX&&(i.reverseX=o.reverseX),void 0!==o.reverseY&&(i.reverseY=o.reverseY),void 0!==o.alignment&&(i.alignment=Array.isArray(o.alignment)?new e(o.alignment):o.alignment),void 0!==o.padding&&(i.padding=Array.isArray(o.padding)?new t(o.padding):o.padding),void 0!==o.spacing&&(i.spacing=Array.isArray(o.spacing)?new e(o.spacing):o.spacing),void 0!==o.widthFitting&&(i.widthFitting=o.widthFitting),void 0!==o.heightFitting&&(i.heightFitting=o.heightFitting),void 0!==o.wrap&&(i.wrap=o.wrap),super.initializeComponentData(i,o,n)}cloneComponent(e,t){const i=e.layoutgroup;return this.addComponent(t,{enabled:i.enabled,orientation:i.orientation,reverseX:i.reverseX,reverseY:i.reverseY,alignment:i.alignment,padding:i.padding,spacing:i.spacing,widthFitting:i.widthFitting,heightFitting:i.heightFitting,wrap:i.wrap})}scheduleReflow(e){-1===this._reflowQueue.indexOf(e)&&this._reflowQueue.push(e)}_onPostUpdate(){this._processReflowQueue()}_processReflowQueue(){if(0===this._reflowQueue.length)return;let e=0;for(;this._reflowQueue.length>0;){const t=this._reflowQueue.slice();this._reflowQueue.length=0,t.sort(((e,t)=>e.entity.graphDepth-t.entity.graphDepth));for(let e=0;e<t.length;++e)t[e].reflow();if(++e>=100){console.warn("Max reflow iterations limit reached, bailing.");break}}}_onRemoveComponent(e,t){t.onRemove()}destroy(){super.destroy(),this.app.systems.off("postUpdate",this._onPostUpdate,this)}}i._buildAccessors(n.prototype,s);export{a as LayoutGroupComponentSystem};