Skip to content

Commit b383382

Browse files
authored
Add a complicated block with buttons (#558)
* Add a button block for testing * Move buttons block to misc category * fix formatting
1 parent 9809ff2 commit b383382

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

test/blocks/p5_blocks.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,74 @@ const p5Canvas = {
8888
},
8989
};
9090

91+
const buttonsJson = {
92+
'type': 'buttons',
93+
'message0': 'If %1 %2 Then %3 %4 more %5 %6 %7',
94+
'args0': [
95+
{
96+
'type': 'field_image',
97+
'name': 'BUTTON1',
98+
'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif',
99+
'width': 30,
100+
'height': 30,
101+
'alt': '*',
102+
},
103+
{
104+
'type': 'input_value',
105+
'name': 'VALUE1',
106+
'check': '',
107+
},
108+
{
109+
'type': 'field_image',
110+
'name': 'BUTTON2',
111+
'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif',
112+
'width': 30,
113+
'height': 30,
114+
'alt': '*',
115+
},
116+
{
117+
'type': 'input_dummy',
118+
'name': 'DUMMY1',
119+
'check': '',
120+
},
121+
{
122+
'type': 'input_value',
123+
'name': 'VALUE2',
124+
'check': '',
125+
},
126+
{
127+
'type': 'input_statement',
128+
'name': 'STATEMENT1',
129+
'check': 'Number',
130+
},
131+
{
132+
'type': 'field_image',
133+
'name': 'BUTTON3',
134+
'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif',
135+
'width': 30,
136+
'height': 30,
137+
'alt': '*',
138+
},
139+
],
140+
'previousStatement': null,
141+
'nextStatement': null,
142+
'colour': 230,
143+
'tooltip': '',
144+
'helpUrl': '',
145+
};
146+
147+
const buttonsBlock = {
148+
init: function () {
149+
this.jsonInit(buttonsJson);
150+
const clickHandler = function () {
151+
console.log('clicking a button!');
152+
};
153+
this.getField('BUTTON1').setOnClickHandler(clickHandler);
154+
this.getField('BUTTON2').setOnClickHandler(clickHandler);
155+
this.getField('BUTTON3').setOnClickHandler(clickHandler);
156+
},
157+
};
158+
91159
const background = {
92160
'type': 'p5_background_color',
93161
'message0': 'Set background color to %1',
@@ -285,5 +353,6 @@ export const blocks = {
285353
'p5_setup': p5Setup,
286354
'p5_draw': p5Draw,
287355
'p5_canvas': p5Canvas,
356+
'buttons_block': buttonsBlock,
288357
...jsonBlocks,
289358
};

test/toolboxCategories.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ export default {
825825
kind: 'block',
826826
type: 'colour_random',
827827
},
828+
{
829+
kind: 'block',
830+
type: 'buttons_block',
831+
},
828832
],
829833
},
830834
],

0 commit comments

Comments
 (0)