我在继承Rect类,以制作自己的元素,称为“按钮”。里面有文字,我想向iText提供smillar的编辑文字工具(双击允许编辑) 如何达到这个目标? 自定义组件代码:
export class Button extends fabric.Rect {
public text: string;
public textColor: string;
public font = '30px Arial';
public action: ActionEnum;
constructor(options: IButttonOptions) {
super(options);
if (options.font) {
this.font = options.font;
}
this.text = options.text;
this.textColor = options.textColor;
this.action = options.action;
}
_render (ctx: CanvasRenderingContext2D) {
super._render(ctx);
ctx.font = this.font;
ctx.fillStyle = this.textColor;
ctx.textAlign = 'center';
ctx.fillText(this.text, 0, 10);
}
}