UNPKG

laya-coreui-es

Version:

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

99 lines (98 loc) 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TipManager = void 0; const Text_1 = require("../display/Text"); const Event_1 = require("../events/Event"); const UIComponent_1 = require("./UIComponent"); const UIEvent_1 = require("./UIEvent"); const Handler_1 = require("../utils/Handler"); const ILaya_1 = require("../../ILaya"); class TipManager extends UIComponent_1.UIComponent { constructor() { super(); this._tipBox = new UIComponent_1.UIComponent(); this._tipBox.addChild(this._tipText = new Text_1.Text()); this._tipText.x = this._tipText.y = 5; this._tipText.color = TipManager.tipTextColor; this._defaultTipHandler = this._showDefaultTip; ILaya_1.ILaya.stage.on(UIEvent_1.UIEvent.SHOW_TIP, this, this._onStageShowTip); ILaya_1.ILaya.stage.on(UIEvent_1.UIEvent.HIDE_TIP, this, this._onStageHideTip); this.zOrder = 1100; } _onStageHideTip(e) { ILaya_1.ILaya.timer.clear(this, this._showTip); this.closeAll(); this.removeSelf(); } _onStageShowTip(data) { ILaya_1.ILaya.timer.once(TipManager.tipDelay, this, this._showTip, [data], true); } _showTip(tip) { if (typeof (tip) == 'string') { var text = String(tip); if (Boolean(text)) { this._defaultTipHandler(text); } } else if (tip instanceof Handler_1.Handler) { tip.run(); } else if (tip instanceof Function) { tip.apply(); } if (true) { ILaya_1.ILaya.stage.on(Event_1.Event.MOUSE_MOVE, this, this._onStageMouseMove); ILaya_1.ILaya.stage.on(Event_1.Event.MOUSE_DOWN, this, this._onStageMouseDown); } this._onStageMouseMove(null); } _onStageMouseDown(e) { this.closeAll(); } _onStageMouseMove(e) { this._showToStage(this, TipManager.offsetX, TipManager.offsetY); } _showToStage(dis, offX = 0, offY = 0) { var rec = dis.getBounds(); dis.x = ILaya_1.ILaya.stage.mouseX + offX; dis.y = ILaya_1.ILaya.stage.mouseY + offY; if (dis._x + rec.width > ILaya_1.ILaya.stage.width) { dis.x -= rec.width + offX; } if (dis._y + rec.height > ILaya_1.ILaya.stage.height) { dis.y -= rec.height + offY; } } closeAll() { ILaya_1.ILaya.timer.clear(this, this._showTip); ILaya_1.ILaya.stage.off(Event_1.Event.MOUSE_MOVE, this, this._onStageMouseMove); ILaya_1.ILaya.stage.off(Event_1.Event.MOUSE_DOWN, this, this._onStageMouseDown); this.removeChildren(); } showDislayTip(tip) { this.addChild(tip); this._showToStage(this); ILaya_1.ILaya.stage.addChild(this); } _showDefaultTip(text) { this._tipText.text = text; var g = this._tipBox.graphics; g.clear(true); g.drawRect(0, 0, this._tipText.width + 10, this._tipText.height + 10, TipManager.tipBackColor); this.addChild(this._tipBox); this._showToStage(this); ILaya_1.ILaya.stage.addChild(this); } get defaultTipHandler() { return this._defaultTipHandler; } set defaultTipHandler(value) { this._defaultTipHandler = value; } } exports.TipManager = TipManager; TipManager.offsetX = 10; TipManager.offsetY = 15; TipManager.tipTextColor = "#ffffff"; TipManager.tipBackColor = "#111111"; TipManager.tipDelay = 200;