Enhance text wrapping in drawCard function to support multi-line input
This commit is contained in:
parent
41505776af
commit
eff962608f
1 changed files with 17 additions and 13 deletions
|
@ -137,7 +137,9 @@ async function drawCardId() {
|
||||||
|
|
||||||
|
|
||||||
function wrapText(text, x, y, maxWidth, lineHeight) {
|
function wrapText(text, x, y, maxWidth, lineHeight) {
|
||||||
const words = text.split(" ");
|
const lines = text.split('\n');
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
let words = lines[i].split(" ");
|
||||||
let line = "";
|
let line = "";
|
||||||
for (let n = 0; n < words.length; n++) {
|
for (let n = 0; n < words.length; n++) {
|
||||||
const testLine = line + words[n] + " ";
|
const testLine = line + words[n] + " ";
|
||||||
|
@ -152,6 +154,8 @@ function wrapText(text, x, y, maxWidth, lineHeight) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.fillText(line, x, y);
|
ctx.fillText(line, x, y);
|
||||||
|
y += lineHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update card live when inputs change
|
// Update card live when inputs change
|
||||||
|
|
Loading…
Add table
Reference in a new issue