Ich versuche derzeit, Google Blockly (ein visueller Code-Editor) in einem meiner Projekte zu verwenden. Das folgende Beispiel zeigt einen "Block" mit mehreren Eingängen. Was ich versuche zu tun, ist, dass ein Block basierend auf der Dropdown-Feldauswahl eine weitere Eingabe zu sich selbst hinzufügt. Das funktioniert, aber die Eingabe bricht immer auf eine neue Zeile um. Ich kann es inline einstellen, aber das Aussehen mag ich nicht. Hast du eine Idee, wie du das erreichen kannst?Google Blockly update Eingabetyp
Vielen Dank im Voraus,
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');
}
}
};
Ich recherchierte und testete ein bisschen mehr und kam zu der Schlussfolgerung, dass aufgrund der Art, wie dieses Framework funktioniert, es nicht möglich ist, zu tun, was ich will (Sie könnten nativen Code ändern, aber das ist zu fortgeschritten für mich). Da ich es nicht mehr brauche, wird dies als geschlossen markiert. – Chrisstar