diff --git a/editor/src/messages/portfolio/document/node_graph/node_properties.rs b/editor/src/messages/portfolio/document/node_graph/node_properties.rs index b3ed309d3f..eb08935e7c 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_properties.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_properties.rs @@ -4,7 +4,7 @@ use super::document_node_definitions::{NODE_OVERRIDES, NodePropertiesContext}; use super::utility_types::FrontendGraphDataType; 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::network_interface::InputConnector; +use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface}; use crate::messages::portfolio::utility_types::{FontCatalogStyle, PersistentData}; use crate::messages::prelude::*; use choice::enum_choice; @@ -79,6 +79,29 @@ pub fn add_blank_assist(widgets: &mut Vec) { ]); } +pub fn jump_to_source_widget(input: &NodeInput, network_interface: &NodeNetworkInterface, selection_network_path: &[NodeId]) -> WidgetInstance { + match input { + NodeInput::Node { node_id: source_id, .. } => { + let source_id = *source_id; + let node_name = network_interface.implementation_name(&source_id, selection_network_path); + TextButton::new(format!("From Graph ({})", node_name)) + .tooltip_description("Click to select the node producing this parameter's data.") + .on_update(move |_| NodeGraphMessage::SelectedNodesSet { nodes: vec![source_id] }.into()) + .widget_instance() + } + _ => TextLabel::new("From Graph (Disconnected)") + .tooltip_description( + " + This parameter is exposed as an input in the node graph, but not currently receiving data from any node.\n\ + \n\ + In the graph, drag a wire out from a compatible output connector of another node, and feed it into the input connector of this exposed node parameter. Alternatively, un-expose this parameter by clicking the triangle directly to the left of here. + " + .trim(), + ) + .widget_instance(), + } +} + pub fn start_widgets(parameter_widgets_info: ParameterWidgetsInfo) -> Vec { let ParameterWidgetsInfo { document_node, @@ -89,6 +112,8 @@ pub fn start_widgets(parameter_widgets_info: ParameterWidgetsInfo) -> Vec Vec { + let is_exposed = default_info.is_exposed(); + let mut widgets = start_widgets(default_info); - widgets.extend_from_slice(&[ - Separator::new(SeparatorStyle::Unrelated).widget_instance(), - TextLabel::new("-") - .tooltip_label(format!("Data Type: {concrete_type}")) - .tooltip_description("This data can only be supplied through the node graph because no widget exists for its type.") - .widget_instance(), - ]); + + if !is_exposed { + widgets.extend_from_slice(&[ + Separator::new(SeparatorStyle::Unrelated).widget_instance(), + TextLabel::new("-") + .tooltip_label(format!("Data Type: {concrete_type}")) + .tooltip_description("This data can only be supplied through the node graph because no widget exists for its type.") + .widget_instance(), + ]); + } return Err(vec![widgets.into()]); } } @@ -2144,6 +2185,8 @@ pub fn math_properties(node_id: NodeId, context: &mut NodePropertiesContext) -> pub struct ParameterWidgetsInfo<'a> { persistent_data: &'a PersistentData, + network_interface: &'a NodeNetworkInterface, + selection_network_path: &'a [NodeId], document_node: Option<&'a DocumentNode>, node_id: NodeId, index: usize, @@ -2165,6 +2208,8 @@ impl<'a> ParameterWidgetsInfo<'a> { ParameterWidgetsInfo { persistent_data: context.persistent_data, + network_interface: context.network_interface, + selection_network_path: context.selection_network_path, document_node, node_id, index, @@ -2175,6 +2220,10 @@ impl<'a> ParameterWidgetsInfo<'a> { exposable: true, } } + + pub fn is_exposed(&self) -> bool { + self.document_node.and_then(|node| node.inputs.get(self.index)).map(|input| input.is_exposed()).unwrap_or(false) + } } pub mod choice {