@@ -2,7 +2,7 @@ import * as t from "io-ts"
2
2
import JSON5 from "json5"
3
3
import type { ComponentKey , DefAndParams , LibraryButtonOptions , LibraryButtonProps , LibraryItem } from "../ComponentMenu"
4
4
import { DrawParams , LogicEditor } from "../LogicEditor"
5
- import { COLOR_BACKGROUND , COLOR_COMPONENT_INNER_LABELS , COLOR_GROUP_SPAN , DrawingRect , GRID_STEP , drawClockInput , drawComponentName , drawLabel , drawWireLineToComponent , isTrivialNodeName , shouldShowNode , useCompact } from "../drawutils"
5
+ import { COLOR_BACKGROUND , COLOR_COMPONENT_INNER_LABELS , COLOR_GROUP_SPAN , DrawingRect , GRID_STEP , drawClockInput , drawComponentName , drawLabel , drawWireLineToComponent , isTrivialNodeName , shouldShowWiresTo , useCompact } from "../drawutils"
6
6
import { IconName , ImageName } from "../images"
7
7
import { S , Template } from "../strings"
8
8
import { ArrayFillUsing , ArrayOrDirect , EdgeTrigger , Expand , FixedArrayMap , HasField , HighImpedance , InteractionResult , LogicValue , LogicValueRepr , Mode , Unknown , brand , deepArrayEquals , isArray , isBoolean , isNumber , isRecord , isString , mergeWhereDefined , toLogicValueRepr , typeOrUndefined , validateJson } from "../utils"
@@ -196,10 +196,19 @@ export const ComponentNameRepr = typeOrUndefined(
196
196
] )
197
197
)
198
198
199
- export type NodeOutDesc = readonly [ x : number , y : number , orient : Orientation , fullName ?: string , opts ?: { hasTriangle ?: boolean , labelName ?: string } ]
200
- export type NodeInDesc = readonly [ x : number , y : number , orient : Orientation , fullName ?: string , opts ?: { hasTriangle ?: boolean , labelName ?: string , prefersSpike ?: boolean , isClock ?: boolean } ]
199
+ type NodeOutDescOptions = { hasTriangle ?: boolean , labelName ?: string , leadLength ?: number }
200
+ export type NodeOutDesc =
201
+ | readonly [ x : number , y : number , orient : Orientation , opts ?: NodeOutDescOptions ]
202
+ | readonly [ x : number , y : number , orient : Orientation , fullName ?: string , opts ?: NodeOutDescOptions ]
203
+
204
+
205
+ type NodeInDescOptions = { hasTriangle ?: boolean , labelName ?: string , leadLength ?: number , prefersSpike ?: boolean , isClock ?: boolean }
206
+ export type NodeInDesc =
207
+ | readonly [ x : number , y : number , orient : Orientation , opts ?: NodeInDescOptions ]
208
+ | readonly [ x : number , y : number , orient : Orientation , fullName ?: string , opts ?: NodeInDescOptions ]
209
+
201
210
export type NodeDesc = NodeOutDesc | NodeInDesc
202
- export type NodeDescInGroup = readonly [ x : number , y : number , shortNameOverride ?: string ]
211
+ export type NodeDescInGroup = readonly [ x : number , y : number , shortNameOverride ?: string , opts ?: NodeInDescOptions ]
203
212
export type NodeGroupDesc < D extends NodeDesc > = ReadonlyArray < D >
204
213
export type NodeGroupMultiDesc < D extends NodeDesc > = ReadonlyArray < NodeGroupDesc < D > >
205
214
export type NodeRec < D extends NodeDesc > = Record < string , D | NodeGroupDesc < D > | NodeGroupMultiDesc < D > >
@@ -417,6 +426,7 @@ export abstract class ComponentBase<
417
426
_gridOffsetY : number ,
418
427
hasTriangle : boolean ,
419
428
orient : Orientation ,
429
+ leadLength : number | undefined ,
420
430
) => TNode ) {
421
431
422
432
const nodes : Record < string , TNode | ReadonlyArray < TNode > | ReadonlyArray < ReadonlyArray < TNode > > > = { }
@@ -426,10 +436,20 @@ export abstract class ComponentBase<
426
436
if ( nodeRec !== undefined ) {
427
437
const makeNode = ( group : NodeGroup < TNode > | undefined , shortName : string , desc : TDesc ) => {
428
438
const spec = specs [ nextSpecIndex ++ ]
429
- const [ offsetX , offsetY , orient , nameOverride , options_ ] = desc
430
- const options = options_ as NodeInDesc [ 4 ] // bleh
439
+ const [ offsetX , offsetY , orient , nameOrOptions , options_ ] = desc
440
+ let nameOverride : string | undefined = undefined
441
+ let options : NodeInDescOptions | undefined = undefined
442
+ if ( isString ( nameOrOptions ) ) {
443
+ nameOverride = nameOrOptions
444
+ } else if ( nameOrOptions !== undefined ) {
445
+ options = nameOrOptions
446
+ }
447
+ if ( options_ !== undefined ) {
448
+ options = options_
449
+ }
431
450
const isClock = options ?. isClock ?? false
432
451
const prefersSpike = options ?. prefersSpike ?? false
452
+ const leadLength = options ?. leadLength
433
453
const hasTriangle = options ?. hasTriangle ?? false
434
454
if ( group !== undefined && nameOverride !== undefined ) {
435
455
// names in groups are considered short names to be used as labels
@@ -449,6 +469,7 @@ export abstract class ComponentBase<
449
469
offsetY ,
450
470
hasTriangle ,
451
471
orient ,
472
+ leadLength ,
452
473
)
453
474
if ( prefersSpike || isClock ) {
454
475
if ( newNode instanceof NodeIn ) {
@@ -874,12 +895,11 @@ export abstract class ComponentBase<
874
895
return
875
896
}
876
897
877
- const offset = node . hasTriangle ? 3 : 0
878
- drawWireLineToComponent ( g , node , ...this . anchorFor ( node , bounds , offset ) , node . hasTriangle )
898
+ drawWireLineToComponent ( g , node )
879
899
}
880
900
881
901
protected drawGroupBox ( g : GraphicsRendering , group : NodeGroup < Node > , bounds : DrawingRect ) {
882
- if ( ! shouldShowNode ( group . nodes ) ) {
902
+ if ( ! shouldShowWiresTo ( group . nodes ) ) {
883
903
return
884
904
}
885
905
@@ -1459,15 +1479,15 @@ export abstract class ParametrizedComponentBase<
1459
1479
//
1460
1480
1461
1481
export function group < const TDescArr extends readonly NodeDescInGroup [ ] > ( orient : Orientation , nodes : TDescArr ) {
1462
- return FixedArrayMap ( nodes , ( [ x , y , name ] ) => [ x , y , orient , name ] as const )
1482
+ return FixedArrayMap ( nodes , ( [ x , y , name , opts ] ) => [ x , y , orient , name , opts ] as const )
1463
1483
}
1464
1484
1465
- export function groupVertical ( orient : "e" | "w" , x : number , yCenter : number , num : number , spacing ?: number ) {
1485
+ export function groupVertical ( orient : "e" | "w" , x : number , yCenter : number , num : number , spacing ?: number , opts ?: NodeInDescOptions ) {
1466
1486
const spacing_ = spacing ?? ( useCompact ( num ) ? 1 : 2 )
1467
1487
const span = ( num - 1 ) * spacing_
1468
1488
const yTop = yCenter - span / 2
1469
1489
return group ( orient ,
1470
- ArrayFillUsing ( i => [ x , yTop + i * spacing_ ] , num )
1490
+ ArrayFillUsing ( i => [ x , yTop + i * spacing_ , undefined , opts ] , num )
1471
1491
)
1472
1492
}
1473
1493
@@ -1482,12 +1502,12 @@ export function groupVerticalMulti(orient: "e" | "w", x: number, yCenter: number
1482
1502
) , numOuter )
1483
1503
}
1484
1504
1485
- export function groupHorizontal ( orient : "n" | "s" , xCenter : number , y : number , num : number , spacing ?: number ) {
1505
+ export function groupHorizontal ( orient : "n" | "s" , xCenter : number , y : number , num : number , spacing ?: number , opts ?: NodeInDescOptions ) {
1486
1506
const spacing_ = spacing ?? ( useCompact ( num ) ? 1 : 2 )
1487
1507
const span = ( num - 1 ) * spacing_
1488
1508
const xRight = xCenter + span / 2
1489
1509
return group ( orient ,
1490
- ArrayFillUsing ( i => [ xRight - i * spacing_ , y ] , num )
1510
+ ArrayFillUsing ( i => [ xRight - i * spacing_ , y , undefined , opts ] , num )
1491
1511
)
1492
1512
}
1493
1513
0 commit comments