mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 15:53:26 -10:00
Prototype wire dragging ux improvements
This commit is contained in:
17 files changed
+587
-178
No files matched your search
@@ -4,6 +4,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
|
||||
use crate::messages::tool::tool_messages::tool_prelude::WidgetCallback;
|
||||
use derivative::*;
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::color::SRGBA8;
|
||||
use graphene_std::vector::style::FillChoice;
|
||||
use graphite_proc_macros::WidgetBuilder;
|
||||
@@ -112,6 +113,15 @@ pub struct ParameterExposeButton {
|
||||
pub exposed: bool,
|
||||
#[serde(rename = "dataType")]
|
||||
pub data_type: FrontendGraphDataType,
|
||||
/// The node whose input this connector represents, so it can be dragged to and from as a wire endpoint.
|
||||
#[serde(rename = "nodeId")]
|
||||
pub node_id: NodeId,
|
||||
/// A `u32` so it reaches the frontend as a number rather than a bigint.
|
||||
#[serde(rename = "inputIndex")]
|
||||
pub input_index: u32,
|
||||
/// Whether the wire currently being dragged in the graph can be dropped onto this connector.
|
||||
#[serde(rename = "wireDropTarget")]
|
||||
pub wire_drop_target: bool,
|
||||
|
||||
// Tooltips
|
||||
#[serde(rename = "tooltipLabel")]
|
||||
|
||||
@@ -274,6 +274,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
.process_message(message, responses, OverlaysMessageContext { visibility_settings, viewport });
|
||||
}
|
||||
DocumentMessage::PropertiesPanel(message) => {
|
||||
let wire_in_progress_output_types = self.node_graph_handler.wire_in_progress_output_types(&self.network_interface, &self.selection_network_path);
|
||||
let context = PropertiesPanelMessageContext {
|
||||
executor,
|
||||
document_id,
|
||||
@@ -284,6 +285,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
fonts,
|
||||
properties_panel_open,
|
||||
properties_panel_collapsed_sections: &self.properties_panel_collapsed_sections,
|
||||
wire_in_progress_output_types: &wire_in_progress_output_types,
|
||||
};
|
||||
self.properties_panel_message_handler.process_message(message, responses, context);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ pub struct NodePropertiesContext<'a> {
|
||||
pub document_name: &'a str,
|
||||
/// The node IDs whose Properties panel sections the user has collapsed.
|
||||
pub properties_panel_collapsed_sections: &'a [NodeId],
|
||||
/// The types a wire being dragged from an output could carry, so compatible inputs can be marked as drop targets.
|
||||
pub wire_in_progress_output_types: &'a [Type],
|
||||
}
|
||||
|
||||
impl NodePropertiesContext<'_> {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::messages::portfolio::document::node_graph::document_node_definitions:
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{ChainInsertionPoint, ChainNodeCopy, ImportOrExport, InputConnector, NodeTemplate, OutputConnector, RootNode};
|
||||
use crate::messages::prelude::*;
|
||||
use glam::IVec2;
|
||||
use glam::{DVec2, IVec2};
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{NodeId, NodeInput};
|
||||
use graph_craft::proto::GraphErrors;
|
||||
@@ -139,6 +139,16 @@ pub enum NodeGraphMessage {
|
||||
},
|
||||
/// Sent every frame while a dragged wire hovers a node, to expand it once the hover delay passes.
|
||||
WireHoverTick,
|
||||
/// Begins dragging a wire out of an input connector shown in the Properties panel.
|
||||
StartWireFromPropertiesPanel {
|
||||
input_connector: InputConnector,
|
||||
editor_position: DVec2,
|
||||
},
|
||||
/// Reports whether the wire in progress is over the Properties panel, and which input connector there it hovers (at its editor position).
|
||||
SetWirePropertiesPanelHover {
|
||||
hovering_panel: bool,
|
||||
target: Option<(InputConnector, DVec2)>,
|
||||
},
|
||||
ShakeNode,
|
||||
UpdateNodeGraphWidth,
|
||||
RemoveImport {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::messages::portfolio::document::graph_operation::utility_types::Modify
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::{
|
||||
DefinitionIdentifier, NodePropertiesContext, resolve_document_node_type, resolve_network_node_type, resolve_proto_node_type,
|
||||
};
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic};
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic, WireInProgressAnchor};
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{
|
||||
@@ -86,7 +86,13 @@ pub struct NodeGraphMessageHandler {
|
||||
pub wire_in_progress_to_connector: Option<DVec2>,
|
||||
/// The data type determining the color of the wire being dragged.
|
||||
pub wire_in_progress_type: FrontendGraphDataType,
|
||||
/// The node hovered by the wire in progress and when the hover began, in milliseconds.
|
||||
/// The connector the wire being dragged is anchored at.
|
||||
pub wire_in_progress_anchor: Option<WireInProgressAnchor>,
|
||||
/// The Properties panel input connector hovered by a wire dragged from an output, with its position in viewport coordinates.
|
||||
wire_in_progress_properties_target: Option<(InputConnector, DVec2)>,
|
||||
/// Whether the pointer dragging a wire is over the Properties panel, where graph connectors beneath it can't be hovered.
|
||||
wire_in_progress_hovering_properties_panel: bool,
|
||||
/// The node hovered by a wire dragged from an output and when the hover began, in milliseconds.
|
||||
wire_hovered_node: Option<(NodeId, u64)>,
|
||||
/// The node expanded for the wire in progress and the indices of the inputs it temporarily exposed.
|
||||
wire_expanded_node: Option<(NodeId, Vec<usize>)>,
|
||||
@@ -324,29 +330,26 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
});
|
||||
responses.add(NodeGraphMessage::ShiftNodePosition { node_id, x, y });
|
||||
// Only auto connect to the dragged wire if the node is being added to the currently opened network
|
||||
if let Some(output_connector_position) = self.wire_in_progress_from_connector {
|
||||
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
|
||||
log::error!("Could not get network metadata in CreateNodeFromContextMenu");
|
||||
return;
|
||||
};
|
||||
let output_connector_position_viewport = network_metadata
|
||||
.persistent_metadata
|
||||
.navigation_metadata
|
||||
.node_graph_to_viewport
|
||||
.transform_point2(output_connector_position);
|
||||
let Some(output_connector) = &network_interface.output_connector_from_click(output_connector_position_viewport, breadcrumb_network_path) else {
|
||||
log::error!("Could not get output from connector start");
|
||||
return;
|
||||
};
|
||||
|
||||
// Ensure connection is to correct input of new node. If it does not have an input then do not connect
|
||||
if let Some((input_index, _)) = node_template.inputs.iter().enumerate().find(|(_, input)| input.is_exposed()) {
|
||||
responses.add(NodeGraphMessage::CreateWire {
|
||||
output_connector: *output_connector,
|
||||
input_connector: InputConnector::node_at_index(node_id, input_index),
|
||||
});
|
||||
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
if let Some(anchor) = self.wire_in_progress_anchor {
|
||||
match anchor {
|
||||
// Connect to the first exposed input of the new node, if it has one
|
||||
WireInProgressAnchor::Output(output_connector) => {
|
||||
if let Some((input_index, _)) = node_template.inputs.iter().enumerate().find(|(_, input)| input.is_exposed()) {
|
||||
responses.add(NodeGraphMessage::CreateWire {
|
||||
output_connector,
|
||||
input_connector: InputConnector::node_at_index(node_id, input_index),
|
||||
});
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
}
|
||||
// Feed the anchored input from the primary output of the new node
|
||||
WireInProgressAnchor::Input { input_connector, .. } => {
|
||||
responses.add(NodeGraphMessage::CreateWire {
|
||||
output_connector: OutputConnector::primary_output(node_id),
|
||||
input_connector,
|
||||
});
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.end_wire_in_progress(network_interface, selection_network_path, responses);
|
||||
@@ -983,21 +986,38 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.preview_on_mouse_up = Some(clicked_node);
|
||||
}
|
||||
|
||||
// Begin moving an existing wire
|
||||
if let Some(clicked_input) = &clicked_input {
|
||||
if let Some(clicked_input) = clicked_input {
|
||||
responses.add(DocumentMessage::StartTransaction);
|
||||
self.initial_disconnecting = true;
|
||||
self.disconnecting = Some(*clicked_input);
|
||||
|
||||
let output_connector = if *clicked_input == InputConnector::Export(0) {
|
||||
let output_connector = if clicked_input == InputConnector::Export(0) {
|
||||
network_interface.root_node(breadcrumb_network_path).map(|root_node| root_node.to_connector())
|
||||
} else {
|
||||
network_interface.upstream_output_connector(clicked_input, breadcrumb_network_path)
|
||||
network_interface.upstream_output_connector(&clicked_input, breadcrumb_network_path)
|
||||
};
|
||||
let Some(output_connector) = output_connector else { return };
|
||||
self.wire_in_progress_from_connector = network_interface.output_position(&output_connector, breadcrumb_network_path);
|
||||
|
||||
self.wire_in_progress_type = network_interface.output_type(&output_connector, breadcrumb_network_path).displayed_type();
|
||||
// Begin moving an existing wire
|
||||
if let Some(output_connector) = output_connector {
|
||||
self.initial_disconnecting = true;
|
||||
self.disconnecting = Some(clicked_input);
|
||||
|
||||
self.wire_in_progress_from_connector = network_interface.output_position(&output_connector, breadcrumb_network_path);
|
||||
self.wire_in_progress_type = network_interface.output_type(&output_connector, breadcrumb_network_path).displayed_type();
|
||||
self.wire_in_progress_anchor = Some(WireInProgressAnchor::Output(output_connector));
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
}
|
||||
// Begin creating a new wire backward from an unconnected input
|
||||
else {
|
||||
self.initial_disconnecting = false;
|
||||
|
||||
self.wire_in_progress_from_connector = network_interface.input_position(&clicked_input, selection_network_path);
|
||||
self.wire_in_progress_type = network_interface.input_type(&clicked_input, selection_network_path).displayed_type();
|
||||
self.wire_in_progress_anchor = Some(WireInProgressAnchor::Input {
|
||||
input_connector: clicked_input,
|
||||
properties_panel_position: None,
|
||||
});
|
||||
}
|
||||
|
||||
self.update_node_graph_hints(responses);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1009,6 +1029,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.wire_in_progress_from_connector = network_interface.output_position(&clicked_output, selection_network_path);
|
||||
let output_type = network_interface.output_type(&clicked_output, breadcrumb_network_path);
|
||||
self.wire_in_progress_type = output_type.displayed_type();
|
||||
self.wire_in_progress_anchor = Some(WireInProgressAnchor::Output(clicked_output));
|
||||
log::debug!("[wire-drag] Started wire from output {clicked_output:?}, refreshing the Properties panel");
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
|
||||
self.update_node_graph_hints(responses);
|
||||
return;
|
||||
@@ -1101,9 +1124,13 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
return;
|
||||
};
|
||||
|
||||
// Auto-panning
|
||||
// Auto-panning, except while a wire is dragged over the Properties panel
|
||||
let messages = [NodeGraphMessage::PointerOutsideViewport { shift }.into(), NodeGraphMessage::PointerMove { shift }.into()];
|
||||
self.auto_panning.setup_by_mouse_position(ipp, viewport, &messages, responses);
|
||||
if self.wire_in_progress_hovering_properties_panel {
|
||||
self.auto_panning.stop(&messages, responses);
|
||||
} else {
|
||||
self.auto_panning.setup_by_mouse_position(ipp, viewport, &messages, responses);
|
||||
}
|
||||
|
||||
let viewport_location = ipp.mouse.position;
|
||||
let point = network_metadata
|
||||
@@ -1114,74 +1141,89 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
.transform_point2(viewport_location);
|
||||
|
||||
if self.wire_in_progress_from_connector.is_some() && self.context_menu.is_none() {
|
||||
let to_connector = network_interface.input_connector_from_click(ipp.mouse.position, selection_network_path);
|
||||
if let Some(to_connector) = &to_connector {
|
||||
let Some(input_position) = network_interface.input_position(to_connector, selection_network_path) else {
|
||||
log::error!("Could not get input position for connector: {to_connector:?}");
|
||||
return;
|
||||
};
|
||||
self.wire_in_progress_to_connector = Some(input_position);
|
||||
}
|
||||
// Not hovering over a node input or node output, update with the mouse position.
|
||||
else {
|
||||
self.wire_in_progress_to_connector = Some(point);
|
||||
// Disconnect if the wire was previously connected to an input
|
||||
if let Some(disconnecting) = &self.disconnecting {
|
||||
let mut disconnect_root_node = false;
|
||||
if let Previewing::Yes { root_node_to_restore } = network_interface.previewing(selection_network_path)
|
||||
&& root_node_to_restore.is_some()
|
||||
&& *disconnecting == InputConnector::Export(0)
|
||||
{
|
||||
disconnect_root_node = true;
|
||||
}
|
||||
if disconnect_root_node {
|
||||
responses.add(NodeGraphMessage::DisconnectRootNode);
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::DisconnectInput { input_connector: *disconnecting });
|
||||
}
|
||||
// Update the frontend that the node is disconnected
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
self.disconnecting = None;
|
||||
}
|
||||
}
|
||||
let viewport_to_node_graph = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.inverse();
|
||||
|
||||
if let (Some(wire_in_progress_from_connector), Some(wire_in_progress_to_connector)) = (self.wire_in_progress_from_connector, self.wire_in_progress_to_connector) {
|
||||
// If performance is a concern this can be stored as a field in the wire_in_progress_from/to_connector struct, and updated when snapping to an output
|
||||
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
|
||||
return;
|
||||
};
|
||||
let from_connector_viewport = network_metadata
|
||||
.persistent_metadata
|
||||
.navigation_metadata
|
||||
.node_graph_to_viewport
|
||||
.transform_point2(wire_in_progress_from_connector);
|
||||
let from_connector_is_layer = network_interface
|
||||
.output_connector_from_click(from_connector_viewport, selection_network_path)
|
||||
.is_some_and(|output_connector| {
|
||||
if let OutputConnector::Node { node_id, .. } = output_connector {
|
||||
network_interface.is_layer(&node_id, selection_network_path)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let to_connector_is_layer = to_connector.is_some_and(|to_connector| {
|
||||
if let InputConnector::Node { node_id, input_index } = to_connector {
|
||||
input_index == 0 && network_interface.is_layer(&node_id, selection_network_path)
|
||||
} else {
|
||||
false
|
||||
// Layer stack connectors leave the wire vertically
|
||||
let is_layer_output =
|
||||
|output_connector: &OutputConnector| matches!(output_connector, OutputConnector::Node { node_id, .. } if network_interface.is_layer(node_id, selection_network_path));
|
||||
let is_layer_stack_input =
|
||||
|input_connector: &InputConnector| matches!(input_connector, InputConnector::Node { node_id, input_index: 0 } if network_interface.is_layer(node_id, selection_network_path));
|
||||
|
||||
// Only a wire dragged from an output expands the nodes it hovers
|
||||
let mut wire_hovered_node = None;
|
||||
|
||||
// Wire endpoints ordered from output to input, plus whether each one is a layer stack connector
|
||||
let wire_endpoints = match self.wire_in_progress_anchor {
|
||||
// Dragging backward from an input, so snap the loose end to an output under the pointer
|
||||
Some(WireInProgressAnchor::Input {
|
||||
input_connector,
|
||||
properties_panel_position,
|
||||
}) => {
|
||||
// An anchor in the Properties panel stays put on screen while the graph may pan beneath it
|
||||
if let Some(properties_panel_position) = properties_panel_position {
|
||||
self.wire_in_progress_from_connector = Some(viewport_to_node_graph.transform_point2(properties_panel_position));
|
||||
}
|
||||
});
|
||||
let vector_wire = build_vector_wire(
|
||||
wire_in_progress_from_connector,
|
||||
wire_in_progress_to_connector,
|
||||
from_connector_is_layer,
|
||||
to_connector_is_layer,
|
||||
GraphWireStyle::Direct,
|
||||
);
|
||||
let path_string = vector_wire.to_svg();
|
||||
|
||||
let hovered_output = (!self.wire_in_progress_hovering_properties_panel)
|
||||
.then(|| network_interface.output_connector_from_click(viewport_location, selection_network_path))
|
||||
.flatten();
|
||||
let hovered_output_position = hovered_output.and_then(|output_connector| network_interface.output_position(&output_connector, selection_network_path));
|
||||
self.wire_in_progress_to_connector = Some(hovered_output_position.unwrap_or(point));
|
||||
|
||||
let input_is_layer = properties_panel_position.is_none() && is_layer_stack_input(&input_connector);
|
||||
let output_is_layer = hovered_output.as_ref().is_some_and(is_layer_output);
|
||||
self.wire_in_progress_to_connector
|
||||
.zip(self.wire_in_progress_from_connector)
|
||||
.map(|(output_position, input_position)| (output_position, input_position, output_is_layer, input_is_layer))
|
||||
}
|
||||
// Dragging forward from an output, so snap the loose end to an input under the pointer or in the Properties panel
|
||||
Some(WireInProgressAnchor::Output(output_connector)) => {
|
||||
let hovered_input = (!self.wire_in_progress_hovering_properties_panel)
|
||||
.then(|| network_interface.input_connector_from_click(viewport_location, selection_network_path))
|
||||
.flatten();
|
||||
let hovered_input_position = hovered_input.and_then(|input_connector| network_interface.input_position(&input_connector, selection_network_path));
|
||||
let properties_target_position = self.wire_in_progress_properties_target.map(|(_, position)| viewport_to_node_graph.transform_point2(position));
|
||||
self.wire_in_progress_to_connector = Some(properties_target_position.or(hovered_input_position).unwrap_or(point));
|
||||
|
||||
// Disconnect if the wire was previously connected to an input
|
||||
if hovered_input.is_none()
|
||||
&& let Some(disconnecting) = self.disconnecting.take()
|
||||
{
|
||||
let disconnect_root_node =
|
||||
disconnecting == InputConnector::Export(0) && matches!(network_interface.previewing(selection_network_path), Previewing::Yes { root_node_to_restore: Some(_) });
|
||||
if disconnect_root_node {
|
||||
responses.add(NodeGraphMessage::DisconnectRootNode);
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::DisconnectInput { input_connector: disconnecting });
|
||||
}
|
||||
|
||||
// Update the frontend that the node is disconnected
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
}
|
||||
|
||||
// Input connectors stick out past their node's edge, so hovering one counts as hovering its node
|
||||
wire_hovered_node = (!self.wire_in_progress_hovering_properties_panel)
|
||||
.then(|| {
|
||||
let hovered_input_node = hovered_input.and_then(|input_connector| input_connector.node_id());
|
||||
hovered_input_node.or_else(|| network_interface.node_from_click(viewport_location, selection_network_path))
|
||||
})
|
||||
.flatten()
|
||||
.filter(|node_id| Some(*node_id) != output_connector.node_id());
|
||||
|
||||
let output_is_layer = is_layer_output(&output_connector);
|
||||
let input_is_layer = properties_target_position.is_none() && hovered_input.as_ref().is_some_and(is_layer_stack_input);
|
||||
self.wire_in_progress_from_connector
|
||||
.zip(self.wire_in_progress_to_connector)
|
||||
.map(|(output_position, input_position)| (output_position, input_position, output_is_layer, input_is_layer))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
if let Some((output_position, input_position, output_is_layer, input_is_layer)) = wire_endpoints {
|
||||
let vector_wire = build_vector_wire(output_position, input_position, output_is_layer, input_is_layer, GraphWireStyle::Direct);
|
||||
let wire_path = WirePath {
|
||||
path_string,
|
||||
path_string: vector_wire.to_svg(),
|
||||
data_type: self.wire_in_progress_type,
|
||||
thick: false,
|
||||
dashed: false,
|
||||
@@ -1191,14 +1233,6 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: Some(wire_path) });
|
||||
}
|
||||
|
||||
// Input connectors stick out past their node's edge, so hovering one counts as hovering its node
|
||||
let wire_source_node = self
|
||||
.wire_in_progress_output_connector(network_interface, selection_network_path)
|
||||
.and_then(|output_connector| output_connector.node_id());
|
||||
let wire_hovered_node = to_connector
|
||||
.and_then(|input_connector| input_connector.node_id())
|
||||
.or_else(|| network_interface.node_from_click(viewport_location, selection_network_path))
|
||||
.filter(|node_id| Some(*node_id) != wire_source_node);
|
||||
self.set_wire_hovered_node(wire_hovered_node.map(|node_id| (node_id, ipp.time)), network_interface, selection_network_path, responses);
|
||||
} else if let Some((drag_start, dragged)) = &mut self.drag_start {
|
||||
if drag_start.start_x != point.x || drag_start.start_y != point.y {
|
||||
@@ -1316,49 +1350,59 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
.node_graph_to_viewport
|
||||
.inverse()
|
||||
.transform_point2(ipp.mouse.position);
|
||||
// Disconnect if the wire was previously connected to an input
|
||||
if let (Some(wire_in_progress_from_connector), Some(wire_in_progress_to_connector)) = (self.wire_in_progress_from_connector, self.wire_in_progress_to_connector) {
|
||||
// Check if dragged connector is reconnected to another input
|
||||
if let (Some(anchor), Some(wire_in_progress_to_connector)) = (self.wire_in_progress_anchor, self.wire_in_progress_to_connector) {
|
||||
let node_graph_to_viewport = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport;
|
||||
let from_connector_viewport = node_graph_to_viewport.transform_point2(wire_in_progress_from_connector);
|
||||
let to_connector_viewport = node_graph_to_viewport.transform_point2(wire_in_progress_to_connector);
|
||||
let output_connector = network_interface.output_connector_from_click(from_connector_viewport, selection_network_path);
|
||||
let input_connector = network_interface.input_connector_from_click(to_connector_viewport, selection_network_path);
|
||||
let over_graph = !self.wire_in_progress_hovering_properties_panel;
|
||||
|
||||
// Resolve the loose end of the wire to the connector it was released on
|
||||
let (output_connector, input_connector) = match anchor {
|
||||
WireInProgressAnchor::Output(output_connector) => {
|
||||
let properties_target = self.wire_in_progress_properties_target.map(|(input_connector, _)| input_connector);
|
||||
let hovered_input = over_graph
|
||||
.then(|| network_interface.input_connector_from_click(to_connector_viewport, selection_network_path))
|
||||
.flatten();
|
||||
(Some(output_connector), properties_target.or(hovered_input))
|
||||
}
|
||||
WireInProgressAnchor::Input { input_connector, .. } => {
|
||||
let hovered_output = over_graph
|
||||
.then(|| network_interface.output_connector_from_click(to_connector_viewport, selection_network_path))
|
||||
.flatten();
|
||||
(hovered_output, Some(input_connector))
|
||||
}
|
||||
};
|
||||
|
||||
log::debug!(
|
||||
"[wire-drag] Released with anchor {anchor:?}, properties target {:?}, over graph {over_graph}, resolved {output_connector:?} -> {input_connector:?}",
|
||||
self.wire_in_progress_properties_target
|
||||
);
|
||||
|
||||
// Collapse now rather than when the wire ends, since the node creation menu can keep the wire alive
|
||||
let connected_input = output_connector.and(input_connector);
|
||||
self.collapse_wire_expanded_node(connected_input, network_interface, selection_network_path, responses);
|
||||
self.set_wire_hovered_node(None, network_interface, selection_network_path, responses);
|
||||
|
||||
if let (Some(output_connector), Some(input_connector)) = (&output_connector, &input_connector) {
|
||||
responses.add(NodeGraphMessage::CreateWire {
|
||||
input_connector: *input_connector,
|
||||
output_connector: *output_connector,
|
||||
});
|
||||
|
||||
if let (Some(output_connector), Some(input_connector)) = (output_connector, input_connector) {
|
||||
responses.add(NodeGraphMessage::CreateWire { output_connector, input_connector });
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
} else if !self.initial_disconnecting
|
||||
&& input_connector.is_none()
|
||||
&& let Some(output_connector) = output_connector
|
||||
{
|
||||
}
|
||||
// Released over empty graph space, so offer to create a node to connect the wire to
|
||||
else if !self.initial_disconnecting && over_graph {
|
||||
// If the add node menu is already open, we don't want to open it again
|
||||
if self.context_menu.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the output types from the network interface
|
||||
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
|
||||
warn!("No network_metadata");
|
||||
return;
|
||||
};
|
||||
|
||||
let appear_right_of_mouse = if ipp.mouse.position.x > viewport.size().y() - 173. { -173. } else { 0. };
|
||||
let appear_right_of_mouse = if ipp.mouse.position.x > viewport.size().x() - 173. { -173. } else { 0. };
|
||||
let appear_above_mouse = if ipp.mouse.position.y > viewport.size().y() - 34. { -34. } else { 0. };
|
||||
let node_graph_shift = DVec2::new(appear_right_of_mouse, appear_above_mouse) / network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.matrix2.x_axis.x;
|
||||
let node_graph_shift = DVec2::new(appear_right_of_mouse, appear_above_mouse) / node_graph_to_viewport.matrix2.x_axis.x;
|
||||
|
||||
let compatible_type = network_interface.output_type(&output_connector, selection_network_path).add_node_string();
|
||||
// The node catalog filters by input type, so a wire from an input isn't filtered
|
||||
let compatible_type = match anchor {
|
||||
WireInProgressAnchor::Output(output_connector) => network_interface.output_type(&output_connector, selection_network_path).add_node_string(),
|
||||
WireInProgressAnchor::Input { .. } => None,
|
||||
};
|
||||
|
||||
self.context_menu = Some(ContextMenuInformation {
|
||||
context_menu_coordinates: (point + node_graph_shift).as_ivec2().into(),
|
||||
@@ -1369,6 +1413,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
responses.add(FrontendMessage::UpdateContextMenuInformation {
|
||||
context_menu_information: self.context_menu.clone(),
|
||||
});
|
||||
// Remove the drop target highlights while the wire waits on the menu
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1545,7 +1591,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.update_node_graph_hints(responses);
|
||||
}
|
||||
NodeGraphMessage::PointerOutsideViewport { shift } => {
|
||||
if self.drag_start.is_some() || self.box_selection_start.is_some() || (self.wire_in_progress_from_connector.is_some() && self.context_menu.is_none()) {
|
||||
let wiring_over_graph = self.wire_in_progress_from_connector.is_some() && self.context_menu.is_none() && !self.wire_in_progress_hovering_properties_panel;
|
||||
if self.drag_start.is_some() || self.box_selection_start.is_some() || wiring_over_graph {
|
||||
let _ = self.auto_panning.shift_viewport(ipp, viewport, responses);
|
||||
} else {
|
||||
// Auto-panning
|
||||
@@ -1556,6 +1603,49 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
NodeGraphMessage::WireHoverTick => {
|
||||
self.expand_wire_hovered_node_after_delay(ipp.time, network_interface, selection_network_path, responses);
|
||||
}
|
||||
NodeGraphMessage::StartWireFromPropertiesPanel { input_connector, editor_position } => {
|
||||
if self.wire_in_progress_anchor.is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
|
||||
log::error!("Could not get network metadata in StartWireFromPropertiesPanel");
|
||||
return;
|
||||
};
|
||||
|
||||
// Dragging out of the Properties panel dismisses any open node creation menu
|
||||
if self.context_menu.take().is_some() {
|
||||
responses.add(FrontendMessage::UpdateContextMenuInformation { context_menu_information: None });
|
||||
}
|
||||
|
||||
let viewport_position: DVec2 = (viewport.logical(editor_position) - viewport.offset()).into();
|
||||
let viewport_to_node_graph = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.inverse();
|
||||
|
||||
responses.add(DocumentMessage::StartTransaction);
|
||||
self.initial_disconnecting = false;
|
||||
self.disconnecting = None;
|
||||
|
||||
self.wire_in_progress_from_connector = Some(viewport_to_node_graph.transform_point2(viewport_position));
|
||||
self.wire_in_progress_type = network_interface.input_type(&input_connector, selection_network_path).displayed_type();
|
||||
self.wire_in_progress_anchor = Some(WireInProgressAnchor::Input {
|
||||
input_connector,
|
||||
properties_panel_position: Some(viewport_position),
|
||||
});
|
||||
self.wire_in_progress_hovering_properties_panel = true;
|
||||
|
||||
self.update_node_graph_hints(responses);
|
||||
}
|
||||
NodeGraphMessage::SetWirePropertiesPanelHover { hovering_panel, target } => {
|
||||
log::debug!("[wire-drag] Hover report: over panel {hovering_panel}, target {target:?}, anchor {:?}", self.wire_in_progress_anchor);
|
||||
let Some(anchor) = self.wire_in_progress_anchor else { return };
|
||||
|
||||
self.wire_in_progress_hovering_properties_panel = hovering_panel;
|
||||
|
||||
// Only a wire dragged from an output can be dropped onto a Properties panel input
|
||||
self.wire_in_progress_properties_target = match anchor {
|
||||
WireInProgressAnchor::Output(_) => target.map(|(input_connector, editor_position)| (input_connector, (viewport.logical(editor_position) - viewport.offset()).into())),
|
||||
WireInProgressAnchor::Input { .. } => None,
|
||||
};
|
||||
}
|
||||
NodeGraphMessage::ShakeNode => {
|
||||
let Some((drag_start, _)) = &mut self.drag_start else {
|
||||
log::error!("Drag start should be initialized when shaking a node");
|
||||
@@ -2297,26 +2387,25 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
}
|
||||
|
||||
impl NodeGraphMessageHandler {
|
||||
/// Removes the wire in progress and collapses any node expanded for it.
|
||||
/// Removes the wire in progress along with any Properties panel drop target highlights, and collapses any node expanded for it.
|
||||
pub fn end_wire_in_progress(&mut self, network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], responses: &mut VecDeque<Message>) {
|
||||
if matches!(self.wire_in_progress_anchor, Some(WireInProgressAnchor::Output(_))) {
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
}
|
||||
|
||||
self.set_wire_hovered_node(None, network_interface, network_path, responses);
|
||||
|
||||
self.wire_in_progress_from_connector = None;
|
||||
self.wire_in_progress_to_connector = None;
|
||||
self.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
self.wire_in_progress_anchor = None;
|
||||
self.wire_in_progress_properties_target = None;
|
||||
self.wire_in_progress_hovering_properties_panel = false;
|
||||
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
}
|
||||
|
||||
/// The output the wire in progress is dragged from.
|
||||
fn wire_in_progress_output_connector(&self, network_interface: &NodeNetworkInterface, network_path: &[NodeId]) -> Option<OutputConnector> {
|
||||
let from_connector = self.wire_in_progress_from_connector?;
|
||||
let node_graph_to_viewport = network_interface.network_metadata(network_path)?.persistent_metadata.navigation_metadata.node_graph_to_viewport;
|
||||
|
||||
network_interface.output_connector_from_click(node_graph_to_viewport.transform_point2(from_connector), network_path)
|
||||
}
|
||||
|
||||
/// Tracks the node under the wire in progress and when the hover began, collapsing the expanded node once the wire leaves it.
|
||||
/// Tracks the node under a wire dragged from an output and when the hover began, collapsing the expanded node once the wire leaves it.
|
||||
fn set_wire_hovered_node(&mut self, hover: Option<(NodeId, u64)>, network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], responses: &mut VecDeque<Message>) {
|
||||
let hovered_node = hover.map(|(node_id, _)| node_id);
|
||||
if self.wire_hovered_node.map(|(node_id, _)| node_id) == hovered_node {
|
||||
@@ -2339,11 +2428,7 @@ impl NodeGraphMessageHandler {
|
||||
}
|
||||
self.set_wire_hover_tick_subscribed(false, responses);
|
||||
|
||||
let output_types = self
|
||||
.wire_in_progress_output_connector(network_interface, network_path)
|
||||
.map(|output_connector| network_interface.potential_output_types(&output_connector, network_path))
|
||||
.unwrap_or_default();
|
||||
|
||||
let output_types = self.wire_in_progress_output_types(network_interface, network_path);
|
||||
let revealed_input_indices = (0..network_interface.number_of_inputs(&node_id, network_path))
|
||||
.filter(|&input_index| {
|
||||
let input_connector = InputConnector::node_at_index(node_id, input_index);
|
||||
@@ -2410,6 +2495,24 @@ impl NodeGraphMessageHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/// The types a wire being dragged from an output could carry, used by the Properties panel to mark compatible inputs as drop targets.
|
||||
pub fn wire_in_progress_output_types(&self, network_interface: &NodeNetworkInterface, network_path: &[NodeId]) -> Vec<Type> {
|
||||
// The wire stays visible while the node creation menu is open, but it can no longer be dropped
|
||||
if self.context_menu.is_some() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let Some(WireInProgressAnchor::Output(output_connector)) = self.wire_in_progress_anchor else {
|
||||
return Vec::new();
|
||||
};
|
||||
let output_types = network_interface.potential_output_types(&output_connector, network_path);
|
||||
log::debug!(
|
||||
"[wire-drag] Output {output_connector:?} has type source {:?}, potential types {output_types:?}",
|
||||
network_interface.output_type(&output_connector, network_path)
|
||||
);
|
||||
output_types
|
||||
}
|
||||
|
||||
/// Similar to [`NodeGraphMessageHandler::actions`], but this provides additional actions if the node graph is open and should only be called in that circumstance.
|
||||
pub fn actions_additional_if_node_graph_is_open(&self) -> ActionList {
|
||||
let mut common = actions!(NodeGraphMessageDiscriminant; EnterNestedNetwork, PointerDown, PointerMove, PointerUp, SendClickTargets, EndSendClickTargets);
|
||||
@@ -3201,6 +3304,9 @@ impl Default for NodeGraphMessageHandler {
|
||||
wire_in_progress_from_connector: None,
|
||||
wire_in_progress_to_connector: None,
|
||||
wire_in_progress_type: FrontendGraphDataType::General,
|
||||
wire_in_progress_anchor: None,
|
||||
wire_in_progress_properties_target: None,
|
||||
wire_in_progress_hovering_properties_panel: false,
|
||||
wire_hovered_node: None,
|
||||
wire_expanded_node: None,
|
||||
wire_hover_tick_subscribed: false,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::messages::layout::utility_types::tooltip_markdown::{escape_markdown,
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface};
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface, type_feeds_connector};
|
||||
use crate::messages::portfolio::fonts::utility_types::FontCatalogStyle;
|
||||
use crate::messages::portfolio::ingest::utility_types::{IngestAction, TypeFilter};
|
||||
use crate::messages::prelude::*;
|
||||
@@ -82,10 +82,13 @@ pub fn commit_value<T>(_: &T) -> Message {
|
||||
DocumentMessage::AddTransaction.into()
|
||||
}
|
||||
|
||||
pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphDataType, exposed: bool) -> WidgetInstance {
|
||||
pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphDataType, exposed: bool, wire_drop_target: bool) -> WidgetInstance {
|
||||
ParameterExposeButton::new()
|
||||
.exposed(exposed)
|
||||
.data_type(data_type)
|
||||
.node_id(node_id)
|
||||
.input_index(index as u32)
|
||||
.wire_drop_target(wire_drop_target)
|
||||
.tooltip_description(if exposed {
|
||||
"Stop exposing this parameter as a node input in the graph."
|
||||
} else {
|
||||
@@ -153,6 +156,7 @@ pub fn start_widgets(parameter_widgets_info: &ParameterWidgetsInfo) -> Vec<Widge
|
||||
parameter_widgets_info.index,
|
||||
parameter_widgets_info.input_type,
|
||||
input.is_exposed(),
|
||||
parameter_widgets_info.wire_drop_target,
|
||||
));
|
||||
}
|
||||
widgets.push(
|
||||
@@ -3516,6 +3520,8 @@ pub struct ParameterWidgetsInfo<'a> {
|
||||
input_type: FrontendGraphDataType,
|
||||
blank_assist: bool,
|
||||
exposable: bool,
|
||||
/// Whether a wire being dragged from an output could be connected to this parameter.
|
||||
wire_drop_target: bool,
|
||||
fonts: &'a FontsMessageHandler,
|
||||
}
|
||||
|
||||
@@ -3549,6 +3555,22 @@ impl<'a> ParameterWidgetsInfo<'a> {
|
||||
.displayed_type();
|
||||
let document_node = context.network_interface.document_node(&node_id, context.selection_network_path);
|
||||
|
||||
let wire_drop_target = !context.wire_in_progress_output_types.is_empty()
|
||||
&& context
|
||||
.network_interface
|
||||
.potential_valid_input_types(&InputConnector::node_at_index(node_id, index), context.selection_network_path)
|
||||
.iter()
|
||||
.any(|valid_type| context.wire_in_progress_output_types.iter().any(|output_type| type_feeds_connector(output_type, valid_type)));
|
||||
if !context.wire_in_progress_output_types.is_empty() {
|
||||
let valid_types = context
|
||||
.network_interface
|
||||
.potential_valid_input_types(&InputConnector::node_at_index(node_id, index), context.selection_network_path)
|
||||
.iter()
|
||||
.map(|valid_type| valid_type.nested_type().clone())
|
||||
.collect::<Vec<_>>();
|
||||
log::debug!("[wire-drag] Input {name} ({node_id}, {index}) has valid types {valid_types:?}, drop target: {wire_drop_target}");
|
||||
}
|
||||
|
||||
ParameterWidgetsInfo {
|
||||
document_id: context.document_id,
|
||||
network_interface: context.network_interface,
|
||||
@@ -3563,6 +3585,7 @@ impl<'a> ParameterWidgetsInfo<'a> {
|
||||
input_type,
|
||||
blank_assist,
|
||||
exposable: true,
|
||||
wire_drop_target,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, OutputConnector};
|
||||
use glam::DVec2;
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::{Type, simplify_identifier_name};
|
||||
|
||||
@@ -163,6 +165,19 @@ pub enum ContextMenuData {
|
||||
},
|
||||
}
|
||||
|
||||
/// The connector a wire being dragged starts from, which stays fixed while its other end follows the pointer.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum WireInProgressAnchor {
|
||||
/// Dragged from an output toward a compatible input.
|
||||
Output(OutputConnector),
|
||||
/// Dragged from an input toward a compatible output.
|
||||
Input {
|
||||
input_connector: InputConnector,
|
||||
/// Set when dragged out of the Properties panel, in viewport coordinates, since the input may not be exposed in the graph.
|
||||
properties_panel_position: Option<DVec2>,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ContextMenuInformation {
|
||||
|
||||
+4
@@ -1,3 +1,4 @@
|
||||
use graphene_std::Type;
|
||||
use graphene_std::uuid::NodeId;
|
||||
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
@@ -17,6 +18,7 @@ pub struct PropertiesPanelMessageContext<'a> {
|
||||
pub fonts: &'a FontsMessageHandler,
|
||||
pub properties_panel_open: bool,
|
||||
pub properties_panel_collapsed_sections: &'a [NodeId],
|
||||
pub wire_in_progress_output_types: &'a [Type],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ExtractField)]
|
||||
@@ -35,6 +37,7 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
|
||||
fonts,
|
||||
properties_panel_open,
|
||||
properties_panel_collapsed_sections,
|
||||
wire_in_progress_output_types,
|
||||
} = context;
|
||||
|
||||
match message {
|
||||
@@ -60,6 +63,7 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
|
||||
document_name,
|
||||
fonts,
|
||||
properties_panel_collapsed_sections,
|
||||
wire_in_progress_output_types,
|
||||
};
|
||||
let layout = Layout(NodeGraphMessageHandler::collate_properties(&mut node_properties_context));
|
||||
|
||||
|
||||
+8
@@ -327,12 +327,20 @@ impl NodeNetworkInterface {
|
||||
|
||||
// Nodes outside the compiled graph, such as disconnected ones, have no resolved type
|
||||
let OutputConnector::Node { node_id, output_index: 0 } = output_connector else {
|
||||
log::debug!("[wire-drag] No registry fallback for {output_connector:?}");
|
||||
return Vec::new();
|
||||
};
|
||||
let Some(DocumentNodeImplementation::ProtoNode(proto_node_identifier)) = self.implementation(node_id, network_path) else {
|
||||
log::debug!("[wire-drag] No registry fallback for non-proto node implementation {:?}", self.implementation(node_id, network_path));
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let all_implementations = NODE_REGISTRY.get(proto_node_identifier).map(|implementations| implementations.keys().cloned().collect::<Vec<_>>());
|
||||
let input_types = (0..self.number_of_inputs(node_id, network_path))
|
||||
.map(|index| self.input_type_not_invalid(&InputConnector::node_at_index(*node_id, index), network_path))
|
||||
.collect::<Vec<_>>();
|
||||
log::debug!("[wire-drag] Registry fallback for {proto_node_identifier:?} with input types {input_types:?} among implementations {all_implementations:?}");
|
||||
|
||||
self.implementations_matching_inputs(proto_node_identifier, node_id, None, network_path)
|
||||
.map(|node_io| node_io.return_value.nested_type().clone())
|
||||
.collect()
|
||||
|
||||
@@ -164,7 +164,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<LayoutCol class="properties">
|
||||
<LayoutCol class="properties" data-properties-panel>
|
||||
<LayoutCol class="sections" classes={{ dragging }} scrollableY={true} bind:this={sectionsCol} on:pointerdown={sectionPointerDown}>
|
||||
<WidgetLayout layout={$propertiesPanelLayout} layoutTarget="PropertiesPanel" />
|
||||
{#if dragging && insertMarkerTop !== undefined}
|
||||
|
||||
@@ -716,15 +716,6 @@
|
||||
{/if}
|
||||
{/each}
|
||||
{/each}
|
||||
{#if $nodeGraph.wirePathInProgress}
|
||||
<path
|
||||
d={$nodeGraph.wirePathInProgress?.pathString}
|
||||
style:--data-line-width={`${$nodeGraph.wirePathInProgress.thick ? 8 : 2}px`}
|
||||
style:--data-color={`var(--color-data-${$nodeGraph.wirePathInProgress.dataType.toLowerCase()})`}
|
||||
style:--data-color-dim={`var(--color-data-${$nodeGraph.wirePathInProgress.dataType.toLowerCase()}-dim)`}
|
||||
style:--data-dasharray={`3,${$nodeGraph.wirePathInProgress.dashed ? 2 : 0}`}
|
||||
/>
|
||||
{/if}
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from "svelte";
|
||||
import type { NodeGraphStore } from "/src/stores/node-graph";
|
||||
|
||||
const nodeGraph = getContext<NodeGraphStore>("nodeGraph");
|
||||
const nodeGraphTransform = nodeGraph.transformStore;
|
||||
|
||||
// The wire is drawn above every panel so it can reach connectors in the Properties panel, which means mapping graph space onto the window ourselves
|
||||
$: wirePath = $nodeGraph.wirePathInProgress;
|
||||
$: graphBounds = wirePath && document.querySelector("[data-node-graph]")?.getBoundingClientRect();
|
||||
$: offsetX = (graphBounds?.left || 0) + $nodeGraphTransform.x;
|
||||
$: offsetY = (graphBounds?.top || 0) + $nodeGraphTransform.y;
|
||||
</script>
|
||||
|
||||
{#if wirePath && graphBounds}
|
||||
<svg class="wire-in-progress">
|
||||
<path
|
||||
d={wirePath.pathString}
|
||||
transform={`translate(${offsetX} ${offsetY}) scale(${$nodeGraphTransform.scale})`}
|
||||
style:--data-line-width={`${wirePath.thick ? 8 : 2}px`}
|
||||
style:--data-color={`var(--color-data-${wirePath.dataType.toLowerCase()})`}
|
||||
style:--data-color-dim={`var(--color-data-${wirePath.dataType.toLowerCase()}-dim)`}
|
||||
style:--data-dasharray={`3,${wirePath.dashed ? 2 : 0}`}
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.wire-in-progress {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
overflow: visible;
|
||||
z-index: 1000;
|
||||
|
||||
path {
|
||||
fill: none;
|
||||
stroke: var(--data-color-dim);
|
||||
stroke-width: var(--data-line-width);
|
||||
stroke-dasharray: var(--data-dasharray);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,30 +1,54 @@
|
||||
<script lang="ts">
|
||||
import LayoutRow from "/src/components/layout/LayoutRow.svelte";
|
||||
import { consumeConnectorClickSuppression, hoveredWireDropTarget, pressPropertiesPanelConnector } from "/src/utility-functions/wire-drag";
|
||||
import type { FrontendGraphDataType, ActionShortcut } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
|
||||
// Content
|
||||
export let exposed: boolean;
|
||||
export let dataType: FrontendGraphDataType;
|
||||
export let nodeId: bigint;
|
||||
export let inputIndex: number;
|
||||
export let wireDropTarget: boolean;
|
||||
// Tooltips
|
||||
export let tooltipLabel: string | undefined = undefined;
|
||||
export let tooltipDescription: string | undefined = undefined;
|
||||
export let tooltipShortcut: ActionShortcut | undefined = undefined;
|
||||
// Callbacks
|
||||
export let action: (e?: MouseEvent) => void;
|
||||
|
||||
$: wireHovering = wireDropTarget && $hoveredWireDropTarget?.nodeId === nodeId && $hoveredWireDropTarget?.inputIndex === inputIndex;
|
||||
|
||||
function click(e: MouseEvent) {
|
||||
// A press that turned into dragging a wire out of this connector shouldn't also toggle its exposure
|
||||
if (consumeConnectorClickSuppression()) return;
|
||||
|
||||
action(e);
|
||||
}
|
||||
</script>
|
||||
|
||||
<LayoutRow class="parameter-expose-button">
|
||||
<button
|
||||
class:exposed
|
||||
class:wire-drop-target={wireDropTarget}
|
||||
class:wire-hovering={wireHovering}
|
||||
style:--data-type-color={`var(--color-data-${dataType.toLowerCase()})`}
|
||||
style:--data-type-color-dim={`var(--color-data-${dataType.toLowerCase()}-dim)`}
|
||||
on:click={action}
|
||||
on:pointerdown={(e) => pressPropertiesPanelConnector(e, { nodeId, inputIndex })}
|
||||
on:click={click}
|
||||
data-wire-drop-target={wireDropTarget || undefined}
|
||||
data-node-id={String(nodeId)}
|
||||
data-input-index={inputIndex}
|
||||
data-tooltip-label={tooltipLabel}
|
||||
data-tooltip-description={tooltipDescription}
|
||||
data-tooltip-shortcut={tooltipShortcut?.shortcut ? JSON.stringify(tooltipShortcut.shortcut) : undefined}
|
||||
tabindex="-1"
|
||||
>
|
||||
{#if !exposed}
|
||||
{#if exposed || wireHovering}
|
||||
<!-- Same shape as an input connector in the node graph -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8">
|
||||
<path class="interior" d="M0,6.306A1.474,1.474,0,0,0,2.356,7.724L7.028,5.248c1.3-.687,1.3-1.809,0-2.5L2.356.276A1.474,1.474,0,0,0,0,1.694Z" />
|
||||
</svg>
|
||||
{:else}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8">
|
||||
<circle class="interior" r="3" cx="4" cy="4" />
|
||||
<path
|
||||
@@ -32,14 +56,6 @@
|
||||
d="M4,1C5.656,1 7,2.344 7,4C7,5.656 5.656,7 4,7C2.344,7 1,5.656 1,4C1,2.344 2.344,1 4,1ZM4,2C2.896,2 2,2.896 2,4C2,5.104 2.896,6 4,6C5.104,6 6,5.104 6,4C6,2.896 5.104,2 4,2z"
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8">
|
||||
<path class="interior" d="M0,6.306L0,1.694C0,0.228 1.06,-0.41 2.356,0.276L7.028,2.752C8.324,3.438 8.324,4.562 7.028,5.248L2.356,7.723C1.06,8.41 0,7.771 0,6.306z" />
|
||||
<path
|
||||
class="outline"
|
||||
d="M1.364,8C0.56,8 0,7.372 0,6.306L0,1.694C0,0.228 1.06,-0.41 2.356,0.276L7.028,2.752C8.324,3.439 8.324,4.561 7.028,5.248L2.356,7.724C2.002,7.911 1.666,8 1.364,8ZM1.364,7.2C1.542,7.2 1.756,7.137 1.981,7.017L6.653,4.541C7.031,4.341 7.2,4.125 7.2,4C7.2,3.875 7.031,3.659 6.653,3.459L1.982,0.983C1.756,0.863 1.542,0.8 1.364,0.8C0.873,0.8 0.8,1.36 0.8,1.694L0.8,6.306C0.8,6.64 0.873,7.2 1.364,7.2z"
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
</LayoutRow>
|
||||
@@ -52,6 +68,7 @@
|
||||
max-height: 24px;
|
||||
|
||||
button {
|
||||
position: relative;
|
||||
flex: 0 0 auto;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
@@ -62,6 +79,18 @@
|
||||
fill: none;
|
||||
stroke: none;
|
||||
|
||||
// Enlarges the area for grabbing the connector or dropping a wire onto it, without affecting the row layout
|
||||
&::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: -4px;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.outline {
|
||||
fill: none;
|
||||
}
|
||||
@@ -70,7 +99,7 @@
|
||||
fill: var(--data-type-color);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
&:hover:not(.exposed) {
|
||||
.outline {
|
||||
fill: var(--data-type-color);
|
||||
}
|
||||
@@ -79,6 +108,33 @@
|
||||
fill: var(--data-type-color-dim);
|
||||
}
|
||||
}
|
||||
|
||||
&.exposed:hover {
|
||||
.interior {
|
||||
fill: var(--data-type-color-dim);
|
||||
stroke: var(--data-type-color);
|
||||
stroke-width: 1px;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
}
|
||||
|
||||
// Rings each connector that the wire being dragged could be dropped onto
|
||||
&.wire-drop-target::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: -4px;
|
||||
border: 1px solid var(--data-type-color);
|
||||
border-radius: 50%;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
// Previews the connection the dragged wire would make if dropped here
|
||||
&.wire-hovering .interior {
|
||||
fill: var(--data-type-color);
|
||||
stroke: var(--color-f-white);
|
||||
stroke-width: 1px;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -4,6 +4,7 @@
|
||||
import Tooltip from "/src/components/floating-menus/Tooltip.svelte";
|
||||
import LayoutCol from "/src/components/layout/LayoutCol.svelte";
|
||||
import LayoutRow from "/src/components/layout/LayoutRow.svelte";
|
||||
import WireInProgress from "/src/components/views/WireInProgress.svelte";
|
||||
import TextLabel from "/src/components/widgets/labels/TextLabel.svelte";
|
||||
import PanelSubdivision from "/src/components/window/PanelSubdivision.svelte";
|
||||
import StatusBar from "/src/components/window/StatusBar.svelte";
|
||||
@@ -27,6 +28,7 @@
|
||||
<PanelSubdivision subdivision={$portfolio.panelLayout.root} depth={0} />
|
||||
</LayoutRow>
|
||||
<StatusBar />
|
||||
<WireInProgress />
|
||||
{#if $dialog.visible}
|
||||
<Dialog />
|
||||
{/if}
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { PortfolioStore } from "/src/stores/portfolio";
|
||||
import { pasteFile } from "/src/utility-functions/files";
|
||||
import { makeKeyboardModifiersBitfield, textInputCleanup, getLocalizedScanCode } from "/src/utility-functions/keyboard-entry";
|
||||
import { operatingSystem } from "/src/utility-functions/platform";
|
||||
import { wireDragPointerMove, wireDragPointerUp } from "/src/utility-functions/wire-drag";
|
||||
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
|
||||
const BUTTON_LEFT = 0;
|
||||
@@ -121,13 +122,16 @@ export function onPointerMove(e: PointerEvent, editor: EditorWrapper, documentSt
|
||||
|
||||
if (isObserveOnly(e)) return;
|
||||
|
||||
// Wire dragging to and from the Properties panel must be resolved before the editor processes this movement
|
||||
const graphViewOverlayOpen = get(documentStore).graphViewOverlayOpen;
|
||||
if (wireDragPointerMove(e, editor, graphViewOverlayOpen, viewportPointerInteractionOngoing)) viewportPointerInteractionOngoing = true;
|
||||
|
||||
// Don't redirect pointer movement to the backend if there's no ongoing interaction and it's over a floating menu, or the graph overlay, on top of the canvas
|
||||
// TODO: A better approach is to pass along a boolean to the backend's input preprocessor so it can know if it's being occluded by the GUI.
|
||||
// TODO: This would allow it to properly decide to act on removing hover focus from something that was hovered in the canvas before moving over the GUI.
|
||||
// TODO: Further explanation: https://github.com/GraphiteEditor/Graphite/pull/623#discussion_r866436197
|
||||
const inFloatingMenu = e.target instanceof Element && e.target.closest("[data-floating-menu-content]");
|
||||
const inGraphOverlay = get(documentStore).graphViewOverlayOpen;
|
||||
if (!viewportPointerInteractionOngoing && (inFloatingMenu || inGraphOverlay)) return;
|
||||
if (!viewportPointerInteractionOngoing && (inFloatingMenu || graphViewOverlayOpen)) return;
|
||||
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
if (detectShake(e)) editor.onMouseShake(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
@@ -183,6 +187,8 @@ export function onPointerUp(e: PointerEvent, editor: EditorWrapper) {
|
||||
|
||||
if (isObserveOnly(e) || textToolInteractiveInputElement) return;
|
||||
|
||||
wireDragPointerUp(e, editor);
|
||||
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.onMouseUp(e.clientX, e.clientY, e.buttons, modifiers, ...pointerAttributes(e));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import { writable } from "svelte/store";
|
||||
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
|
||||
// Wire dragging between the node graph and the input connectors shown in the Properties panel.
|
||||
// The graph's pointer capture hides hover from the panel's DOM, so the connector under the pointer is found by hit-testing instead.
|
||||
|
||||
export type PropertiesPanelConnector = { nodeId: bigint; inputIndex: number };
|
||||
|
||||
const DRAG_OUT_THRESHOLD = 4;
|
||||
|
||||
// The Properties panel connector that a wire dragged from the graph is hovering, which renders as a connector awaiting the drop
|
||||
export const hoveredWireDropTarget = writable<PropertiesPanelConnector | undefined>(undefined);
|
||||
|
||||
let pressedConnector: (PropertiesPanelConnector & { element: Element; startX: number; startY: number }) | undefined = undefined;
|
||||
let draggingOutOfPropertiesPanel = false;
|
||||
let suppressNextClick = false;
|
||||
|
||||
let reportedHoveringPanel = false;
|
||||
let reportedTarget: PropertiesPanelConnector | undefined = undefined;
|
||||
|
||||
export function pressPropertiesPanelConnector(e: PointerEvent, connector: PropertiesPanelConnector) {
|
||||
if (e.button !== 0 || !(e.currentTarget instanceof Element)) return;
|
||||
|
||||
pressedConnector = { ...connector, element: e.currentTarget, startX: e.clientX, startY: e.clientY };
|
||||
suppressNextClick = false;
|
||||
}
|
||||
|
||||
// Whether the click ending a press should be ignored because the press became a wire drag
|
||||
export function consumeConnectorClickSuppression(): boolean {
|
||||
const suppress = suppressNextClick;
|
||||
suppressNextClick = false;
|
||||
return suppress;
|
||||
}
|
||||
|
||||
// Returns true when this movement begins dragging a wire out of a Properties panel connector, which makes it a pointer interaction the editor must receive
|
||||
export function wireDragPointerMove(e: PointerEvent, editor: EditorWrapper, graphViewOverlayOpen: boolean, interactionOngoing: boolean): boolean {
|
||||
let started = false;
|
||||
|
||||
// Begin dragging out of a pressed connector once the pointer has moved far enough that it's no longer a click
|
||||
if (pressedConnector && !draggingOutOfPropertiesPanel && e.buttons) {
|
||||
const distance = Math.hypot(e.clientX - pressedConnector.startX, e.clientY - pressedConnector.startY);
|
||||
if (distance > DRAG_OUT_THRESHOLD && graphViewOverlayOpen) {
|
||||
const [x, y] = elementCenter(pressedConnector.element);
|
||||
editor.startWireFromPropertiesPanel(pressedConnector.nodeId, pressedConnector.inputIndex, x, y);
|
||||
|
||||
draggingOutOfPropertiesPanel = true;
|
||||
reportedHoveringPanel = true;
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!graphViewOverlayOpen || !e.buttons || !(interactionOngoing || started)) return started;
|
||||
|
||||
// Find which Properties panel connector, if any, is under the pointer
|
||||
const topmost = document.elementFromPoint(e.clientX, e.clientY);
|
||||
const hoveringPanel = Boolean(topmost?.closest("[data-properties-panel]"));
|
||||
const targetElement = topmost?.closest("[data-wire-drop-target]") || undefined;
|
||||
const target = targetElement && connectorFromElement(targetElement);
|
||||
|
||||
if (hoveringPanel) {
|
||||
const dropTargets = Array.from(document.querySelectorAll("[data-wire-drop-target]")).map((element) => ({ element, bounds: element.getBoundingClientRect() }));
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug("[wire-drag] Hit test", { pointer: [e.clientX, e.clientY], topmost, elementsAtPoint: document.elementsFromPoint(e.clientX, e.clientY), dropTargets });
|
||||
}
|
||||
|
||||
const targetChanged = target?.nodeId !== reportedTarget?.nodeId || target?.inputIndex !== reportedTarget?.inputIndex;
|
||||
if (hoveringPanel === reportedHoveringPanel && !targetChanged) return started;
|
||||
|
||||
reportedHoveringPanel = hoveringPanel;
|
||||
reportedTarget = target;
|
||||
hoveredWireDropTarget.set(target);
|
||||
|
||||
const [x, y] = targetElement ? elementCenter(targetElement) : [0, 0];
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug("[wire-drag] Reporting hover", { hoveringPanel, target, topmost, dropTargetsInDocument: document.querySelectorAll("[data-wire-drop-target]").length });
|
||||
editor.setWirePropertiesPanelHover(hoveringPanel, target?.nodeId, target?.inputIndex ?? 0, x, y);
|
||||
|
||||
return started;
|
||||
}
|
||||
|
||||
export function wireDragPointerUp(e: PointerEvent, editor: EditorWrapper) {
|
||||
if (e.buttons) return;
|
||||
|
||||
// The editor never saw the pointer go down in the Properties panel, so it needs to be told about the release
|
||||
if (draggingOutOfPropertiesPanel) {
|
||||
editor.releaseWireFromPropertiesPanel();
|
||||
suppressNextClick = true;
|
||||
}
|
||||
|
||||
pressedConnector = undefined;
|
||||
draggingOutOfPropertiesPanel = false;
|
||||
reportedHoveringPanel = false;
|
||||
reportedTarget = undefined;
|
||||
hoveredWireDropTarget.set(undefined);
|
||||
}
|
||||
|
||||
function connectorFromElement(element: Element): PropertiesPanelConnector | undefined {
|
||||
const nodeId = element.getAttribute("data-node-id") || undefined;
|
||||
const inputIndex = element.getAttribute("data-input-index") || undefined;
|
||||
if (nodeId === undefined || inputIndex === undefined) return undefined;
|
||||
|
||||
return { nodeId: BigInt(nodeId), inputIndex: Number(inputIndex) };
|
||||
}
|
||||
|
||||
function elementCenter(element: Element): [number, number] {
|
||||
const bounds = element.getBoundingClientRect();
|
||||
return [bounds.left + bounds.width / 2, bounds.top + bounds.height / 2];
|
||||
}
|
||||
@@ -19,7 +19,7 @@ mod editor_commands {
|
||||
use editor::messages::input_mapper::utility_types::pointer::{EditorPointerState, ScrollDelta};
|
||||
use editor::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
|
||||
use editor::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use editor::messages::portfolio::document::utility_types::network_interface::ImportOrExport;
|
||||
use editor::messages::portfolio::document::utility_types::network_interface::{ImportOrExport, InputConnector};
|
||||
use editor::messages::portfolio::utility_types::PanelGroupId;
|
||||
use editor::messages::prelude::*;
|
||||
use editor::messages::tool::tool_messages::tool_prelude::{DroppedFile, WidgetId};
|
||||
@@ -664,6 +664,26 @@ mod editor_commands {
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Begin dragging a wire out of a Properties panel input connector, anchored at its center
|
||||
fn start_wire_from_properties_panel(node_id: u64, input_index: usize, x: f64, y: f64) -> Message {
|
||||
NodeGraphMessage::StartWireFromPropertiesPanel {
|
||||
input_connector: InputConnector::node_at_index(NodeId(node_id), input_index),
|
||||
editor_position: (x, y).into(),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Release a wire dragged out of the Properties panel, whose pointer down never reached the editor
|
||||
fn release_wire_from_properties_panel() -> Message {
|
||||
NodeGraphMessage::PointerUp.into()
|
||||
}
|
||||
|
||||
/// Report whether the wire in progress is over the Properties panel, and which input connector there it hovers (centered at `x`, `y`)
|
||||
fn set_wire_properties_panel_hover(hovering_panel: bool, target_node_id: Option<u64>, target_input_index: usize, x: f64, y: f64) -> Message {
|
||||
let target = target_node_id.map(|node_id| (InputConnector::node_at_index(NodeId(node_id), target_input_index), (x, y).into()));
|
||||
NodeGraphMessage::SetWirePropertiesPanelHover { hovering_panel, target }.into()
|
||||
}
|
||||
|
||||
/// Respond to selection read
|
||||
fn read_selection(content: Option<String>, cut: bool) -> Message {
|
||||
ClipboardMessage::ReadSelection { content, cut }.into()
|
||||
|
||||
Reference in new issue
Block a user