Regards
Vivek
Blockly.FieldColour.COLOURS = ['#f00','#0f0','#00f','#000','#888','#fff'];
Blockly.FieldColour.COLUMNS = 3;
For future reference, here's the docs. You can also use setcolors() to define it for a specific block type.
init: function() {
var limitedColourField = new Blockly.FieldColour('#00f');
limitedColourField.setColours(['#ff0000', '#00ff00', '#ffff00', '#0000ff', '#888888']).setColumns(3);
...
this.appendDummyInput().appendField(limitedColourField, 'COLOUR');
...
}
init: function () {
var limitedColourField = new Blockly.FieldColour('#00f');
limitedColourField.setColours(['#ff0000', '#00ff00', '#ffff00', '#0000ff', '#888888']).setColumns(3);
this.jsonInit({
...
"args0": [
{
"type": "field_colour", ??????????????????????????????????????????????????
"name": "COLOUR",
"colour": "#0000ff"
}
],
...
});
}
{
"type": "field_colour",
"name": "COLOUR",
"colour": "#0000ff",
"colours": ['#ff0000', '#00ff00', '#ffff00', '#0000ff', '#888888']
},
Thanks for the bad news :-)
Did meanwhile some further reading and found something interesting ( see https://github.com/google/blockly/blob/master/core/field_textinput.js ) :
Blockly.Field.register('field_input', Blockly.FieldTextInput);
Could I use that somehow to use my limitedColourField in the json, or do I have develop an entirely new color subclass?
Thanks!
Bart
Blockly.Blocks['node_status'] = {
init: function () {
this.jsonInit({
"type": "node_status",
"message0": Blockly.Msg.NODE_STATUS,
"args0": [
{
"type": "input_value",
"name": "TEXT_INPUT",
"check": "String"
},
{
"type": "input_dummy",
"name": "COLOUR_PLACEHOLDER",
},
{
"type": "field_dropdown",
"name": "SHAPE",
"options": [["ring", "RING" ],
["dot" , "DOT" ]]
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": "#BB8FCE",
"tooltip": Blockly.Msg.NODE_STATUS_TOOLTIP,
"helpUrl": null,
"extensions": ["limited_colorpicker_extension"]
});
}
}
Blockly.Extensions.register('limited_colorpicker_extension', function() {
//var input = this.inputList[0];
var placeholder = this.inputList[1];
// Set the allowed status colours (red, green, orange, blue, grey).
var colourField = new Blockly.FieldColour('#00f');
colourField.setColours(['#ff0000', '#00ff00', '#ffff00', '#0000ff', '#888888']).setColumns(3);
placeholder.appendField(colourField, 'COLOUR');
});
Blockly.JavaScript['node_status'] = function(block) {
var colour = block.getFieldValue('COLOUR');
....
}