pixso.fieldset
pixso.fieldset
为画框工具,该工具区别于 Pixso 应用的其他画笔工具,并不会在画布上绘制生成一个实质的图层,但配合画框工具的以下 API,可用于在插件上实现一些复杂的自定义交互。
name
- type:
string
可获取或修改画框工具按钮所展示的名称(仅能获取自定义的名称,不包括默认名称)。
setIcon
- type:
setIcon(icon: string | Uint8Array): void
可修改画框工具按钮所展示的图标。
strokeColor
- type:
{r: number, g: number, b: number, a: number}
可获取或修改画框工具所绘制的边框颜色。
strokeWeight
- type:
number
可获取或修改画框工具所绘制的边框粗细。
dashPattern
- type:
ReadonlyArray<number>
可获取或修改画框工具所绘制的边框短划线与间隙的长度。
enable
- type:
enable(): void
画笔工具按钮展示在 Pixso 顶部工具条,但默认是隐藏状态。要想使用画笔工具,需先执行 pixso.fieldset.enable()
展示该功能。
disable
- type:
disable(): void
再通过 pixso.fieldset.enable()
展示画笔工具按钮后,可根据需要执行 pixso.fieldset.disable()
再隐藏该功能。
remove
- type:
remove(): void
主动移除画框工具所绘制的边框。
on
on(type: "drawstart", callback: () => void): void;
on(type: "drawend", callback: (event: FieldsetEvent) => void): void;
on(type: "move", callback: (event: FieldsetEvent) => void): void;
on(type: "disappear", callback: () => void): void;
on
方法允许注册画框工具特定事件的处理函数,当事件发生时会执行该回调函数,事件类型如下:
drawstart
:使用画框工具开始绘制边框或重新拉伸绘制的边框。drawend
:使用画框工具结束绘制边框或结束拉伸绘制的边框。move
: 拖拽使用画框工具所绘制的边框。disappear
: 使用画框工具所绘制的边框从画布中移除。
once
once(type: "drawstart", callback: () => void): void;
once(type: "drawend", callback: (event: FieldsetEvent) => void): void;
once(type: "move", callback: (event: FieldsetEvent) => void): void;
once(type: "disappear", callback: () => void): void;
once
方法允许注册画框工具特定事件的处理函数,当事件发生时会执行该回调函数。与 on
方法的区别在于,通过 once
方法注册的事件处理函数只会执行一次。
off
off(type: "drawstart", callback: () => void): void;
off(type: "drawend", callback: (event: FieldsetEvent) => void): void;
off(type: "move", callback: (event: FieldsetEvent) => void): void;
off(type: "disappear", callback: () => void): void;
移除通过 pixso.fieldset.on
或 pixso.fieldset.once
绑定的事件处理函数。