How to resize the block?

142 views
Skip to first unread message

fu6...@gmail.com

unread,
Aug 29, 2021, 1:07:14 AM8/29/21
to Blockly
Hi,
I want to change the field text of the block  , but the width of the block doesn't resize according to the text width after connecting to the parent block.
Thank you very much. 



Blockly.Blocks.lists_create_with={
init:function(){
this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);
this.setStyle("list_blocks");
this.itemCount_=3;
this.updateShape_();
this.setOutput(!0,"Array");
this.setMutator(new Blockly.Mutator(["lists_create_with_item"]));
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP)
}
        //etc...
,onchange: function(event) {
if (!this.workspace || this.workspace.isFlyout) {
  return;
}
if (!event.recordUndo) {
  return;
}
if (this.mutator.block_.parentBlock_) {
if (this.mutator.block_.parentBlock_.type=="procedures_callnoreturn"||this.mutator.block_.parentBlock_.type=="procedures_callreturn") {
this.getField("TITLE").fieldGroup_.childNodes[0].innerHTML=Blockly.Msg["LISTS_CREATE_WITH_INPUT_WITH_PROCEDURE_VALUE"];
this.getField("TITLE").isDirty_=true;
return;
}
}
if (this.itemCount_)
this.getField("TITLE").fieldGroup_.childNodes[0].innerHTML=Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH;
else
this.getField("TITLE").fieldGroup_.childNodes[0].innerHTML=Blockly.Msg.LISTS_CREATE_EMPTY_TITLE;
this.getField("TITLE").isDirty_=true;
};



2.png
錄製_2021_08_29_12_46_01_706.mp4

Maribeth Bottorff

unread,
Aug 31, 2021, 8:12:42 PM8/31/21
to Blockly
Hello, can you try using `field.setValue('your value here');` ?

In general, you probably shouldn't have to mess with the innerHTML or the inner structure of any of the fields/pieces of Blockly, or access private properties (the underscore on fieldGroup_ means it's private). Instead, you should see if there is API support for what you're trying to do. Our API documentation is found on our developer site here. Hope that helps,

Maribeth

fu6...@gmail.com

unread,
Aug 31, 2021, 10:33:17 PM8/31/21
to Blockly
It works well. Thank you.

Maribeth Bottorff 在 2021年9月1日 星期三上午8:12:42 [UTC+8] 的信中寫道:
1.mp4
Reply all
Reply to author
Forward
0 new messages