|
|
|
|
@ -12,24 +12,39 @@ export class CheckboxParticle {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public render(ctx: CanvasRenderingContext2D, element: IRowElement, x: number, y: number) {
|
|
|
|
|
const { checkbox: { gap, lineWidth } } = this.options
|
|
|
|
|
const { checkbox: { gap, lineWidth, fillStyle, fontStyle }, scale } = this.options
|
|
|
|
|
const { metrics, checkbox } = element
|
|
|
|
|
// left top 四舍五入避免1像素问题
|
|
|
|
|
const left = Math.round(x + gap)
|
|
|
|
|
const top = Math.round(y - metrics.height + lineWidth)
|
|
|
|
|
const width = metrics.width - gap * 2
|
|
|
|
|
const width = metrics.width - gap * 2 * scale
|
|
|
|
|
const height = metrics.height
|
|
|
|
|
ctx.save()
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
ctx.translate(0.5, 0.5)
|
|
|
|
|
ctx.lineWidth = lineWidth
|
|
|
|
|
ctx.rect(left, top, width, height)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
// 绘制勾选状态
|
|
|
|
|
if (checkbox?.value) {
|
|
|
|
|
ctx.moveTo(left + 2, top + 7)
|
|
|
|
|
ctx.lineTo(left + 6, top + 12)
|
|
|
|
|
ctx.lineTo(left + 12, top + 3)
|
|
|
|
|
// 边框
|
|
|
|
|
ctx.lineWidth = lineWidth
|
|
|
|
|
ctx.strokeStyle = fillStyle
|
|
|
|
|
ctx.rect(left, top, width, height)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
// 背景色
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
ctx.fillStyle = fillStyle
|
|
|
|
|
ctx.fillRect(left, top, width, height)
|
|
|
|
|
// 勾选对号
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
ctx.strokeStyle = fontStyle
|
|
|
|
|
ctx.lineWidth = lineWidth * 2
|
|
|
|
|
ctx.moveTo(left + 2 * scale, top + 7 * scale)
|
|
|
|
|
ctx.lineTo(left + 7 * scale, top + 11 * scale)
|
|
|
|
|
ctx.moveTo(left + 6.5 * scale, top + 11 * scale)
|
|
|
|
|
ctx.lineTo(left + 12 * scale, top + 3 * scale)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
} else {
|
|
|
|
|
ctx.lineWidth = lineWidth
|
|
|
|
|
ctx.rect(left, top, width, height)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
}
|
|
|
|
|
ctx.closePath()
|
|
|
|
|
|