UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

40 lines (39 loc) 1.03 kB
import { Box } from "./Box"; import { ILaya } from "../../ILaya"; export class ScaleBox extends Box { constructor() { super(...arguments); this._oldW = 0; this._oldH = 0; } onEnable() { ILaya.stage.on("resize", this, this.onResize); this.onResize(); } onDisable() { ILaya.stage.off("resize", this, this.onResize); } onResize() { let stage = ILaya.stage; if (this.width > 0 && this.height > 0) { var scale = Math.min(stage.width / this._oldW, stage.height / this._oldH); super.width = stage.width; super.height = stage.height; this.scale(scale, scale); } } set width(value) { super.width = value; this._oldW = value; } get width() { return super.width; } set height(value) { super.height = value; this._oldH = value; } get height() { return super.height; } }