feat(canvas-v3): P2 out 结果缩略图 Canvas 化
This commit is contained in:
1 parent
db50733876
commit
2d0abb1b79
9 files changed
+61
-10
No files matched your search
@@ -65,6 +65,7 @@
|
||||
const widthOf = typeof o.widthOf === 'function' ? o.widthOf : (n) => n.w || 240
|
||||
const heightOf = typeof o.heightOf === 'function' ? o.heightOf : (n) => n.h || 220
|
||||
const imageFor = typeof o.imageFor === 'function' ? o.imageFor : () => ''
|
||||
const outThumbsFor = typeof o.outThumbsFor === 'function' ? o.outThumbsFor : () => []
|
||||
const onImageLoad = o.onImageLoad
|
||||
const types = Array.isArray(o.types) && o.types.length ? o.types : ['ref']
|
||||
const bg = css('--iwb-panel', '#ffffff')
|
||||
@@ -114,6 +115,29 @@
|
||||
ctx.font = Math.max(10, 12 / scale * 0.9) + 'px -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif'
|
||||
ctx.fillText(entry && entry.failed ? '图片源失效' : '图片加载中…', ix + 12, iy + 24)
|
||||
}
|
||||
} else if (n.type === 'out') {
|
||||
// 输出节点:画结果缩略图网格;没有结果时提示选中查看。
|
||||
const urls = outThumbsFor(n) || []
|
||||
if (urls.length) {
|
||||
const cols = 2
|
||||
const gap = 4
|
||||
const cw = Math.max(1, (iw - gap) / cols)
|
||||
const ch = cw * 0.75
|
||||
for (let i = 0; i < Math.min(4, urls.length); i++) {
|
||||
const col = i % cols, row = Math.floor(i / cols)
|
||||
const x0 = ix + col * (cw + gap), y0 = iy + row * (ch + gap)
|
||||
const entry = imageOf(imageFor(n, urls[i]), onImageLoad)
|
||||
ctx.fillStyle = css('--iwb-layer2', '#f1f2f4')
|
||||
roundRect(ctx, x0, y0, cw, ch, 6); ctx.fill()
|
||||
if (entry && entry.loaded && !entry.failed) {
|
||||
try { ctx.drawImage(entry.img, x0, y0, cw, ch) } catch (e) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.fillStyle = text
|
||||
ctx.font = Math.max(10, 12 / scale * 0.9) + 'px -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif'
|
||||
ctx.fillText('选中查看结果', ix + 2, iy + Math.max(14, 16 / scale))
|
||||
}
|
||||
} else {
|
||||
// P2 文本节点:画截断文本,选中后由 NodeCard 负责编辑。
|
||||
ctx.save()
|
||||
|
||||
Reference in new issue
Block a user