Skip to content
Widget

界面 / Widget

Widget Class
​

控件的基类


可挂载叶子节点的根节点,以及提供各种自动布局功能。

放置控件需要的通用属性与方法。

Hierarchy ​

Table of contents ​

Properties
​

onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client
监听自定义属性同步事件

Accessors
​

alignPosition(): Readonly<Vector2> client
获取控件的对齐位置,在对齐方式为靠右对齐、靠下对齐、中心对齐时,alignPosition的值与positon不同;
autoSizeHorizontalEnable(): boolean client
获取是否自动水平设置大小
autoSizeVerticalEnable(): boolean client
获取是否自动垂直设置大小
cachedGeometry(): Geometry client
获取上一次的GetTickSpaceGeometry
constraints(): Readonly<UIConstraintAnchors> client
获取控件的布局
desiredSize(): Vector2 client
获取期望大小
enable(): boolean client
是否可用
guid(): string client
获取控件GUID
isHovered(): boolean client
是否是hovered
mouseCursor(): MouseCursor client
获取控件上光标类型
name(): string client
获取名字
paintSpaceGeometry(): Geometry client
获取最后一次用于渲染Widget的几何信息
parent(): Widget client
获取父节点
pivot(): Vector2 client
获取控件锚点位置,这个属性决定了控件图形与锚点的相对位置;(0,0)时,锚点位于控件左上角;(0.5,0.5)时,锚点位于控件正中心
position(): Readonly<Vector2> client
获取控件的位置
renderOpacity(): number client
获取渲染透明度
renderScale(): Vector2 client
获取渲染缩放
renderShear(): Vector2 client
获取渲染错切形变
renderTransformAngle(): number client
获取渲染的角度
renderTransformPivot(): Vector2 client
获取渲染锚点
size(): Vector2 client
获取大小
tickSpaceGeometry(): Geometry client
获取最后一次用于驱动Widget Tick的几何信息
transform(): Readonly<UITransform> client
得到控件的大小和位置
visibility(): SlateVisibility client
获取可见性
visible(): boolean client
是否可见
zOrder(): number client
获取zorder

Methods
​

addChild(child: Widget): void client
添加子节点
clone(position: Vector2, Parent?: Widget): Widget client
克隆UI控件及其子节点到指定父控件位置(默认到其父节点)
destroyObject(): void client
立刻移除并销毁 不可以在使用
equal(that: Widget): boolean client
判断是不是同一个对象
findChildByPath(inPath: string): Widget client
通过相对路径查找节点
getChildAt(index: number): Widget client
获取第几位子节点
getChildByName<T: extends Widget<T>>(name: string): T: extends Widget<T> client
通过名字查找节点
getChildrenCount(): number client
获取子节点数量
getCustomProperties(): string[] client
获取所有自定义属性
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType client
获取自定义属性
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client
给定对象属性修改时触发的事件代理
invalidateLayoutAndVolatility(): void client
立刻触发重新渲染的和排布计算
isValid(): boolean client
判断控件有没有被销毁,是否是有效的控件
removeAllChildren(): void client
清除所有子节点,会销毁UI无法再使用
removeChild(child: Widget): void client
移除节点,会销毁UI无法在使用
removeChildAt(index: number): void client
移除第几个节点,会销毁UI无法再使用
removeObject(): void client
立刻移除并添加到根节点 可以再使用
serialize(): string client
序列化UI控件
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void client
设置自定义属性
deserialize(Data: string, Parent?: Widget): Widget client
反序列化UI

Properties ​

onCustomPropertyChange
​

• onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client

监听自定义属性同步事件

使用示例:监听自定义属性变化
ts
this.onCustomPropertyChange.add((path, value, oldValue) => {
    console.log(`属性 ${path} 改变了,新值为 ${value},旧值为 ${oldValue}`);
});
this.onCustomPropertyChange.add((path, value, oldValue) => {
    console.log(`属性 ${path} 改变了,新值为 ${value},旧值为 ${oldValue}`);
});

Accessors ​

alignPosition
​

• get alignPosition(): Readonly<Vector2> client

• set alignPosition(inFigmaPosition): void client

获取控件的对齐位置,在对齐方式为靠右对齐、靠下对齐、中心对齐时,alignPosition的值与positon不同;

此时,两套位置计算的坐标系不同,例如设置为右下对齐时,该控件的alignPosition以父级右下角为原点来计算

Returns ​

Readonly<Vector2>控件的对齐位置

设置控件的对齐位置,在对齐方式为靠右对齐、靠下对齐、中心对齐时,alignPosition的值与positon不同;

此时,两套位置计算的坐标系不同,例如设置为右下对齐时,该控件的alignPosition以父级右下角为原点来计算

Parameters ​

inFigmaPosition Vector2控件的对齐位置

autoSizeHorizontalEnable
​

• get autoSizeHorizontalEnable(): boolean client

• set autoSizeHorizontalEnable(bEnabled): void client

获取是否自动水平设置大小

Returns ​

boolean是否自动水平设置大小

获取是否自动水平设置大小

Parameters ​

bEnabledboolean

是否自动水平设置大小


autoSizeVerticalEnable
​

• get autoSizeVerticalEnable(): boolean client

• set autoSizeVerticalEnable(bEnabled): void client

获取是否自动垂直设置大小

Returns ​

boolean是否自动垂直设置大小

获取是否自动垂直设置大小

Parameters ​

bEnabledboolean

是否自动垂直设置大小


cachedGeometry
​

• get cachedGeometry(): Geometry client

获取上一次的GetTickSpaceGeometry

Returns ​

Geometry返回上一次的 GetTickSpaceGeometry

constraints
​

• get constraints(): Readonly<UIConstraintAnchors> client

• set constraints(ininconstraints): void client

获取控件的布局

Returns ​

Readonly<UIConstraintAnchors>控件的布局

设置控件的布局

Parameters ​

ininconstraints UIConstraintAnchors控件的布局

desiredSize
​

• get desiredSize(): Vector2 client

获取期望大小

Returns ​

Vector2返回期望大小

enable
​

• get enable(): boolean client

• set enable(isEnable): void client

是否可用

Returns ​

booleanboolean

设置可用性

Parameters ​

isEnable boolean可用性boolean

返回设置结果


guid
​

• get guid(): string client

获取控件GUID

Returns ​

string控件GUID

isHovered
​

• get isHovered(): boolean client

是否是hovered

Returns ​

booleanboolean

mouseCursor
​

• get mouseCursor(): MouseCursor client

• set mouseCursor(type): void client

获取控件上光标类型

Returns ​

MouseCursor光标类型

将光标类型设置到控件上

Parameters ​

typeMouseCursor

name
​

• get name(): string client

• set name(name): void client

获取名字

Returns ​

string返回名字

设定名字

Parameters ​

name string名字

paintSpaceGeometry
​

• get paintSpaceGeometry(): Geometry client

获取最后一次用于渲染Widget的几何信息

Returns ​

Geometry返回最后一次用于渲染Widget的几何信息

parent
​

• get parent(): Widget client

获取父节点

Returns ​

Widget返回父节点

pivot
​

• get pivot(): Vector2 client

• set pivot(inPivot): void client

获取控件锚点位置,这个属性决定了控件图形与锚点的相对位置;(0,0)时,锚点位于控件左上角;(0.5,0.5)时,锚点位于控件正中心

锚点本身的位置由positon或alignPosition决定

Returns ​

Vector2控件的锚点位置

设置控件锚点位置,这个属性决定了控件图形与锚点的相对位置;(0,0)时,锚点位于控件左上角;(0.5,0.5)时,锚点位于控件正中心;

锚点本身的位置由positon或alignPosition决定

Parameters ​

inPivot Vector2输入的锚点位置

position
​

• get position(): Readonly<Vector2> client

• set position(inFigmaPosition): void client

获取控件的位置

Returns ​

Readonly<Vector2>控件的位置

设置控件的位置

Parameters ​

inFigmaPosition Vector2控件的位置

renderOpacity
​

• get renderOpacity(): number client

• set renderOpacity(InOpacity): void client

获取渲染透明度

Returns ​

number返回渲染透明度

设置渲染透明度 0 ~ 1

Parameters ​

InOpacity number透明度

renderScale
​

• get renderScale(): Vector2 client

• set renderScale(scale): void client

获取渲染缩放

Returns ​

Vector2返回渲染缩放

设置渲染缩放

Parameters ​

scale Vector2渲染缩放

renderShear
​

• get renderShear(): Vector2 client

• set renderShear(shear): void client

获取渲染错切形变

Returns ​

Vector2返回渲染错切形变

设置渲染错切形变

Parameters ​

shear Vector2渲染错切形变

renderTransformAngle
​

• get renderTransformAngle(): number client

• set renderTransformAngle(o): void client

获取渲染的角度

Returns ​

number返回渲染角度

设置渲染的角度

Parameters ​

o number渲染角度

renderTransformPivot
​

• get renderTransformPivot(): Vector2 client

• set renderTransformPivot(Pivot): void client

获取渲染锚点

Returns ​

Vector2返回渲染锚点

设置渲染锚点

Parameters ​

Pivot Vector2渲染锚点

size
​

• get size(): Vector2 client

• set size(inSize): void client

获取大小

Returns ​

Vector2FVector2D

设置控件的大小

Parameters ​

inSize Vector2输入大小

tickSpaceGeometry
​

• get tickSpaceGeometry(): Geometry client

获取最后一次用于驱动Widget Tick的几何信息

Returns ​

Geometry返回最后一次用于驱动Widget Tick的几何信息

transform
​

• get transform(): Readonly<UITransform> client

• set transform(inTransform): void client

得到控件的大小和位置

Returns ​

Readonly<UITransform>控件的大小和位置

设置控件的大小和位置

Parameters ​

inTransform UITransform大小位置

visibility
​

• get visibility(): SlateVisibility client

• set visibility(Visibility): void client

获取可见性

Returns ​

SlateVisibility返回可见性

设置可见性

Parameters ​

Visibility SlateVisibility可见性

visible
​

• get visible(): boolean client

是否可见

Returns ​

booleanboolean

zOrder
​

• get zOrder(): number client

• set zOrder(InZOrder): void client

获取zorder

Returns ​

numberzorder

设置zoder

Parameters ​

InZOrder number值越大在越上层

Methods ​

addChild
​

• addChild(child): void client

添加子节点

Parameters ​

child Widget子控件

clone
​

• clone(position, Parent?): Widget client

克隆UI控件及其子节点到指定父控件位置(默认到其父节点)

Parameters ​

position Vector2克隆后控件生成的位置
Parent? Widget克隆后的控件需要在该控件下生成 default: undefined

Returns ​

Widget克隆生成的UI控件

destroyObject
​

• destroyObject(): void client

立刻移除并销毁 不可以在使用


equal
​

• equal(that): boolean client

判断是不是同一个对象

Parameters ​

that Widget需要比较的另外一个对象

Returns ​

booleanboolean

findChildByPath
​

• findChildByPath(inPath): Widget client

通过相对路径查找节点

Parameters ​

inPath string路径 range: 不限制

Returns ​

Widget返回查找节点结果

getChildAt
​

• getChildAt(index): Widget client

获取第几位子节点

Parameters ​

index number下标 range:大于等于0 type: 整形

Returns ​

Widget找到的控件

getChildByName
​

• getChildByName<T>(name): T client

通过名字查找节点

Parameters ​

name string名字
range: 不限制

Returns ​

T找到的控件

Type parameters ​

Textends Widget<T>

getChildrenCount
​

• getChildrenCount(): number client

获取子节点数量

Returns ​

number子节点数量

getCustomProperties
​

• getCustomProperties(): string[] client

获取所有自定义属性

Returns ​

string[]属性名列表
使用示例:获取所有自定义属性
ts
const attributes = this.getAttributes();
console.log(attributes);
// ["name", "age"]
const attributes = this.getAttributes();
console.log(attributes);
// ["name", "age"]

getCustomProperty
​

• getCustomProperty<T>(propertyName): T client

获取自定义属性

Parameters ​

propertyName string对象属性名字 range: 无

Returns ​

T属性值

Type parameters ​

Textends CustomPropertyType

getCustomPropertyChangeDelegate
​

• getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client

给定对象属性修改时触发的事件代理

Parameters ​

property string对象属性名字 range: 无

Returns ​

Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>代理对象

invalidateLayoutAndVolatility
​

• invalidateLayoutAndVolatility(): void client

立刻触发重新渲染的和排布计算


isValid
​

• isValid(): boolean client

判断控件有没有被销毁,是否是有效的控件

Returns ​

booleanboolean 是否还有效,判定有没有被销毁

removeAllChildren
​

• removeAllChildren(): void client

清除所有子节点,会销毁UI无法再使用


removeChild
​

• removeChild(child): void client

移除节点,会销毁UI无法在使用

Parameters ​

child Widget需要移除的子控件

removeChildAt
​

• removeChildAt(index): void client

移除第几个节点,会销毁UI无法再使用

Parameters ​

index number下标 range: 大于 0 type: 整形

removeObject
​

• removeObject(): void client

立刻移除并添加到根节点 可以再使用


serialize
​

• serialize(): string client

序列化UI控件

Returns ​

string返回传入控件序列化后的JSON字符串

setCustomProperty
​

• setCustomProperty(propertyName, value): void client

设置自定义属性

Parameters ​

propertyName string对象属性名字 range: 无
value undefined CustomPropertyType属性值

deserialize
​

• Static deserialize(Data, Parent?): Widget client

反序列化UI

Parameters ​

Data string需要反序列化的JSON字符串 range: 无
Parent? Widget生成的UI控件的父节点 default: undefined

Returns ​

Widget返回传入JSON字符串反序列化后得到的UI