11import { Camera } from "./camera" ;
22import { Connection } from './connection' ;
3+ import { RenderElementBase } from "./elements/base" ;
4+ import { ContainerRenderElement , AlignItems } from './elements/container' ;
5+ import { TextAlign , TextElement } from "./elements/text" ;
36import { FlowNode } from "./node" ;
47import { PassSubsystem } from "./pass/subsystem" ;
5- import { TextAlign } from "./styles/canvasTextAlign" ;
6- import { Box , BoxIntersection , InBox } from "./types/box" ;
8+ import { FontStyle } from "./styles/text" ;
9+ import { Box , InBox } from "./types/box" ;
10+ import { Text } from "./types/text" ;
711import { Vector2 } from "./types/vector2" ;
8- import { Color , HSV , HSV2RGB , RgbToHex } from " ./utils/color" ;
12+ import { Color , HSV , HSV2RGB , RgbToHex } from ' ./utils/color' ;
913
1014export enum PortType {
1115 Input = "INPUT" ,
@@ -25,6 +29,7 @@ type ConnectionChangeCallback = (connection: Connection, connectionIndex: number
2529export interface PortConfig {
2630 name ?: string ;
2731 type ?: string ;
32+ description ?: string ;
2833 array ?: boolean ;
2934 emptyStyle ?: PortStyle ;
3035 filledStyle ?: PortStyle ;
@@ -64,9 +69,11 @@ export class Port {
6469
6570 #dataType: string ;
6671
72+ #dataTypePopupElement: RenderElementBase ;
73+
6774 #onConnectionAdded: Array < ConnectionChangeCallback > ;
6875
69- #onConnectionRemoved: Array < ConnectionChangeCallback > ; ;
76+ #onConnectionRemoved: Array < ConnectionChangeCallback > ;
7077
7178 constructor ( node : FlowNode , portType : PortType , config ?: PortConfig ) {
7279 this . #node = node ;
@@ -98,6 +105,43 @@ export class Port {
98105 if ( config ?. onConnectionRemoved ) {
99106 this . #onConnectionRemoved. push ( config ?. onConnectionRemoved ) ;
100107 }
108+
109+ const containerElements = new Array < RenderElementBase > ( ) ;
110+ let dataTypeDisplay = this . #dataType;
111+ if ( config ?. array === true ) {
112+ dataTypeDisplay = "Array<" + dataTypeDisplay + ">"
113+ }
114+ containerElements . push ( new TextElement (
115+ new Text ( dataTypeDisplay , {
116+ color : "white" ,
117+ } ) ,
118+ {
119+ Align : TextAlign . Center ,
120+ }
121+ ) ) ;
122+
123+ const description = config ?. description ;
124+ if ( description && description !== "" ) {
125+ containerElements . push ( new TextElement (
126+ new Text ( description , { color : "white" , style : FontStyle . Italic } ) ,
127+ {
128+ Align : TextAlign . Center ,
129+ Padding : { Top : 8 } ,
130+ MaxWidth : 300
131+ }
132+ ) ) ;
133+ }
134+
135+ this . #dataTypePopupElement = new ContainerRenderElement (
136+ containerElements ,
137+ {
138+ BackgroundColor : "rgba(0, 0, 0, 0.75)" ,
139+ Border : {
140+ Radius : 6 ,
141+ } ,
142+ Padding : 13 ,
143+ }
144+ ) ;
101145 }
102146
103147 addConnection ( connection : Connection ) : void {
@@ -183,20 +227,12 @@ export class Port {
183227 const xPos = position . x ;
184228 const yPos = position . y ;
185229
230+ // TODO: Make it so we're not creating a new lambda each frame
186231 postProcess . queue ( ( ) => {
187- ctx . textAlign = TextAlign . Center ;
188-
189- const padding = 13 ;
190- const measurement = ctx . measureText ( this . #dataType)
191- const w = measurement . width + ( padding * camera . zoom ) ;
192-
193- ctx . beginPath ( ) ;
194- ctx . fillStyle = "rgba(0, 0, 0, 0.75)" ;
195- ctx . roundRect ( xPos - w / 2 , yPos + ( scaledRadius * 3 ) - ( padding * camera . zoom ) , w , ( padding * 2 ) * camera . zoom , 4 * camera . zoom ) ;
196- ctx . fill ( ) ;
197-
198- ctx . fillStyle = "#FFFFFF" ;
199- ctx . fillText ( this . #dataType, xPos , yPos + ( scaledRadius * 3 ) ) ;
232+ const size = { x : 0 , y : 0 }
233+ this . #dataTypePopupElement. calcSize ( ctx , size , { x : - 1 , y : - 1 } ) ;
234+ // size.x = Math.min(150, size.x)
235+ this . #dataTypePopupElement. render ( ctx , { x : xPos - ( size . x / 2 ) , y : yPos } , 1 , size )
200236 } )
201237 }
202238
0 commit comments