How to customize block connection shape.

139 views
Skip to first unread message

Paing Htet Aung

unread,
May 2, 2022, 4:40:42 AM5/2/22
to Blockly
 I want to customize the connection shape of blocks based on individual block types. This is what I want => https://studio.code.org/s/coursee-2021/lessons/6/levels/4
Example Photo
Screenshot from 2022-05-02 15-05-40.png

Beka Westberg

unread,
May 2, 2022, 11:29:25 AM5/2/22
to Blockly
Hello!

Have you checked out the custom renderers codelab? It walks you through how to customize connection shapes =)

I hope that helps! If you have any further questions please reply!
--Beka

Paing Htet Aung

unread,
May 3, 2022, 12:21:08 AM5/3/22
to Blockly
thanks for your reply I've already checked that before. But all I need to do is like, to customize each block, not for whole blocks in the toolbox.Is there any way to do that.

Beka Westberg

unread,
May 3, 2022, 5:15:20 PM5/3/22
to blo...@googlegroups.com
I believe so! On page five under the "Override shapeFor" section it references the shapeFor function:

```
CustomConstantsProvider.prototype.shapeFor = function(
    connection) {
  switch (connection.type) {
    case Blockly.INPUT_VALUE:
    case Blockly.OUTPUT_VALUE:
      return this.RECT_INPUT_OUTPUT;
    case Blockly.PREVIOUS_STATEMENT:
    case Blockly.NEXT_STATEMENT:
      return this.RECT_PREV_NEXT;
    default:
      throw Error('Unknown connection type');
  }
};
```

This function takes in a connection, and returns a shape based on that. If you want, this function could look at the block the connection is associated with, before returning a shape based on that block.

To access the block you would do connection.getSourceBlock();

I hope that helps! If you have any further questions please reply!
--Beka
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/41291c6c-f78e-4e16-8ec4-914bf2bc0568n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages