mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Added setting a colour fields options through JSON. (#2655)
This commit is contained in:
@@ -63,7 +63,14 @@ goog.inherits(Blockly.FieldColour, Blockly.Field);
|
||||
* @nocollapse
|
||||
*/
|
||||
Blockly.FieldColour.fromJson = function(options) {
|
||||
return new Blockly.FieldColour(options['colour']);
|
||||
var field = new Blockly.FieldColour(options['colour']);
|
||||
if (options['colourOptions']) {
|
||||
field.setColours(options['colourOptions'], options['colourTitles']);
|
||||
}
|
||||
if (options['columns']) {
|
||||
field.setColumns(options['columns']);
|
||||
}
|
||||
return field;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -257,6 +257,26 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
|
||||
"tooltip": "",
|
||||
"helpUrl": ""
|
||||
},
|
||||
{
|
||||
"type": "test_fields_colour_options",
|
||||
"message0": "colour options %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_colour",
|
||||
"name": "COLOUR",
|
||||
"colour": "#ff4040",
|
||||
"colourOptions":
|
||||
['#ff4040', '#ff8080', '#ffc0c0',
|
||||
'#4040ff', '#8080ff', '#c0c0ff'],
|
||||
"colourTitles":
|
||||
['dark pink', 'pink', 'light pink',
|
||||
'dark blue', 'blue', 'light blue'],
|
||||
"columns": 3
|
||||
}
|
||||
],
|
||||
"style": "math_blocks",
|
||||
"tooltip": "test tooltip"
|
||||
},
|
||||
{
|
||||
"type": "test_fields_variable",
|
||||
"message0": "variable %1",
|
||||
|
||||
@@ -1305,6 +1305,7 @@ h1 {
|
||||
<block type="test_fields_date"></block>
|
||||
<block type="test_fields_checkbox"></block>
|
||||
<block type="test_fields_colour"></block>
|
||||
<block type="test_fields_colour_options"></block>
|
||||
<block type="test_fields_text_input"></block>
|
||||
<block type="test_fields_variable"></block>
|
||||
<button text="randomize label text" callbackKey="randomizeLabelText"></button>
|
||||
|
||||
Reference in New Issue
Block a user