Files
fc/dev/project/assets/Scripts/nx/cmp/flex/nx.fx.align.width.js
T
2026-05-23 22:10:14 +08:00

76 lines
1.8 KiB
JavaScript

/******************************************************************
* 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() {
nx.faw = this;
// 监听尺寸改变
if( this.tar ) {
this.tar.on( "position-changed", this.onTargetFresh.bind( this ) );
}
this.onTargetFresh();
},
// 关闭
onDisable: function() {
// 解除监听尺寸改变
if( this.tar ) {
this.tar.off( "position-changed", this.onTargetFresh.bind( this ) );
}
},
// 目标改变
onTargetFresh: function() {
if( !this.tar ) {
return;
}
// 右对齐处理
let box = this.tar.getBoundingBoxToWorld();
if( this.right ) {
let width = box.x - this.space;
this.node.width = width;
return;
}
nx.warn( "$NxFxAlignWidth:尚未实现" );
},
} );