I am currently trying to use Google Blockly (a visual code editor) in a project of mine. The example below shows a "block", with several inputs. What I am trying to do is, having a block add another input to itself based on the dropdown field selection. This works, but the input always breaks to a new line. I can set it inline, but I don't like the look of that. Do you have any idea how to achieve that?
Thanks in advance,
Chrisstar
Code:
Blockly.Blocks['page_settings'] = {
init: function() {
var PROPERTIES =
[["Nothing", "NONE"], ["Show Text Component", "SHOW_TEXT"], ["Show Item", "SHOW_ITEM"]];
this.setColour(65);
this.appendValueInput("TEXT")
.setCheck("String")
.appendField("Text");
this.appendValueInput("FORMAT")
.setCheck("mc_text_format")
.appendField("Format");
var dropdown = new Blockly.FieldDropdown(PROPERTIES, function(option) {
this.sourceBlock_.updateShape_(option);
});
this.appendDummyInput()
.appendField("Hover Event")
.appendField(dropdown, 'HOVER_EVENT_TYPE');
this.setInputsInline(false);
this.setOutput(true, 'Boolean');
this.setTooltip('Blockly.Msg.MATH_IS_TOOLTIP');
},
mutationToDom: function() {
var container = document.createElement('mutation');
var itemInput = this.getFieldValue('HOVER_EVENT_TYPE');
container.setAttribute('hover_type', itemInput);
return container;
},
domToMutation: function(xmlElement) {
var itemInput = xmlElement.getAttribute('hover_type');
this.updateShape_(itemInput);
},
updateShape_: function(input_type) {
// Add or remove a Value Input.
var inputExists = this.getInput('HOVER_INPUT');
if (input_type == 'SHOW_TEXT') {
if (!inputExists) {
this.appendValueInput('HOVER_INPUT')
.setCheck('mc_text_component');
}
}else if(input_type == 'SHOW_ITEM') {
if (!inputExists) {
this.appendValueInput('HOVER_INPUT')
.setCheck('mc_item');
}
}else if(inputExists) {
this.removeInput('HOVER_INPUT');
}
}
};