From 138a1e717f1a5a6ac6a964c197b747588f3cac43 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Fri, 23 Aug 2024 20:11:11 +1200 Subject: [PATCH] Fix links being unclickable in canvas renderer --- examples/clay-official-website/index.html | 5 +++++ renderers/web/canvas2d/clay-canvas2d-renderer.html | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/examples/clay-official-website/index.html b/examples/clay-official-website/index.html index 7e75f17..b53f19f 100644 --- a/examples/clay-official-website/index.html +++ b/examples/clay-official-website/index.html @@ -514,6 +514,11 @@ [config.cornerRadius.topLeft.value * scale, config.cornerRadius.topRight.value * scale, config.cornerRadius.bottomRight.value * scale, config.cornerRadius.bottomLeft.value * scale]) // height; ctx.fill(); ctx.closePath(); + // Handle link clicks + let linkContents = config.link.length.value > 0 ? textDecoder.decode(new Uint8Array(memoryDataView.buffer.slice(config.link.chars.value, config.link.chars.value + config.link.length.value))) : 0; + if (linkContents.length > 0 && (window.mouseDown || window.touchDown) && instance.exports.Clay_PointerOver(renderCommand.id.value)) { + window.location.href = linkContents; + } break; } case (CLAY_RENDER_COMMAND_TYPE_BORDER): { diff --git a/renderers/web/canvas2d/clay-canvas2d-renderer.html b/renderers/web/canvas2d/clay-canvas2d-renderer.html index ce895f6..5a791a8 100644 --- a/renderers/web/canvas2d/clay-canvas2d-renderer.html +++ b/renderers/web/canvas2d/clay-canvas2d-renderer.html @@ -324,6 +324,11 @@ [config.cornerRadius.topLeft.value * scale, config.cornerRadius.topRight.value * scale, config.cornerRadius.bottomRight.value * scale, config.cornerRadius.bottomLeft.value * scale]) // height; ctx.fill(); ctx.closePath(); + // Handle link clicks + let linkContents = config.link.length.value > 0 ? textDecoder.decode(new Uint8Array(memoryDataView.buffer.slice(config.link.chars.value, config.link.chars.value + config.link.length.value))) : 0; + if (linkContents.length > 0 && (window.mouseDown || window.touchDown) && instance.exports.Clay_PointerOver(renderCommand.id.value)) { + window.location.href = linkContents; + } break; } case (CLAY_RENDER_COMMAND_TYPE_BORDER): {