-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ 调整Circle环形进度条在微信小程序端使用canvas2d支持同层渲染 (#351)
- Loading branch information
1 parent
c5b3c5f
commit 4489517
Showing
3 changed files
with
129 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/uni_modules/wot-design-uni/components/common/canvasHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 适配 canvas 2d 上下文 | ||
* @param ctx canvas 2d 上下文 | ||
* @returns | ||
*/ | ||
export function canvas2dAdapter(ctx: CanvasRenderingContext2D): UniApp.CanvasContext { | ||
return Object.assign(ctx, { | ||
setFillStyle(color: string | CanvasGradient) { | ||
ctx.fillStyle = color | ||
}, | ||
setStrokeStyle(color: string | CanvasGradient | CanvasPattern) { | ||
ctx.strokeStyle = color | ||
}, | ||
setLineWidth(lineWidth: number) { | ||
ctx.lineWidth = lineWidth | ||
}, | ||
setLineCap(lineCap: 'butt' | 'round' | 'square') { | ||
ctx.lineCap = lineCap | ||
}, | ||
|
||
setFontSize(font: string) { | ||
ctx.font = font | ||
}, | ||
setGlobalAlpha(alpha: number) { | ||
ctx.globalAlpha = alpha | ||
}, | ||
setLineJoin(lineJoin: 'bevel' | 'round' | 'miter') { | ||
ctx.lineJoin = lineJoin | ||
}, | ||
setTextAlign(align: 'left' | 'center' | 'right') { | ||
ctx.textAlign = align | ||
}, | ||
setMiterLimit(miterLimit: number) { | ||
ctx.miterLimit = miterLimit | ||
}, | ||
setShadow(offsetX: number, offsetY: number, blur: number, color: string) { | ||
ctx.shadowOffsetX = offsetX | ||
ctx.shadowOffsetY = offsetY | ||
ctx.shadowBlur = blur | ||
ctx.shadowColor = color | ||
}, | ||
setTextBaseline(textBaseline: 'top' | 'bottom' | 'middle') { | ||
ctx.textBaseline = textBaseline | ||
}, | ||
createCircularGradient() {}, | ||
draw() {}, | ||
addColorStop() {} | ||
}) as unknown as UniApp.CanvasContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters