Skip to content

Commit 977309a

Browse files
committed
Added Font Awesome icons to node titles and toggle description rendering
1 parent fd2a02f commit 977309a

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
1212
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
1313
<title>JavaScript Visual Scripting</title>
14+
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet">
1415
</head>
1516
<body>
1617
<noscript>You need to enable JavaScript to run this app.</noscript>

src/engine/Renderer.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { nodeTypes } from '../nodeDefinitions';
2+
import { getIconForNodeType } from '../components/ContextMenu';
23

34
const FONT_FAMILY = "'Inter', sans-serif";
45

@@ -8,6 +9,7 @@ class Renderer {
89
this.isDarkTheme = isDarkTheme;
910
this.isGridVisible = isGridVisible;
1011
this.isNodeRoundingEnabled = isNodeRoundingEnabled;
12+
this.renderDescription = false;
1113
this.GRID_SIZE = 20;
1214
}
1315

@@ -51,8 +53,8 @@ class Renderer {
5153
const titleWidth = ctx.measureText(node.type).width;
5254

5355
ctx.font = `400 13px ${FONT_FAMILY}`;
54-
const descriptionLines = this.wrapText(ctx, nodeType.description, 180);
55-
const descriptionHeight = descriptionLines.length * 14;
56+
const descriptionLines = this.renderDescription ? this.wrapText(ctx, nodeType.description, 180) : [];
57+
const descriptionHeight = this.renderDescription ? descriptionLines.length * 14 : 0;
5658

5759
const inputsHeight = nodeType.inputs.length * 20;
5860
const outputsHeight = nodeType.outputs.length * 20;
@@ -64,13 +66,13 @@ class Renderer {
6466
return height + (isVisible ? 20 : 0);
6567
}, 0) : 0;
6668

67-
const width = Math.max(200, titleWidth + 20, ...descriptionLines.map(line => ctx.measureText(line).width + 20));
69+
const width = Math.max(200, titleWidth + 20, ...(this.renderDescription ? descriptionLines.map(line => ctx.measureText(line).width + 20) : []));
6870
const height = 35 + descriptionHeight + Math.max(inputsHeight, outputsHeight) + propertiesHeight;
6971

7072
return {
7173
width,
7274
height,
73-
portStartY: 35 + descriptionHeight // This is the y-coordinate where ports start
75+
portStartY: 35 + descriptionHeight
7476
};
7577
}
7678

@@ -258,21 +260,33 @@ class Renderer {
258260

259261
let currentHeight = 0;
260262

261-
// Node title
263+
// Node title with icon
262264
ctx.fillStyle = 'white';
263265
ctx.font = `600 14px ${FONT_FAMILY}`;
264266
currentHeight += 20;
265-
ctx.fillText(node.type, node.x + 10, node.y + currentHeight);
266-
267-
// Node description
268-
ctx.font = `400 13px ${FONT_FAMILY}`;
269-
const descriptionLines = this.wrapText(ctx, nodeType.description, width - 20);
270-
descriptionLines.forEach((line, index) => {
271-
currentHeight += 14;
272-
ctx.fillText(line, node.x + 10, node.y + currentHeight + 3);
273-
});
274-
275-
currentHeight += 15; // Add some padding after description
267+
268+
// Draw icon using Font Awesome unicode
269+
const iconClass = getIconForNodeType(node.type);
270+
const iconUnicode = this.getIconUnicode(iconClass);
271+
ctx.font = `900 14px "Font Awesome 5 Free"`;
272+
ctx.fillText(iconUnicode, node.x + 10, node.y + currentHeight);
273+
274+
// Draw title after icon
275+
ctx.font = `600 14px ${FONT_FAMILY}`;
276+
ctx.fillText(node.type, node.x + 30, node.y + currentHeight);
277+
278+
// Node description - only render if renderDescription is true
279+
if (this.renderDescription) {
280+
ctx.font = `400 13px ${FONT_FAMILY}`;
281+
const descriptionLines = this.wrapText(ctx, nodeType.description, width - 20);
282+
descriptionLines.forEach((line, index) => {
283+
currentHeight += 14;
284+
ctx.fillText(line, node.x + 10, node.y + currentHeight + 3);
285+
});
286+
currentHeight += 15; // Add padding after description
287+
} else {
288+
currentHeight += 15; // Add minimal padding between title and ports
289+
}
276290

277291
// Input ports
278292
nodeType.inputs.forEach((input, i) => {
@@ -390,6 +404,32 @@ class Renderer {
390404
y + height < viewBounds.top - padding ||
391405
y > viewBounds.bottom + padding);
392406
}
407+
408+
setRenderDescription(renderDescription) {
409+
this.renderDescription = renderDescription;
410+
}
411+
412+
// Add this helper method to convert Font Awesome class names to unicode
413+
getIconUnicode(iconClass) {
414+
const iconMap = {
415+
'fa-play': '\uf04b',
416+
'fa-terminal': '\uf120',
417+
'fa-cube': '\uf1b2',
418+
'fa-code': '\uf121',
419+
'fa-calculator': '\uf1ec',
420+
'fa-code-branch': '\uf126',
421+
'fa-sync': '\uf021',
422+
'fa-redo': '\uf01e',
423+
'fa-list': '\uf03a',
424+
'fa-globe': '\uf0ac',
425+
'fa-file-code': '\uf1c9',
426+
'fa-file-alt': '\uf15c',
427+
'fa-lock': '\uf023',
428+
'fa-unlock': '\uf09c',
429+
'fa-puzzle-piece': '\uf12e'
430+
};
431+
return iconMap[iconClass] || iconMap['fa-puzzle-piece'];
432+
}
393433
}
394434

395435
export default Renderer;

0 commit comments

Comments
 (0)