Files
fc/dev/project/library/imports/55/5573cff8-c264-41cc-a1dc-16aad12758ef.js
2026-05-24 10:21:26 +08:00

93 lines
2.1 KiB
JavaScript

"use strict";
cc._RF.push(module, '5573c/4wmRBzKHcFqrRJ1jv', 'cmp.message.tip');
// Scripts/nx/cmp/message/cmp.message.tip.js
"use strict";
/*******************************************************************************
*
* 轻态提示框
*
*
*
* 2021.12.10
******************************************************************************/
cc.Class({
"extends": cc.Component,
properties: {
extWidth: {
"default": 150,
displayName: "扩边宽度"
}
},
// 载入
onLoad: function onLoad() {
var node = nx.gui.find(this, "txt");
if (node) {
node.on("size-changed", this.onResizeFrame, this);
}
},
// 设置
setText: function setText(_text, _maxWidth) {
if (nx.gui.getComponent(this, "txt", cc.Label)) {
this._normal(_text, _maxWidth);
} else {
this._rich(_text, _maxWidth);
}
},
// 普通文本
_normal: function _normal(_text, _maxWidth) {
var _this = this;
var txt = nx.gui.getComponent(this, "txt", cc.Label);
if (!txt) {
return;
}
// 默认为不限制宽度
txt.overflow = cc.Label.Overflow.NONE;
txt.string = _text;
txt._forceUpdateRenderData();
// 超出限制宽度
if (txt.node.width > _maxWidth) {
txt.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
txt.node.width = _maxWidth;
txt._forceUpdateRenderData();
}
// 调整自身宽度
this.scheduleOnce(function () {
_this.node.width = txt.node.width + _this.extWidth;
}, 0.01);
},
// 富文本
_rich: function _rich(_text, _maxWidth) {
var txt = nx.gui.getComponent(this, "txt", cc.RichText);
if (!txt) {
return;
}
this.maxWidth = _maxWidth;
txt.string = _text;
txt.maxWidth = 0;
},
// 框架设配
onResizeFrame: function onResizeFrame() {
// 调整自身宽度
var txt = nx.gui.getComponent(this, "txt", cc.RichText);
if (!txt) {
return;
}
// 超过宽度调整
if (txt.node.width > this.maxWidth) {
txt.maxWidth = this.maxWidth;
return;
}
// 边框调整
this.node.width = txt.node.width + this.extWidth;
}
});
cc._RF.pop();