Skip to content

Commit 9b4d619

Browse files
committed
feat:图元新增placeholder属性
1 parent f176f7e commit 9b4d619

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/core/src/pen/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ export interface Pen extends Rect {
206206

207207
// canvas 滤镜
208208
filter?: string;
209-
209+
placeholder?: string; //占位符
210+
placeholderColor?: string;
210211
text?: string;
211212
textWidth?: number;
212213
textHeight?: number;

packages/core/src/pen/render.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,25 @@ function drawText(ctx: CanvasRenderingContext2D, pen: Pen) {
996996
textBackground,
997997
textType,
998998
} = pen.calculative;
999+
if (
1000+
pen.input &&
1001+
!pen.text &&
1002+
!(pen.calculative.canvas.inputDiv.dataset.penId === pen.id)
1003+
) {
1004+
ctx.save();
1005+
ctx.font = getFont({
1006+
fontStyle,
1007+
fontWeight,
1008+
fontFamily: fontFamily,
1009+
fontSize,
1010+
lineHeight,
1011+
});
1012+
ctx.fillStyle = pen.placeholderColor || '#c0c0c0';
1013+
const rect = pen.calculative.worldTextRect;
1014+
ctx.fillText(pen.placeholder || '请输入', rect.x, rect.y + rect.height / 2);
1015+
ctx.restore();
1016+
}
1017+
9991018
if (text == undefined || hiddenText) {
10001019
return;
10011020
}

0 commit comments

Comments
 (0)