Skip to content

Commit 0e80277

Browse files
authored
fix: fix styling of dropdown menus (#152)
* chore: remove block definitions monkeypatched by scratch-gui * refactor: use block styles instead of colors to color blocks * fix: fix highlighting of dropdown fields in shadow blocks * fix: prevent white hover highlight on non-shadow dropdown fields * fix: make selected dropdown color changes more robust * chore: remove duplicative sound colors * refactor: move block colors into a custom theme * chore: condense placeholder block definitions
1 parent 8e165ce commit 0e80277

17 files changed

+213
-439
lines changed

src/blocks/control.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import * as Blockly from "blockly/core";
2222
import { Categories } from "../categories.js";
23-
import { Colours } from "../colours.js";
2423

2524
Blockly.Blocks["control_forever"] = {
2625
/**
@@ -198,12 +197,7 @@ Blockly.Blocks["control_stop"] = {
198197
this.appendDummyInput()
199198
.appendField(Blockly.Msg.CONTROL_STOP)
200199
.appendField(stopDropdown, "STOP_OPTION");
201-
this.setColour(
202-
Colours.control.primary,
203-
Colours.control.secondary,
204-
Colours.control.tertiary,
205-
Colours.control.quaternary
206-
);
200+
this.setStyle("colours_control");
207201
this.setPreviousStatement(true);
208202
},
209203
};
@@ -381,25 +375,10 @@ Blockly.Blocks["control_start_as_clone"] = {
381375
},
382376
};
383377

384-
Blockly.Blocks["control_create_clone_of_menu"] = {
385-
/**
386-
* Create-clone drop-down menu.
387-
* @this Blockly.Block
388-
*/
389-
init: function () {
390-
this.jsonInit({
391-
message0: "%1",
392-
args0: [
393-
{
394-
type: "field_dropdown",
395-
name: "CLONE_OPTION",
396-
options: [[Blockly.Msg.CONTROL_CREATECLONEOF_MYSELF, "_myself_"]],
397-
},
398-
],
399-
extensions: ["colours_control", "output_string"],
400-
});
401-
},
402-
};
378+
/**
379+
* Create-clone drop-down menu. Populated dynamically by scratch-gui.
380+
*/
381+
Blockly.Blocks["control_create_clone_of_menu"] = {};
403382

404383
Blockly.Blocks["control_create_clone_of"] = {
405384
/**

src/blocks/event.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,11 @@ Blockly.Blocks["event_whenbroadcastreceived"] = {
142142
},
143143
};
144144

145-
Blockly.Blocks["event_whenbackdropswitchesto"] = {
146-
/**
147-
* Block for when the current backdrop switched to a selected backdrop.
148-
* @this Blockly.Block
149-
*/
150-
init: function () {
151-
this.jsonInit({
152-
message0: Blockly.Msg.EVENT_WHENBACKDROPSWITCHESTO,
153-
args0: [
154-
{
155-
type: "field_dropdown",
156-
name: "BACKDROP",
157-
options: [["backdrop1", "BACKDROP1"]],
158-
},
159-
],
160-
category: Categories.event,
161-
extensions: ["colours_event", "shape_hat"],
162-
});
163-
},
164-
};
145+
/**
146+
* Block for when the current backdrop switched to a selected backdrop.
147+
* Populated dynamically by scratch-gui.
148+
*/
149+
Blockly.Blocks["event_whenbackdropswitchesto"] = {};
165150

166151
Blockly.Blocks["event_whengreaterthan"] = {
167152
/**

src/blocks/looks.js

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -339,28 +339,10 @@ Blockly.Blocks["looks_setstretchto"] = {
339339
},
340340
};
341341

342-
Blockly.Blocks["looks_costume"] = {
343-
/**
344-
* Costumes drop-down menu.
345-
* @this Blockly.Block
346-
*/
347-
init: function () {
348-
this.jsonInit({
349-
message0: "%1",
350-
args0: [
351-
{
352-
type: "field_dropdown",
353-
name: "COSTUME",
354-
options: [
355-
["costume1", "COSTUME1"],
356-
["costume2", "COSTUME2"],
357-
],
358-
},
359-
],
360-
extensions: ["colours_looks", "output_string"],
361-
});
362-
},
363-
};
342+
/**
343+
* Costumes drop-down menu. Populated dynamically by scratch-gui.
344+
*/
345+
Blockly.Blocks["looks_costume"] = {};
364346

365347
Blockly.Blocks["looks_switchcostumeto"] = {
366348
/**
@@ -416,26 +398,10 @@ Blockly.Blocks["looks_switchbackdropto"] = {
416398
},
417399
};
418400

419-
Blockly.Blocks["looks_backdrops"] = {
420-
/**
421-
* Backdrop list
422-
* @this Blockly.Block
423-
*/
424-
init: function () {
425-
this.jsonInit({
426-
id: "looks_backdrops",
427-
message0: "%1",
428-
args0: [
429-
{
430-
type: "field_dropdown",
431-
name: "BACKDROP",
432-
options: [["backdrop1", "BACKDROP1"]],
433-
},
434-
],
435-
extensions: ["colours_looks", "output_string"],
436-
});
437-
},
438-
};
401+
/**
402+
* Backdrop list. Populated dynamically by scratch-gui.
403+
*/
404+
Blockly.Blocks["looks_backdrops"] = {};
439405

440406
Blockly.Blocks["looks_gotofrontback"] = {
441407
/**

src/blocks/math.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* @author [email protected] (Quynh Neutron)
2424
*/
2525
import * as Blockly from "blockly/core";
26-
import { Colours } from "../colours.js";
2726
import * as Constants from "../constants.js";
2827

2928
Blockly.Blocks["math_number"] = {
@@ -43,10 +42,7 @@ Blockly.Blocks["math_number"] = {
4342
],
4443
output: "Number",
4544
outputShape: Constants.OUTPUT_SHAPE_ROUND,
46-
colour: Colours.textField,
47-
colourSecondary: Colours.textField,
48-
colourTertiary: Colours.textField,
49-
colourQuaternary: Colours.textField,
45+
extensions: ["colours_textfield"],
5046
});
5147
},
5248
};
@@ -68,10 +64,7 @@ Blockly.Blocks["math_integer"] = {
6864
],
6965
output: "Number",
7066
outputShape: Constants.OUTPUT_SHAPE_ROUND,
71-
colour: Colours.textField,
72-
colourSecondary: Colours.textField,
73-
colourTertiary: Colours.textField,
74-
colourQuaternary: Colours.textField,
67+
extensions: ["colours_textfield"],
7568
});
7669
},
7770
};
@@ -94,10 +87,7 @@ Blockly.Blocks["math_whole_number"] = {
9487
],
9588
output: "Number",
9689
outputShape: Constants.OUTPUT_SHAPE_ROUND,
97-
colour: Colours.textField,
98-
colourSecondary: Colours.textField,
99-
colourTertiary: Colours.textField,
100-
colourQuaternary: Colours.textField,
90+
extensions: ["colours_textfield"],
10191
});
10292
},
10393
};
@@ -119,10 +109,7 @@ Blockly.Blocks["math_positive_number"] = {
119109
],
120110
output: "Number",
121111
outputShape: Constants.OUTPUT_SHAPE_ROUND,
122-
colour: Colours.textField,
123-
colourSecondary: Colours.textField,
124-
colourTertiary: Colours.textField,
125-
colourQuaternary: Colours.textField,
112+
extensions: ["colours_textfield"],
126113
});
127114
},
128115
};
@@ -144,10 +131,7 @@ Blockly.Blocks["math_angle"] = {
144131
],
145132
output: "Number",
146133
outputShape: Constants.OUTPUT_SHAPE_ROUND,
147-
colour: Colours.textField,
148-
colourSecondary: Colours.textField,
149-
colourTertiary: Colours.textField,
150-
colourQuaternary: Colours.textField,
134+
extensions: ["colours_textfield"],
151135
});
152136
},
153137
};

src/blocks/motion.js

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,10 @@ Blockly.Blocks["motion_pointindirection"] = {
115115
},
116116
};
117117

118-
Blockly.Blocks["motion_pointtowards_menu"] = {
119-
/**
120-
* Point towards drop-down menu.
121-
* @this Blockly.Block
122-
*/
123-
init: function () {
124-
this.jsonInit({
125-
message0: "%1",
126-
args0: [
127-
{
128-
type: "field_dropdown",
129-
name: "TOWARDS",
130-
options: [
131-
[Blockly.Msg.MOTION_POINTTOWARDS_POINTER, "_mouse_"],
132-
[Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, "_random_"],
133-
],
134-
},
135-
],
136-
extensions: ["colours_motion", "output_string"],
137-
});
138-
},
139-
};
118+
/**
119+
* Point towards drop-down menu. Populated dynamically by scratch-gui.
120+
*/
121+
Blockly.Blocks["motion_pointtowards_menu"] = {};
140122

141123
Blockly.Blocks["motion_pointtowards"] = {
142124
/**
@@ -158,28 +140,10 @@ Blockly.Blocks["motion_pointtowards"] = {
158140
},
159141
};
160142

161-
Blockly.Blocks["motion_goto_menu"] = {
162-
/**
163-
* Go to drop-down menu.
164-
* @this Blockly.Block
165-
*/
166-
init: function () {
167-
this.jsonInit({
168-
message0: "%1",
169-
args0: [
170-
{
171-
type: "field_dropdown",
172-
name: "TO",
173-
options: [
174-
[Blockly.Msg.MOTION_GOTO_POINTER, "_mouse_"],
175-
[Blockly.Msg.MOTION_GOTO_RANDOM, "_random_"],
176-
],
177-
},
178-
],
179-
extensions: ["colours_motion", "output_string"],
180-
});
181-
},
182-
};
143+
/**
144+
* Go to drop-down menu. Populated dynamically by scratch-gui.
145+
*/
146+
Blockly.Blocks["motion_goto_menu"] = {};
183147

184148
Blockly.Blocks["motion_gotoxy"] = {
185149
/**
@@ -253,28 +217,10 @@ Blockly.Blocks["motion_glidesecstoxy"] = {
253217
},
254218
};
255219

256-
Blockly.Blocks["motion_glideto_menu"] = {
257-
/**
258-
* Glide to drop-down menu
259-
* @this Blockly.Block
260-
*/
261-
init: function () {
262-
this.jsonInit({
263-
message0: "%1",
264-
args0: [
265-
{
266-
type: "field_dropdown",
267-
name: "TO",
268-
options: [
269-
[Blockly.Msg.MOTION_GLIDETO_POINTER, "_mouse_"],
270-
[Blockly.Msg.MOTION_GLIDETO_RANDOM, "_random_"],
271-
],
272-
},
273-
],
274-
extensions: ["colours_motion", "output_string"],
275-
});
276-
},
277-
};
220+
/**
221+
* Glide to drop-down menu. Populated dynamically by scratch-gui.
222+
*/
223+
Blockly.Blocks["motion_glideto_menu"] = {};
278224

279225
Blockly.Blocks["motion_glideto"] = {
280226
/**

src/blocks/note.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* @author [email protected] (Eric Rosenbaum)
2424
*/
2525
import * as Blockly from "blockly/core";
26-
import { Colours } from "../colours.js";
2726
import * as Constants from "../constants.js";
2827

2928
Blockly.Blocks["note"] = {
@@ -43,10 +42,7 @@ Blockly.Blocks["note"] = {
4342
],
4443
outputShape: Constants.OUTPUT_SHAPE_ROUND,
4544
output: "Number",
46-
colour: Colours.textField,
47-
colourSecondary: Colours.textField,
48-
colourTertiary: Colours.textField,
49-
colourQuaternary: Colours.textField,
45+
extensions: ["colours_textfield"],
5046
});
5147
},
5248
};

src/blocks/procedures.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
import * as Blockly from "blockly/core";
26-
import { Colours } from "../colours.js";
2726
import { FieldTextInputRemovable } from "../fields/field_textinput_removable.js";
2827

2928
class DuplicateOnDragDraggable {
@@ -984,11 +983,7 @@ Blockly.Blocks["argument_editor_boolean"] = {
984983
text: "foo",
985984
},
986985
],
987-
colour: Colours.textField,
988-
colourSecondary: Colours.textField,
989-
colourTertiary: Colours.textField,
990-
colourQuaternary: Colours.textField,
991-
extensions: ["output_boolean"],
986+
extensions: ["colours_textfield", "output_boolean"],
992987
});
993988

994989
// Exist on declaration and arguments editors, with different implementations.
@@ -1007,11 +1002,7 @@ Blockly.Blocks["argument_editor_string_number"] = {
10071002
text: "foo",
10081003
},
10091004
],
1010-
colour: Colours.textField,
1011-
colourSecondary: Colours.textField,
1012-
colourTertiary: Colours.textField,
1013-
colourQuaternary: Colours.textField,
1014-
extensions: ["output_number", "output_string"],
1005+
extensions: ["colours_textfield", "output_number", "output_string"],
10151006
});
10161007

10171008
// Exist on declaration and arguments editors, with different implementations.

0 commit comments

Comments
 (0)