UNPKG

laya-coreui-es

Version:

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

114 lines (113 loc) 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Image = void 0; const Styles_1 = require("./Styles"); const Event_1 = require("../events/Event"); const Loader_1 = require("../net/Loader"); const AutoBitmap_1 = require("./AutoBitmap"); const UIComponent_1 = require("./UIComponent"); const UIUtils_1 = require("./UIUtils"); const Handler_1 = require("../utils/Handler"); const ILaya_1 = require("../../ILaya"); class Image extends UIComponent_1.UIComponent { constructor(skin = null) { super(); this.skin = skin; } destroy(destroyChild = true) { super.destroy(destroyChild); this._bitmap && this._bitmap.destroy(); this._bitmap = null; } dispose() { this.destroy(true); ILaya_1.ILaya.loader.clearRes(this._skin); } createChildren() { this.graphics = this._bitmap = new AutoBitmap_1.AutoBitmap(); this._bitmap.autoCacheCmd = false; } get skin() { return this._skin; } set skin(value) { if (this._skin != value) { this._skin = value; if (value) { var source = Loader_1.Loader.getRes(value); if (source) { this.source = source; this.onCompResize(); } else ILaya_1.ILaya.loader.load(this._skin, Handler_1.Handler.create(this, this.setSource, [this._skin]), null, Loader_1.Loader.IMAGE, 1, true, this._group); } else { this.source = null; } } } get source() { return this._bitmap.source; } set source(value) { if (!this._bitmap) return; this._bitmap.source = value; this.event(Event_1.Event.LOADED); this.repaint(); } get group() { return this._group; } set group(value) { if (value && this._skin) Loader_1.Loader.setGroup(this._skin, value); this._group = value; } setSource(url, img = null) { if (url === this._skin && img) { this.source = img; this.onCompResize(); } } measureWidth() { return this._bitmap.width; } measureHeight() { return this._bitmap.height; } set width(value) { super.width = value; this._bitmap.width = value == 0 ? 0.0000001 : value; } get width() { return super.width; } set height(value) { super.height = value; this._bitmap.height = value == 0 ? 0.0000001 : value; } get height() { return super.height; } get sizeGrid() { if (this._bitmap.sizeGrid) return this._bitmap.sizeGrid.join(","); return null; } set sizeGrid(value) { this._bitmap.sizeGrid = UIUtils_1.UIUtils.fillArray(Styles_1.Styles.defaultSizeGrid, value, Number); } set dataSource(value) { this._dataSource = value; if (typeof (value) == 'string') this.skin = value; else super.dataSource = value; } get dataSource() { return super.dataSource; } } exports.Image = Image;