()
| 3679 | } |
| 3680 | |
| 3681 | function renderElements() { |
| 3682 | const scale = parseFloat(preview.dataset.scale || "1"); |
| 3683 | preview.innerHTML = ""; |
| 3684 | preview.style.position = "relative"; |
| 3685 | |
| 3686 | const isOLED = driverMode === "u8g2"; |
| 3687 | |
| 3688 | // Resolve asset references (assetId) into element preview/code fields. |
| 3689 | // This keeps old projects working while enabling the Assets Manager. |
| 3690 | const assetById = new Map((assets || []).filter(Boolean).map((a) => [a.id, a])); |
| 3691 | elements.forEach((el) => { |
| 3692 | if (!el || !el.assetId) return; |
| 3693 | const a = assetById.get(el.assetId); |
| 3694 | if (!a) return; |
| 3695 | if (el.type === "image") { |
| 3696 | if (a.dataUrl) el.previewUrl = a.dataUrl; |
| 3697 | if (a.rgb565) el.rgb565 = a.rgb565; |
| 3698 | if (a.width && a.height) { |
| 3699 | el.imageWidth = a.width; |
| 3700 | el.imageHeight = a.height; |
| 3701 | } |
| 3702 | } else if (el.type === "icon") { |
| 3703 | if (a.dataUrl) el.iconSrc = a.dataUrl; |
| 3704 | if (a.rgb565) el.rgb565 = a.rgb565; |
| 3705 | if (a.monoBitmap) el.monoBitmap = a.monoBitmap; |
| 3706 | if (a.width && a.height) { |
| 3707 | el.imageWidth = a.width; |
| 3708 | el.imageHeight = a.height; |
| 3709 | } |
| 3710 | } |
| 3711 | }); |
| 3712 | |
| 3713 | // OLED mode: draw everything into a 1:1 canvas and scale it up pixelated. |
| 3714 | let oledCanvasOk = false; |
| 3715 | if (isOLED) { |
| 3716 | const canvas = document.createElement("canvas"); |
| 3717 | canvas.id = "oledCanvas"; |
| 3718 | canvas.width = dispWidth; |
| 3719 | canvas.height = dispHeight; |
| 3720 | canvas.style.position = "absolute"; |
| 3721 | canvas.style.left = "0"; |
| 3722 | canvas.style.top = "0"; |
| 3723 | canvas.style.width = dispWidth * scale + "px"; |
| 3724 | canvas.style.height = dispHeight * scale + "px"; |
| 3725 | canvas.style.pointerEvents = "none"; |
| 3726 | // Keep the OLED canvas above the background and below interaction overlays/icons |
| 3727 | canvas.style.zIndex = "4"; |
| 3728 | canvas.style.imageRendering = "pixelated"; |
| 3729 | canvas.style.imageRendering = "-moz-crisp-edges"; |
| 3730 | canvas.style.imageRendering = "crisp-edges"; |
| 3731 | preview.appendChild(canvas); |
| 3732 | |
| 3733 | const ctx = canvas.getContext("2d", { willReadFrequently: true }); |
| 3734 | if (ctx) { |
| 3735 | try { |
| 3736 | ctx.imageSmoothingEnabled = false; |
| 3737 | ctx.clearRect(0, 0, dispWidth, dispHeight); |
| 3738 |
no test coverage detected