Icon on block to show comments

49 views
Skip to first unread message

Gurvan Jochum

unread,
Sep 11, 2024, 10:53:23 AM9/11/24
to Blockly

Hi everyone,

I'm reaching out again regarding my upgrade to Blockly 11.1. In version 8.2, I was able to dynamically set a custom icon to display comments in the editor using the following code:

Blockly.Comment.prototype.drawIcon_ = function(group) { var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); img.setAttribute("width", "20px"); img.setAttribute("height", "20px"); img.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "./media/user-comment.svg"); return group.appendChild(img); }

However, this approach no longer works in version 11.1. Is there an updated or similar way to implement this functionality in the newer version, or do I need to declare it for each block individually now?

Any advice or direction would be much appreciated!

Thanks in advance!

Aaron Dodson

unread,
Sep 12, 2024, 4:52:42 PM9/12/24
to Blockly
Hi,

It should now be possible to create a subclass of CommentIcon, override initView to perform essentially the same change you were doing before, then unregister the built-in class and register yours in its place. This doc describes icon registration, and the built-in CommentIcon class may also be a useful reference. Feel free to let me know if you get stuck!

- Aaron

Gurvan Jochum

unread,
Sep 16, 2024, 8:57:54 AM9/16/24
to Blockly

Thank you for your response. I just saw it now, but I managed to finish what I was working on last week.That's exactly what i did, I overrode initView, and everything is working perfectly!

Thanks again for your help, Gurvan.

Reply all
Reply to author
Forward
0 new messages