@elicdavis/node-flow 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -298,11 +298,16 @@ node.addOutput({ name: "sum", type: "float32" })
298
298
  ],
299
299
  messages: [
300
300
  {
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!",
302
306
  },
303
307
  {
304
308
  message: "I am another message attatched to the node with type \"error\"",
305
- type: "error"
309
+ type: "error",
310
+ alwaysShow: true,
306
311
  }
307
312
  ],
308
313
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@elicdavis/node-flow",
3
3
  "description": "build node graphs",
4
4
  "author": "Eli C Davis",
5
- "version": "0.1.9",
5
+ "version": "0.1.11",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "nodes",
package/src/index.ts CHANGED
@@ -14,12 +14,14 @@ export { FlowNote };
14
14
  import { NumberWidget } from './widgets/number';
15
15
  import { ColorWidget } from './widgets/color';
16
16
  import { StringWidget } from './widgets/string';
17
+ import { TextWidget } from './widgets/text';
17
18
  import { ButtonWidget } from './widgets/button';
18
19
  import { ToggleWidget } from './widgets/toggle';
19
20
  import { SliderWidget } from './widgets/slider';
20
21
  import { ImageWidget } from './widgets/image';
21
22
  export {
22
- NumberWidget, ColorWidget, StringWidget, ButtonWidget, ToggleWidget, SliderWidget, ImageWidget
23
+ NumberWidget, ColorWidget, StringWidget, TextWidget,
24
+ ButtonWidget, ToggleWidget, SliderWidget, ImageWidget
23
25
  };
24
26
 
25
27
  import { GlobalWidgetFactory } from './widgets/factory';
package/src/node.ts CHANGED
@@ -35,7 +35,6 @@ type TitleChangeCallback = (node: FlowNode, oldTitle: string, newTitle: string)
35
35
  type InfoChangeCallback = (node: FlowNode, oldInfo: string, newInfo: string) => void
36
36
 
37
37
 
38
-
39
38
  export interface WidgetConfig {
40
39
  type?: string,
41
40
  config?: any
@@ -81,6 +80,8 @@ function MessageTypeColor(messageType: MessageType): string {
81
80
  export interface NodeMessageConfig {
82
81
  message: string;
83
82
  type?: MessageType;
83
+ alwaysShow?: boolean;
84
+ color?: string;
84
85
  }
85
86
 
86
87
  export interface FlowNodeConfig {
@@ -143,10 +144,13 @@ class MessageRenderer {
143
144
 
144
145
  #text: Text;
145
146
 
147
+ #alwaysShow: boolean;
148
+
146
149
  constructor(config: NodeMessageConfig) {
150
+ this.#alwaysShow = config.alwaysShow ? config.alwaysShow : false;
147
151
  this.#text = new Text(config.message,
148
152
  {
149
- color: MessageTypeColor(config.type ? config.type : MessageType.Info),
153
+ color: config.color ? config.color : MessageTypeColor(config.type ? config.type : MessageType.Info),
150
154
  },
151
155
  {
152
156
  LineSpacing: 2.5,
@@ -155,7 +159,10 @@ class MessageRenderer {
155
159
  );
156
160
  }
157
161
 
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
+ }
159
166
  ctx.textAlign = TextAlign.Center;
160
167
  this.#text.render(ctx, scale, position);
161
168
  return this.#text.height(ctx) * scale;
@@ -849,6 +856,14 @@ export class FlowNode {
849
856
  this.#widgets.push(widget);
850
857
  }
851
858
 
859
+ removeWidget(widget: Widget): void {
860
+ const index = this.#widgets.indexOf(widget, 0);
861
+ if (index === -1) {
862
+ throw new Error("node does not contain widget");
863
+ }
864
+ this.#widgets.splice(index, 1);
865
+ }
866
+
852
867
  getWidget(index: number): Widget {
853
868
  return this.#widgets[index];
854
869
  }
@@ -1201,7 +1216,7 @@ export class FlowNode {
1201
1216
  messageStart.y = nodeBounds.Position.y + nodeBounds.Size.y + (15 * camera.zoom);
1202
1217
  for (let i = 0; i < this.#messages.length; i++) {
1203
1218
  const message = this.#messages[i];
1204
- messageStart.y += message.render(ctx, camera.zoom, messageStart) + (10 * camera.zoom);
1219
+ messageStart.y += message.render(ctx, camera.zoom, messageStart, !(state === NodeState.Idle)) + (10 * camera.zoom);
1205
1220
  }
1206
1221
  })
1207
1222
  }