UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.53 kB
import{ComponentSystem as e}from"../system.js";import{ScrollViewComponent as t}from"./component.js";import{ScrollViewComponentData as o}from"./data.js";import{Vec2 as n}from"../../../core/math/vec2.js";const i=[{name:"enabled",type:"boolean"},{name:"horizontal",type:"boolean"},{name:"vertical",type:"boolean"},{name:"scrollMode",type:"number"},{name:"bounceAmount",type:"number"},{name:"friction",type:"number"},{name:"dragThreshold",type:"number"},{name:"useMouseWheel",type:"boolean"},{name:"mouseWheelSensitivity",type:"vec2"},{name:"horizontalScrollbarVisibility",type:"number"},{name:"verticalScrollbarVisibility",type:"number"}];class s extends e{constructor(e){super(e),this.id="scrollview",this.ComponentType=t,this.DataType=o,this.schema=i,this.on("beforeremove",this._onRemoveComponent,this),this.app.systems.on("update",this.onUpdate,this)}initializeComponentData(e,t,o){void 0===t.dragThreshold&&(t.dragThreshold=10),void 0===t.useMouseWheel&&(t.useMouseWheel=!0),void 0===t.mouseWheelSensitivity&&(t.mouseWheelSensitivity=new n(1,1)),super.initializeComponentData(e,t,i),e.viewportEntity=t.viewportEntity,e.contentEntity=t.contentEntity,e.horizontalScrollbarEntity=t.horizontalScrollbarEntity,e.verticalScrollbarEntity=t.verticalScrollbarEntity}onUpdate(e){const t=this.store;for(const e in t){const o=t[e].entity,n=o.scrollview;n.enabled&&o.enabled&&n.onUpdate()}}_onRemoveComponent(e,t){t.onRemove()}destroy(){super.destroy(),this.app.systems.off("update",this.onUpdate,this)}}export{s as ScrollViewComponentSystem};