Transform a matrix blocks of fields into a matrix block of input

96 views
Skip to first unread message

Jean

unread,
Sep 16, 2021, 5:21:42 AM9/16/21
to Blockly
Dear Blockly community,

I have a block that create a matrix of éléments from fields, and today i want to modify it so it has input instead of fields so i can put any types of block.

block.PNG

So this is the code of the matrix when i add a column:

addColumnFields: function() {
    for (var j = 0; j < this.dimY; j++) {
      this.line[j].appendField(new Blockly.Field(), "element_" + j +"_"+ this.dimX);
    }
},

I also tried to change it into input but it didn't succeed:

addColumnFields: function() {
    for (var j = 0; j < this.dimY; j++) {
      this.line[j] = this.appendValueInput("element_" + j +"_"+ i);
    }
},

Do you think it's possible ?

Any help at all would be greatly appreciated.

Thank you.

Abby Schmiedt

unread,
Sep 17, 2021, 12:57:23 PM9/17/21
to Blockly
Hello!

The problem is that we have inline and external inputs. External inputs stack inputs vertically and inline line up inputs horizontally. We don't really offer a way to do both. I don't think our current renderer can handle this situation. You can look at creating a custom renderer.There is also a plugin that allows you to add/remove inputs using a +/- button on the block. I know it isn't exactly what you are looking for, but might get you halfway there. 


Hope this helps!
Abby

Jean

unread,
Sep 23, 2021, 4:28:15 AM9/23/21
to Blockly
Hello,

Thanks to your suggestion, i found a way to make the block that i wanted. I made a block that add an input vertically (lines) where i put another block that can add an input horizontally (columns).

table matrix.PNG
Right now my code only add value input and i have to add those columns blocks manually, do you think i can append a block to directly in the code:

My code:

addPart_: function() {
    if (this.itemCount_ == 0) {
      this.removeInput('EMPTY');
      this.topInput_ = this.appendDummyInput('LINE_' + this.itemCount_)
          .appendField(createPlusField(), 'PLUS')
          .appendField(Blockly.Msg['TABLE_MATRIX_TITLE']);
    } else {
      this.appendValueInput('LINE_' + this.itemCount_).setAlign(Blockly.ALIGN_RIGHT);
    }
    this.itemCount_++;
  },

What i want:

addPart_: function() {
    if (this.itemCount_ == 0) {
      this.removeInput('EMPTY');
      this.topInput_ = this.appendDummyInput('LINE_' + this.itemCount_)
          .appendField(createPlusField(), 'PLUS')
          .appendField(Blockly.Msg['TABLE_MATRIX_TITLE']);
    } else {
      this.appendValueInput('LINE_' + this.itemCount_).setAlign(Blockly.ALIGN_RIGHT).append(new Block column...);
    }
    this.itemCount_++;
  },

Do you think it's possible ?

Any help at all would be greatly appreciated.

Thank you.

Abby Schmiedt

unread,
Sep 30, 2021, 5:26:28 PM9/30/21
to Blockly
Hello!

Sorry for the late reply! You should be able to do something like below: 

const input = this.appendValueInput('LINE_' + this.itemCount_)
const newBlock = new Block column...
input.connection.connect(newBlock.outputConnection)

Hope this helps and let me know if you have any other questions!
Abby

Reply all
Reply to author
Forward
0 new messages