"use strict"; cc._RF.push(module, '40ca3TtvP9FF753zFHG03Za', 'nx.fx.align.width'); // Scripts/nx/cmp/flex/nx.fx.align.width.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * NX UI插件 -- 宽度依赖 * * 2018.05.18 ******************************************************************/ cc.Class({ "extends": cc.Component, properties: { tar: { "default": null, type: cc.Node }, right: { "default": true }, space: { "default": 0 } }, // 编辑器特性 editor: { // 允许当前组件在编辑器模式下运行 executeInEditMode: false, // requireComponent 参数用来指定当前组件的依赖组件 requireComponent: null, // 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突 disallowMultiple: true, // menu 用来将当前组件添加到组件菜单中,方便用户查找 menu: "Nx/组件|宽度依赖" }, // 显示 onEnable: function onEnable() { nx.faw = this; // 监听尺寸改变 if (this.tar) { this.tar.on("position-changed", this.onTargetFresh.bind(this)); } this.onTargetFresh(); }, // 关闭 onDisable: function onDisable() { // 解除监听尺寸改变 if (this.tar) { this.tar.off("position-changed", this.onTargetFresh.bind(this)); } }, // 目标改变 onTargetFresh: function onTargetFresh() { if (!this.tar) { return; } // 右对齐处理 var box = this.tar.getBoundingBoxToWorld(); if (this.right) { var width = box.x - this.space; this.node.width = width; return; } nx.warn("$NxFxAlignWidth:尚未实现"); } }); cc._RF.pop();