Skip to content

Commit 12ca060

Browse files
committed
Hide the left border notch in layers when a wire isn't entering from the layer's left
1 parent 35f7cfa commit 12ca060

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub enum FrontendMessage {
158158
layer_widths: HashMap<NodeId, u32>,
159159
#[serde(rename = "chainWidths")]
160160
chain_widths: HashMap<NodeId, u32>,
161+
#[serde(rename = "hasLeftInputWire")]
162+
has_left_input_wire: HashMap<NodeId, bool>,
161163
},
162164
UpdateDialogButtons {
163165
#[serde(rename = "layoutTarget")]

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,12 +1076,16 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
10761076
// TODO: Implement culling of nodes and wires whose bounding boxes are outside of the viewport
10771077
let wires = Self::collect_wires(network_interface, breadcrumb_network_path);
10781078
let nodes = self.collect_nodes(network_interface, breadcrumb_network_path);
1079-
let (layer_widths, chain_widths) = network_interface.collect_layer_widths(breadcrumb_network_path);
1079+
let (layer_widths, chain_widths, has_left_input_wire) = network_interface.collect_layer_widths(breadcrumb_network_path);
10801080
let imports = network_interface.frontend_imports(breadcrumb_network_path).unwrap_or_default();
10811081
let exports = network_interface.frontend_exports(breadcrumb_network_path).unwrap_or_default();
10821082
responses.add(FrontendMessage::UpdateImportsExports { imports, exports });
10831083
responses.add(FrontendMessage::UpdateNodeGraph { nodes, wires });
1084-
responses.add(FrontendMessage::UpdateLayerWidths { layer_widths, chain_widths });
1084+
responses.add(FrontendMessage::UpdateLayerWidths {
1085+
layer_widths,
1086+
chain_widths,
1087+
has_left_input_wire,
1088+
});
10851089
responses.add(NodeGraphMessage::SendSelectedNodes);
10861090
}
10871091
}

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,24 +2783,36 @@ impl NodeNetworkInterface {
27832783
bounding_box_subpath.bounding_box_with_transform(network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport)
27842784
}
27852785

2786-
pub fn collect_layer_widths(&mut self, network_path: &[NodeId]) -> (HashMap<NodeId, u32>, HashMap<NodeId, u32>) {
2786+
pub fn collect_layer_widths(&mut self, network_path: &[NodeId]) -> (HashMap<NodeId, u32>, HashMap<NodeId, u32>, HashMap<NodeId, bool>) {
27872787
let Some(network_metadata) = self.network_metadata(network_path) else {
27882788
log::error!("Could not get nested network_metadata in collect_layer_widths");
2789-
return (HashMap::new(), HashMap::new());
2789+
return (HashMap::new(), HashMap::new(), HashMap::new());
27902790
};
27912791
let nodes = network_metadata
27922792
.persistent_metadata
27932793
.node_metadata
27942794
.iter()
27952795
.filter_map(|(node_id, _)| if self.is_layer(node_id, network_path) { Some(*node_id) } else { None })
27962796
.collect::<Vec<_>>();
2797-
(
2798-
nodes
2799-
.iter()
2800-
.filter_map(|node_id| self.layer_width(node_id, network_path).map(|layer_width| (*node_id, layer_width)))
2801-
.collect::<HashMap<NodeId, u32>>(),
2802-
nodes.iter().map(|node_id| (*node_id, self.chain_width(node_id, network_path))).collect::<HashMap<NodeId, u32>>(),
2803-
)
2797+
let layer_widths = nodes
2798+
.iter()
2799+
.filter_map(|node_id| self.layer_width(node_id, network_path).map(|layer_width| (*node_id, layer_width)))
2800+
.collect::<HashMap<NodeId, u32>>();
2801+
let chain_widths = nodes.iter().map(|node_id| (*node_id, self.chain_width(node_id, network_path))).collect::<HashMap<NodeId, u32>>();
2802+
let has_left_input_wire = nodes
2803+
.iter()
2804+
.map(|node_id| {
2805+
(
2806+
*node_id,
2807+
!self
2808+
.upstream_flow_back_from_nodes(vec![*node_id], network_path, FlowType::HorizontalFlow)
2809+
.skip(1)
2810+
.all(|node_id| self.is_chain(&node_id, network_path)),
2811+
)
2812+
})
2813+
.collect::<HashMap<NodeId, bool>>();
2814+
2815+
(layer_widths, chain_widths, has_left_input_wire)
28042816
}
28052817

28062818
pub fn compute_modified_vector(&self, layer: LayerNodeIdentifier) -> Option<VectorData> {

frontend/src/components/views/Graph.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
return borderMask(boxes, nodeWidth, nodeHeight);
232232
}
233233
234-
function layerBorderMask(nodeWidthFromThumbnail: number, nodeChainAreaLeftExtension: number): string {
234+
function layerBorderMask(nodeWidthFromThumbnail: number, nodeChainAreaLeftExtension: number, hasLeftInputWire: boolean): string {
235235
const NODE_HEIGHT = 2 * 24;
236236
const THUMBNAIL_WIDTH = 72 + 8 * 2;
237237
const FUDGE_HEIGHT_BEYOND_LAYER_HEIGHT = 2;
@@ -241,7 +241,7 @@
241241
const boxes: { x: number; y: number; width: number; height: number }[] = [];
242242
243243
// Left input
244-
if (nodeChainAreaLeftExtension > 0) {
244+
if (hasLeftInputWire && nodeChainAreaLeftExtension > 0) {
245245
boxes.push({ x: -8, y: 16, width: 16, height: 16 });
246246
}
247247
@@ -461,6 +461,7 @@
461461
{@const stackDataInput = node.exposedInputs[0]}
462462
{@const layerAreaWidth = $nodeGraph.layerWidths.get(node.id) || 8}
463463
{@const layerChainWidth = $nodeGraph.chainWidths.get(node.id) || 0}
464+
{@const hasLeftInputWire = $nodeGraph.hasLeftInputWire.get(node.id) || false}
464465
{@const description = (node.reference && $nodeGraph.nodeDescriptions.get(node.reference)) || undefined}
465466
<div
466467
class="layer"
@@ -576,7 +577,7 @@
576577
<defs>
577578
<clipPath id={clipPathId}>
578579
<!-- Keep this equation in sync with the equivalent one in the CSS rule for `.layer { width: ... }` below -->
579-
<path clip-rule="evenodd" d={layerBorderMask(24 * layerAreaWidth - 12, layerChainWidth ? (0.5 + layerChainWidth) * 24 : 0)} />
580+
<path clip-rule="evenodd" d={layerBorderMask(24 * layerAreaWidth - 12, layerChainWidth ? (0.5 + layerChainWidth) * 24 : 0, hasLeftInputWire)} />
580581
</clipPath>
581582
</defs>
582583
</svg>

frontend/src/state-providers/node-graph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function createNodeGraphState(editor: Editor) {
3333
contextMenuInformation: undefined as ContextMenuInformation | undefined,
3434
layerWidths: new Map<bigint, number>(),
3535
chainWidths: new Map<bigint, number>(),
36+
hasLeftInputWire: new Map<bigint, boolean>(),
3637
imports: [] as { outputMetadata: FrontendGraphOutput; position: { x: number; y: number } }[],
3738
exports: [] as { inputMetadata: FrontendGraphInput; position: { x: number; y: number } }[],
3839
nodes: new Map<bigint, FrontendNode>(),
@@ -92,6 +93,7 @@ export function createNodeGraphState(editor: Editor) {
9293
update((state) => {
9394
state.layerWidths = updateLayerWidths.layerWidths;
9495
state.chainWidths = updateLayerWidths.chainWidths;
96+
state.hasLeftInputWire = updateLayerWidths.hasLeftInputWire;
9597
return state;
9698
});
9799
});

frontend/src/wasm-communication/messages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ export class UpdateInSelectedNetwork extends JsMessage {
6969

7070
const LayerWidths = Transform(({ obj }) => obj.layerWidths);
7171
const ChainWidths = Transform(({ obj }) => obj.chainWidths);
72+
const HasLeftInputWire = Transform(({ obj }) => obj.hasLeftInputWire);
7273

7374
export class UpdateLayerWidths extends JsMessage {
7475
@LayerWidths
7576
readonly layerWidths!: Map<bigint, number>;
7677
@ChainWidths
7778
readonly chainWidths!: Map<bigint, number>;
79+
@HasLeftInputWire
80+
readonly hasLeftInputWire!: Map<bigint, boolean>;
7881
}
7982

8083
export class UpdateNodeGraph extends JsMessage {

0 commit comments

Comments
 (0)