Skip to content

Commit 3b62021

Browse files
committed
node messages not required to render, can control node message
1 parent c0885e7 commit 3b62021

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,16 @@
298298
],
299299
messages: [
300300
{
301-
message: "I am a message attatched to the node"
301+
message: "I am a message attatched to the node",
302+
alwaysShow: true,
303+
},
304+
{
305+
message: "I am a message that only shows when you're hovering over the node!",
302306
},
303307
{
304308
message: "I am another message attatched to the node with type \"error\"",
305-
type: "error"
309+
type: "error",
310+
alwaysShow: true,
306311
}
307312
],
308313
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@elicdavis/node-flow",
33
"description": "build node graphs",
44
"author": "Eli C Davis",
5-
"version": "0.1.9",
5+
"version": "0.1.10",
66
"license": "MIT",
77
"keywords": [
88
"nodes",

src/node.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type TitleChangeCallback = (node: FlowNode, oldTitle: string, newTitle: string)
3535
type InfoChangeCallback = (node: FlowNode, oldInfo: string, newInfo: string) => void
3636

3737

38-
3938
export interface WidgetConfig {
4039
type?: string,
4140
config?: any
@@ -81,6 +80,8 @@ function MessageTypeColor(messageType: MessageType): string {
8180
export interface NodeMessageConfig {
8281
message: string;
8382
type?: MessageType;
83+
alwaysShow?: boolean;
84+
color?: string;
8485
}
8586

8687
export interface FlowNodeConfig {
@@ -143,10 +144,13 @@ class MessageRenderer {
143144

144145
#text: Text;
145146

147+
#alwaysShow: boolean;
148+
146149
constructor(config: NodeMessageConfig) {
150+
this.#alwaysShow = config.alwaysShow ? config.alwaysShow : false;
147151
this.#text = new Text(config.message,
148152
{
149-
color: MessageTypeColor(config.type ? config.type : MessageType.Info),
153+
color: config.color ? config.color : MessageTypeColor(config.type ? config.type : MessageType.Info),
150154
},
151155
{
152156
LineSpacing: 2.5,
@@ -155,7 +159,10 @@ class MessageRenderer {
155159
);
156160
}
157161

158-
render(ctx: CanvasRenderingContext2D, scale: number, position: Vector2): number {
162+
render(ctx: CanvasRenderingContext2D, scale: number, position: Vector2, hovering: boolean): number {
163+
if (!this.#alwaysShow && !hovering) {
164+
return 0;
165+
}
159166
ctx.textAlign = TextAlign.Center;
160167
this.#text.render(ctx, scale, position);
161168
return this.#text.height(ctx) * scale;
@@ -1201,7 +1208,7 @@ export class FlowNode {
12011208
messageStart.y = nodeBounds.Position.y + nodeBounds.Size.y + (15 * camera.zoom);
12021209
for (let i = 0; i < this.#messages.length; i++) {
12031210
const message = this.#messages[i];
1204-
messageStart.y += message.render(ctx, camera.zoom, messageStart) + (10 * camera.zoom);
1211+
messageStart.y += message.render(ctx, camera.zoom, messageStart, !(state === NodeState.Idle)) + (10 * camera.zoom);
12051212
}
12061213
})
12071214
}

0 commit comments

Comments
 (0)