Skip to content

Commit 88c700e

Browse files
authored
fix: fix the color of procedure argument blocks (#216)
1 parent 1279c0a commit 88c700e

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/renderer/path_object.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as Blockly from "blockly/core";
8+
9+
/**
10+
* An object that handles creating and setting each of the SVG elements
11+
* used by the renderer.
12+
*/
13+
export class PathObject extends Blockly.zelos.PathObject {
14+
/**
15+
* Apply the stored colours to the block's path, taking into account whether
16+
* the paths belong to a shadow block.
17+
*
18+
* @param {!Blockly.BlockSvg} block The source block.
19+
*/
20+
applyColour(block) {
21+
super.applyColour(block);
22+
23+
// These blocks are special in that, while they are technically shadow
24+
// blocks when contained in a procedure definition/prototype, their parent
25+
// (the sample procedure caller block embedded in the definition block) is
26+
// also a shadow, so they need to use normal block colors in order to
27+
// provide contrast with it.
28+
if (
29+
block.type === "argument_reporter_string_number" ||
30+
block.type === "argument_reporter_boolean"
31+
) {
32+
this.svgPath.setAttribute("fill", this.style.colourPrimary);
33+
}
34+
}
35+
}

src/renderer/renderer.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,61 @@ import * as Blockly from "blockly/core";
88
import { Drawer } from "./drawer.js";
99
import { RenderInfo } from "./render_info.js";
1010
import { ConstantProvider } from "./constants.js";
11+
import { PathObject } from "./path_object.js";
1112

13+
/**
14+
* Custom renderer for Scratch-style blocks.
15+
*/
1216
export class ScratchRenderer extends Blockly.zelos.Renderer {
17+
/**
18+
* Create a new instance of the renderer's drawer.
19+
*
20+
* @param {!Blockly.BlockSvg} block The block to render.
21+
* @param info {!Blockly.blockRendering.RenderInfo} An object containing all
22+
* information needed to render this block.
23+
* @returns {!Drawer} The drawer.
24+
*/
1325
makeDrawer_(block, info) {
1426
return new Drawer(block, info);
1527
}
1628

29+
/**
30+
* Create a new instance of the renderer's render info object.
31+
*
32+
* @param {!Blockly.BlockSvg} block The block to measure.
33+
* @returns {!RenderInfo} The render info object.
34+
*/
1735
makeRenderInfo_(block) {
1836
return new RenderInfo(this, block);
1937
}
2038

39+
/**
40+
* Create a new instance of the renderer's constant provider.
41+
*
42+
* @returns {!ConstantProvider} The constant provider.
43+
*/
2144
makeConstants_() {
2245
return new ConstantProvider();
2346
}
2447

48+
/**
49+
* Create a new instance of a renderer path object.
50+
*
51+
* @param {!SVGElement} root The root SVG element.
52+
* @param {!Blockly.BlockStyle} style The style object to use for colouring.
53+
* @returns {!PathObject} The renderer path object.
54+
*/
55+
makePathObject(root, style) {
56+
return new PathObject(root, style, this.getConstants());
57+
}
58+
59+
/**
60+
* Determine whether or not to highlight a connection.
61+
*
62+
* @param {!Blockly.RenderedConnection} connection The connection to determine
63+
* whether or not to highlight.
64+
* @returns {boolean} True if we should highlight the connection.
65+
*/
2566
shouldHighlightConnection(connection) {
2667
return (
2768
connection.type === Blockly.ConnectionType.INPUT_VALUE &&

0 commit comments

Comments
 (0)