Skip to content

Commit

Permalink
add text control, fix button control
Browse files Browse the repository at this point in the history
  • Loading branch information
eskim committed Apr 14, 2015
1 parent f2b808e commit effcc3e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
46 changes: 43 additions & 3 deletions rocon_composer_blockly/public/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,23 @@ Blockly.Blocks['ui_vertical'] = {
return this.setNextStatement(true);
},

};
Blockly.Blocks['ui_text'] = {

init: function() {
this.setColour(30);
this.appendDummyInput().appendField('Text' + name);

this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('TEXT').appendField('text:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);

},

};

Blockly.Blocks['ui_button'] = {
Expand All @@ -2098,8 +2115,10 @@ Blockly.Blocks['ui_button'] = {
this.setColour(30);
this.appendDummyInput().appendField('Button' + name);

this.appendValueInput('NAME').appendField('name : ');
this.appendValueInput('TEXT').appendField('text : ');
this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('TEXT').appendField('text:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);
Expand All @@ -2109,7 +2128,28 @@ Blockly.Blocks['ui_button'] = {

};
Blockly.JavaScript['ui_button'] = function(block){
return 'layout.push({type: "button"});';
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');

console.log(name);

var code = _.template('layout.push({type: "button", name: "<%= name %>", text: <%= text %>});')({
text: text,
name: name
});
return code;
};
Blockly.JavaScript['ui_text'] = function(block){
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');

console.log(name);

var code = _.template('layout.push({type: "text", name: "<%= name %>", text: <%= text %>});')({
text: text,
name: name
});
return code;
};


Expand Down
46 changes: 43 additions & 3 deletions rocon_composer_blockly/public/js/blocks/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ Blockly.Blocks['ui_vertical'] = {
return this.setNextStatement(true);
},

};
Blockly.Blocks['ui_text'] = {

init: function() {
this.setColour(30);
this.appendDummyInput().appendField('Text' + name);

this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('TEXT').appendField('text:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);

},

};

Blockly.Blocks['ui_button'] = {
Expand All @@ -55,8 +72,10 @@ Blockly.Blocks['ui_button'] = {
this.setColour(30);
this.appendDummyInput().appendField('Button' + name);

this.appendValueInput('NAME').appendField('name : ');
this.appendValueInput('TEXT').appendField('text : ');
this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('TEXT').appendField('text:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);
Expand All @@ -66,7 +85,28 @@ Blockly.Blocks['ui_button'] = {

};
Blockly.JavaScript['ui_button'] = function(block){
return 'layout.push({type: "button"});';
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');

console.log(name);

var code = _.template('layout.push({type: "button", name: "<%= name %>", text: <%= text %>});')({
text: text,
name: name
});
return code;
};
Blockly.JavaScript['ui_text'] = function(block){
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');

console.log(name);

var code = _.template('layout.push({type: "text", name: "<%= name %>", text: <%= text %>});')({
text: text,
name: name
});
return code;
};


Expand Down
6 changes: 4 additions & 2 deletions rocon_composer_blockly/public/js/tpl/blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ <h3>List</h3>
<block type="ui_create" />
<block type="ui_horizontal" />
<block type="ui_vertical" />
<block type="ui_button">
<value name="NAME">
<block type="ui_text">
<value name="TEXT">
<block type="text" />
</value>
</block>
<block type="ui_button">
<value name="TEXT">
<block type="text" />
</value>
Expand Down

0 comments on commit effcc3e

Please sign in to comment.