Adding buttons or double click to blockly blocks

293 views
Skip to first unread message

senal weerasekara

unread,
Mar 17, 2024, 6:37:39 PM3/17/24
to Blockly
Hi guys so i wanna add some sort of a button to my blockly blocks. so when i click on the button it should run some function.

for example when i click on the button it should run a function that will identify the block that im clicking the button from and display more information about the block and how to use it. 

Another example is when i click the button it should collapse the block. Right now i can do this by right clicking and clicking collapse but would be nice to use a button. OR rather than a button maybe i can double click on the block to do the same thing. collapse and expand.

Maribeth Moffatt

unread,
Mar 18, 2024, 1:38:23 PM3/18/24
to Blockly
Hello,

Both of these things are possible. For buttons, see the FieldImage documentation. You can add a click handler that will be called whenever the image is clicked, allowing your image to function as a button.

For double-clicking a block, you would use the Blockly event system. You can register an event listener that will respond to clicks on blocks. For double-click specifically, there is not a built-in event, but you can add custom logic to a click event that checks for double clicks. Others have done this in the past so you can find information in the forum; see this post for example.

I hope that gives you a good starting point. If you have follow-up questions please post them here and we'll be happy to help!

Best,
Maribeth

Reply all
Reply to author
Forward
0 new messages