UNPKG

laya-coreui-es

Version:

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

124 lines (123 loc) 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressBar = void 0; const Event_1 = require("../events/Event"); const Loader_1 = require("../net/Loader"); const UIComponent_1 = require("./UIComponent"); const Image_1 = require("./Image"); const Handler_1 = require("../utils/Handler"); const ILaya_1 = require("../../ILaya"); class ProgressBar extends UIComponent_1.UIComponent { constructor(skin = null) { super(); this._value = 0.5; this.skin = skin; } destroy(destroyChild = true) { super.destroy(destroyChild); this._bg && this._bg.destroy(destroyChild); this._bar && this._bar.destroy(destroyChild); this._bg = this._bar = null; this.changeHandler = null; } createChildren() { this.addChild(this._bg = new Image_1.Image()); this.addChild(this._bar = new Image_1.Image()); this._bar._bitmap.autoCacheCmd = false; } get skin() { return this._skin; } set skin(value) { if (this._skin != value) { this._skin = value; if (this._skin && !Loader_1.Loader.getRes(this._skin)) { ILaya_1.ILaya.loader.load(this._skin, Handler_1.Handler.create(this, this._skinLoaded), null, Loader_1.Loader.IMAGE, 1); } else { this._skinLoaded(); } } } _skinLoaded() { if (this.destroyed) { return; } this._bg.skin = this._skin; this._bar.skin = this._skin.replace(".png", "$bar.png"); this.callLater(this.changeValue); this._sizeChanged(); this.event(Event_1.Event.LOADED); } measureWidth() { return this._bg.width; } measureHeight() { return this._bg.height; } get value() { return this._value; } set value(num) { if (this._value != num) { num = num > 1 ? 1 : num < 0 ? 0 : num; this._value = num; this.callLater(this.changeValue); this.event(Event_1.Event.CHANGE); this.changeHandler && this.changeHandler.runWith(num); } } changeValue() { if (this.sizeGrid) { var grid = this.sizeGrid.split(","); var left = Number(grid[3]); var right = Number(grid[1]); var max = this.width - left - right; var sw = max * this._value; this._bar.width = left + right + sw; this._bar.visible = this._bar.width > left + right; } else { this._bar.width = this.width * this._value; } } get bar() { return this._bar; } get bg() { return this._bg; } get sizeGrid() { return this._bg.sizeGrid; } set sizeGrid(value) { this._bg.sizeGrid = this._bar.sizeGrid = value; } set width(value) { super.width = value; this._bg.width = this._width; this.callLater(this.changeValue); } get width() { return super.width; } set height(value) { super.height = value; this._bg.height = this._height; this._bar.height = this._height; } get height() { return super.height; } set dataSource(value) { this._dataSource = value; if (typeof (value) == 'number' || typeof (value) == 'string') this.value = Number(value); else super.dataSource = value; } get dataSource() { return super.dataSource; } } exports.ProgressBar = ProgressBar;