Skip to content

Commit

Permalink
Render target attachment bit as part of port. (#9068)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Feb 19, 2024
1 parent 167a91d commit d75523b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/gui2/src/components/GraphEditor/GraphEdge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ interface Inputs {
interface JunctionPoints {
points: Vec2[]
maxRadius: number
targetAttachment: { target: Vec2; length: number } | undefined
}
function circleIntersection(x: number, r1: number, r2: number): number {
Expand Down Expand Up @@ -160,8 +159,8 @@ function circleIntersection(x: number, r1: number, r2: number): number {
*/
/** Calculate the start and end positions of each 1-corner section composing an edge to the
* given offset. Return the points, the maximum radius that should be used to draw the corners
* connecting them, and the length of the target attachment bit.
* given offset. Return the points and the maximum radius that should be used to draw the corners
* connecting them.
*/
function junctionPoints(inputs: Inputs): JunctionPoints | null {
let halfSourceSize = inputs.sourceSize?.scale(0.5) ?? Vec2.Zero
Expand Down Expand Up @@ -230,7 +229,6 @@ function junctionPoints(inputs: Inputs): JunctionPoints | null {
return {
points: [source, targetAttachment],
maxRadius,
targetAttachment: attachment,
}
} else {
const radiusMax = theme.edge.three_corner.radius_max
Expand Down Expand Up @@ -282,7 +280,6 @@ function junctionPoints(inputs: Inputs): JunctionPoints | null {
return {
points: [source, j0, j1, attachmentTarget],
maxRadius: radiusMax,
targetAttachment: attachment,
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions app/gui2/src/components/GraphEditor/widgets/WidgetPort.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ const hasConnection = computed(
const isCurrentEdgeHoverTarget = computed(
() => isHovered.value && graph.unconnectedEdge != null && selection?.hoveredPort === portId.value,
)
const isCurrentDisconectedEdgeTarget = computed(
() =>
graph.unconnectedEdge?.disconnectedEdgeTarget === portId.value &&
graph.unconnectedEdge?.target !== portId.value,
)
const connected = computed(() => hasConnection.value || isCurrentEdgeHoverTarget.value)
const isTarget = computed(
() =>
(hasConnection.value && !isCurrentDisconectedEdgeTarget.value) ||
isCurrentEdgeHoverTarget.value,
)
const rootNode = shallowRef<HTMLElement>()
const nodeSize = useResizeObserver(rootNode, false)
Expand Down Expand Up @@ -145,6 +155,7 @@ export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {
class="WidgetPort"
:class="{
connected,
isTarget,
'r-24': connected,
newToConnect: !hasConnection && isCurrentEdgeHoverTarget,
primary: props.nesting < 2,
Expand Down Expand Up @@ -213,4 +224,16 @@ export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {
right: 0px;
}
}
.WidgetPort.isTarget:after {
content: '';
position: absolute;
top: -4px;
left: 50%;
width: 4px;
height: 5px;
transform: translate(-50%, 0);
background-color: var(--node-color-port);
z-index: -1;
}
</style>

0 comments on commit d75523b

Please sign in to comment.