mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 15:53:26 -10:00
Expand nodes to reveal compatible hidden inputs while hovering them with a dragged wire (#4670)
* Expand nodes to reveal compatible hidden inputs while hovering them with a dragged wire * Treat underscore-named parameters as internal state never exposed to the graph * Show exposed optional-parameter toggles as their own Inspector rows * Skip layers when expanding nodes hovered by a dragged wire * Stop previewing hidden inputs on wire hover from creating empty undo steps * Don't expand nodes upstream of a dragged wire's source, which would form a cycle * End a wire drag when its graph is closed or its document is left mid-drag * Abort the left document's wire drag and harden the internal parameter rule --------- Co-authored-by: Keavon Chambers <[email protected]>
This commit is contained in:
1 parent
a4ed8f0031
commit
0f915cfbb3
17 files changed
+413
-104
No files matched your search
@@ -37,6 +37,8 @@ pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f64 = 0.95;
|
||||
|
||||
pub const DRAG_BEYOND_VIEWPORT_MAX_OVEREXTENSION_PIXELS: f64 = 50.;
|
||||
pub const DRAG_BEYOND_VIEWPORT_SPEED_FACTOR: f64 = 20.;
|
||||
/// How long a dragged wire must rest over a node before the node reveals its hidden inputs the wire could connect to.
|
||||
pub const WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS: u64 = 250;
|
||||
|
||||
// SNAPPING POINT
|
||||
pub const SNAP_POINT_TOLERANCE: f64 = 5.;
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::messages::portfolio::document::graph_operation::utility_types::{Modif
|
||||
use crate::messages::portfolio::document::inspector::inspector_message_handler::InspectorMessageContext;
|
||||
use crate::messages::portfolio::document::node_graph::NodeGraphMessageContext;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
|
||||
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
|
||||
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings, Pivot};
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
|
||||
@@ -642,11 +641,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
}
|
||||
// Abort wire in progress of being connected
|
||||
else if self.node_graph_handler.wire_in_progress_from_connector.is_some() {
|
||||
self.node_graph_handler.wire_in_progress_from_connector = None;
|
||||
self.node_graph_handler.wire_in_progress_to_connector = None;
|
||||
self.node_graph_handler.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
self.node_graph_handler.end_wire_in_progress(&mut self.network_interface, &self.selection_network_path, responses);
|
||||
responses.add(DocumentMessage::AbortTransaction);
|
||||
}
|
||||
// Close the context menu if it's open
|
||||
@@ -751,6 +746,11 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
responses.add(NodeGraphMessage::UpdateHints);
|
||||
} else {
|
||||
// The closed graph won't get the pointer up that ends a wire drag, so abandon it as Escape would
|
||||
if self.end_node_graph_wire_in_progress(responses) {
|
||||
responses.add(DocumentMessage::AbortTransaction);
|
||||
}
|
||||
|
||||
responses.add(ToolMessage::ActivateTool { tool_type: *current_tool });
|
||||
responses.add(OverlaysMessage::Draw); // Redraw overlays when graph is closed
|
||||
}
|
||||
@@ -2803,6 +2803,16 @@ impl DocumentMessageHandler {
|
||||
self.graph_view_overlay_open
|
||||
}
|
||||
|
||||
/// Ends any wire being dragged in the node graph, collapsing a node expanded for it, and returns whether there was one.
|
||||
pub fn end_node_graph_wire_in_progress(&mut self, responses: &mut VecDeque<Message>) -> bool {
|
||||
if self.node_graph_handler.wire_in_progress_from_connector.is_none() {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.node_graph_handler.end_wire_in_progress(&mut self.network_interface, &self.selection_network_path, responses);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn set_auto_save_state(&mut self, is_saved: bool) {
|
||||
if is_saved {
|
||||
self.auto_saved_hash = Some(self.current_hash());
|
||||
|
||||
@@ -866,7 +866,14 @@ static INPUT_OVERRIDES: once_cell::sync::Lazy<InputInspector> = once_cell::sync:
|
||||
/// Defines the logic for inputs to display a custom Inspector widget.
|
||||
fn static_input_inspector() -> InputInspector {
|
||||
let mut map: InputInspector = HashMap::new();
|
||||
map.insert("hidden".to_string(), Box::new(|_node_id, _index, _context| Ok(Vec::new())));
|
||||
map.insert(
|
||||
"hidden".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
Ok(node_inspector::exposed_parameter_row(&ParameterWidgetsInfo::at_index(node_id, index, true, context))
|
||||
.into_iter()
|
||||
.collect())
|
||||
}),
|
||||
);
|
||||
map.insert(
|
||||
"string".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
|
||||
@@ -137,6 +137,8 @@ pub enum NodeGraphMessage {
|
||||
PointerOutsideViewport {
|
||||
shift: Key,
|
||||
},
|
||||
/// Sent every frame while a dragged wire hovers a node, to expand it once the hover delay passes.
|
||||
WireHoverTick,
|
||||
ShakeNode,
|
||||
UpdateNodeGraphWidth,
|
||||
RemoveImport {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::node_inspector;
|
||||
use super::utility_types::{BoxSelection, ContextMenuInformation, DragStart, FrontendNode};
|
||||
use crate::consts::GRID_SIZE;
|
||||
use crate::consts::{GRID_SIZE, WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS};
|
||||
use crate::messages::input_mapper::utility_types::macros::{action_shortcut, action_shortcut_manual};
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::document_message_handler::navigation_controls;
|
||||
@@ -11,7 +11,9 @@ use crate::messages::portfolio::document::node_graph::document_node_definitions:
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic};
|
||||
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::{self, FlowType, InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata, OutputConnector, Previewing, RootNode};
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{
|
||||
self, FlowType, InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata, OutputConnector, Previewing, RootNode, TransactionCheckpoint, type_feeds_connector,
|
||||
};
|
||||
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelChainInsertion, LayerPanelChainNode, LayerPanelEntry};
|
||||
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
|
||||
use crate::messages::prelude::*;
|
||||
@@ -86,6 +88,12 @@ 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.
|
||||
wire_hovered_node: Option<(NodeId, u64)>,
|
||||
/// The node expanded for the wire in progress, the indices of the inputs it temporarily exposed, and the prior transaction state.
|
||||
wire_expanded_node: Option<(NodeId, Vec<usize>, TransactionCheckpoint)>,
|
||||
/// Whether [`NodeGraphMessage::WireHoverTick`] is subscribed to animation frames.
|
||||
wire_hover_tick_subscribed: bool,
|
||||
/// State for the context menus.
|
||||
pub context_menu: Option<ContextMenuInformation>,
|
||||
/// Index of selected node to be deselected on pointer up when shift clicking an already selected node
|
||||
@@ -354,12 +362,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
|
||||
self.wire_in_progress_from_connector = None;
|
||||
self.wire_in_progress_to_connector = None;
|
||||
self.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
}
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
self.end_wire_in_progress(network_interface, selection_network_path, responses);
|
||||
responses.add(FrontendMessage::UpdateContextMenuInformation {
|
||||
context_menu_information: self.context_menu.clone(),
|
||||
});
|
||||
@@ -860,12 +864,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
}
|
||||
// Abort dragging a wire
|
||||
if self.wire_in_progress_from_connector.is_some() {
|
||||
self.wire_in_progress_from_connector = None;
|
||||
self.wire_in_progress_to_connector = None;
|
||||
self.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
|
||||
self.end_wire_in_progress(network_interface, selection_network_path, responses);
|
||||
responses.add(DocumentMessage::AbortTransaction);
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -967,14 +967,11 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
// Since the user is clicking elsewhere in the graph, ensure the add nodes list is closed
|
||||
if self.context_menu.is_some() {
|
||||
self.context_menu = None;
|
||||
self.wire_in_progress_from_connector = None;
|
||||
self.wire_in_progress_to_connector = None;
|
||||
self.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
self.end_wire_in_progress(network_interface, selection_network_path, responses);
|
||||
|
||||
responses.add(FrontendMessage::UpdateContextMenuInformation {
|
||||
context_menu_information: self.context_menu.clone(),
|
||||
});
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
}
|
||||
|
||||
// Toggle visibility of clicked node and return
|
||||
@@ -1207,6 +1204,14 @@ 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_hovered_node = to_connector
|
||||
.and_then(|input_connector| input_connector.node_id())
|
||||
.or_else(|| network_interface.node_from_click(viewport_location, selection_network_path))
|
||||
// Exposing a parameter of a layer would turn it into a node
|
||||
.filter(|node_id| !network_interface.is_layer(node_id, selection_network_path));
|
||||
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 {
|
||||
*dragged = true;
|
||||
@@ -1332,6 +1337,11 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
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);
|
||||
|
||||
// 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,
|
||||
@@ -1535,15 +1545,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.duplicated_in_drag = false;
|
||||
self.box_selection_start = None;
|
||||
|
||||
self.wire_in_progress_from_connector = None;
|
||||
self.wire_in_progress_to_connector = None;
|
||||
self.wire_in_progress_type = FrontendGraphDataType::General;
|
||||
self.end_wire_in_progress(network_interface, selection_network_path, responses);
|
||||
|
||||
self.reordering_export = None;
|
||||
self.reordering_import = None;
|
||||
|
||||
responses.add(DocumentMessage::EndTransaction);
|
||||
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
|
||||
responses.add(FrontendMessage::UpdateBox { box_selection: None });
|
||||
responses.add(FrontendMessage::UpdateImportReorderIndex { index: None });
|
||||
responses.add(FrontendMessage::UpdateExportReorderIndex { index: None });
|
||||
@@ -1558,6 +1565,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.auto_panning.stop(&messages, responses);
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::WireHoverTick => {
|
||||
self.expand_wire_hovered_node_after_delay(ipp.time, network_interface, selection_network_path, responses);
|
||||
}
|
||||
NodeGraphMessage::ShakeNode => {
|
||||
let Some((drag_start, _)) = &mut self.drag_start else {
|
||||
log::error!("Drag start should be initialized when shaking a node");
|
||||
@@ -2295,6 +2305,141 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
}
|
||||
|
||||
impl NodeGraphMessageHandler {
|
||||
/// Removes the wire in progress 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>) {
|
||||
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;
|
||||
|
||||
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.
|
||||
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 {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.wire_expanded_node.as_ref().is_some_and(|(node_id, _, _)| Some(*node_id) != hovered_node) {
|
||||
self.collapse_wire_expanded_node(None, network_interface, network_path, responses);
|
||||
}
|
||||
|
||||
self.wire_hovered_node = hover;
|
||||
self.set_wire_hover_tick_subscribed(hover.is_some(), responses);
|
||||
}
|
||||
|
||||
/// Expands the hovered node once the wire has rested over it for the hover delay.
|
||||
fn expand_wire_hovered_node_after_delay(&mut self, time: u64, network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], responses: &mut VecDeque<Message>) {
|
||||
let Some((node_id, hover_start_time)) = self.wire_hovered_node else { return };
|
||||
if time.saturating_sub(hover_start_time) < WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS {
|
||||
return;
|
||||
}
|
||||
self.set_wire_hover_tick_subscribed(false, responses);
|
||||
|
||||
let Some(output_connector) = self.wire_in_progress_output_connector(network_interface, network_path) else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Connecting the wire to its source node, or to any node upstream of it, would form a cycle
|
||||
if let OutputConnector::Node { node_id: source_node_id, .. } = output_connector
|
||||
&& network_interface
|
||||
.upstream_flow_back_from_nodes(vec![source_node_id], network_path, FlowType::UpstreamFlow)
|
||||
.any(|upstream_node_id| upstream_node_id == node_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let output_types = network_interface.potential_output_types(&output_connector, 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);
|
||||
let hidden_value = matches!(network_interface.input_from_connector(&input_connector, network_path), Some(NodeInput::Value { exposed: false, .. }));
|
||||
|
||||
hidden_value
|
||||
&& !network_interface.is_internal_input(&node_id, input_index, network_path)
|
||||
&& network_interface
|
||||
.potential_valid_input_types(&input_connector, network_path)
|
||||
.iter()
|
||||
.any(|valid_type| output_types.iter().any(|output_type| type_feeds_connector(output_type, valid_type)))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if revealed_input_indices.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let transaction_checkpoint = network_interface.transaction_checkpoint();
|
||||
for &input_index in &revealed_input_indices {
|
||||
Self::set_value_input_exposed(InputConnector::node_at_index(node_id, input_index), true, network_interface, network_path);
|
||||
}
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
|
||||
self.wire_expanded_node = Some((node_id, revealed_input_indices, transaction_checkpoint));
|
||||
}
|
||||
|
||||
/// Hides the inputs revealed by the expanded node again, except `connected_input`.
|
||||
fn collapse_wire_expanded_node(&mut self, connected_input: Option<InputConnector>, network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], responses: &mut VecDeque<Message>) {
|
||||
let Some((node_id, revealed_input_indices, transaction_checkpoint)) = self.wire_expanded_node.take() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut connecting_revealed_input = false;
|
||||
for &input_index in &revealed_input_indices {
|
||||
let input_connector = InputConnector::node_at_index(node_id, input_index);
|
||||
if Some(input_connector) == connected_input {
|
||||
connecting_revealed_input = true;
|
||||
} else {
|
||||
Self::set_value_input_exposed(input_connector, false, network_interface, network_path);
|
||||
}
|
||||
}
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
|
||||
// Unless the wire connects to one of them, the reveal was only a preview and isn't an edit
|
||||
if !connecting_revealed_input {
|
||||
network_interface.restore_transaction_checkpoint(transaction_checkpoint);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_value_input_exposed(input_connector: InputConnector, exposed: bool, network_interface: &mut NodeNetworkInterface, network_path: &[NodeId]) {
|
||||
let Some(mut input) = network_interface.input_from_connector(&input_connector, network_path).cloned() else {
|
||||
return;
|
||||
};
|
||||
let NodeInput::Value { exposed: input_exposed, .. } = &mut input else { return };
|
||||
|
||||
*input_exposed = exposed;
|
||||
network_interface.set_input(&input_connector, input, network_path);
|
||||
}
|
||||
|
||||
fn set_wire_hover_tick_subscribed(&mut self, subscribed: bool, responses: &mut VecDeque<Message>) {
|
||||
if self.wire_hover_tick_subscribed == subscribed {
|
||||
return;
|
||||
}
|
||||
self.wire_hover_tick_subscribed = subscribed;
|
||||
|
||||
let send = Box::new(NodeGraphMessage::WireHoverTick.into());
|
||||
responses.add(match subscribed {
|
||||
true => BroadcastMessage::SubscribeEvent {
|
||||
on: EventMessage::AnimationFrame,
|
||||
send,
|
||||
},
|
||||
false => BroadcastMessage::UnsubscribeEvent {
|
||||
on: EventMessage::AnimationFrame,
|
||||
send,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/// 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);
|
||||
@@ -2992,6 +3137,9 @@ impl Default for NodeGraphMessageHandler {
|
||||
wire_in_progress_from_connector: None,
|
||||
wire_in_progress_to_connector: None,
|
||||
wire_in_progress_type: FrontendGraphDataType::General,
|
||||
wire_hovered_node: None,
|
||||
wire_expanded_node: None,
|
||||
wire_hover_tick_subscribed: false,
|
||||
context_menu: None,
|
||||
deselect_on_pointer_up: None,
|
||||
auto_panning: Default::default(),
|
||||
|
||||
@@ -172,6 +172,11 @@ pub fn disconnected_input_label() -> WidgetInstance {
|
||||
.widget_instance()
|
||||
}
|
||||
|
||||
/// The standard exposed row of a parameter that otherwise has no row of its own, or none while it is unexposed.
|
||||
pub fn exposed_parameter_row(parameter_widgets_info: &ParameterWidgetsInfo) -> Option<LayoutGroup> {
|
||||
parameter_widgets_info.is_exposed().then(|| LayoutGroup::row(start_widgets(parameter_widgets_info)))
|
||||
}
|
||||
|
||||
pub fn start_widgets(parameter_widgets_info: &ParameterWidgetsInfo) -> Vec<WidgetInstance> {
|
||||
if parameter_widgets_info.document_node.is_none() {
|
||||
log::warn!("A widget failed to be built because its document node is invalid.");
|
||||
@@ -1151,19 +1156,8 @@ pub fn optional_f64_widget(parameter_widgets_info: ParameterWidgetsInfo, bool_in
|
||||
None => number_widget(parameter_widgets_info, number_props),
|
||||
};
|
||||
|
||||
if let Some(enabled) = enabled
|
||||
&& !exposed
|
||||
{
|
||||
let checkbox = [
|
||||
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
CheckboxInput::new(enabled)
|
||||
.on_update(update_value_at_index(|x: &CheckboxInput| TaggedValue::Bool(x.checked), node_id, bool_input_index))
|
||||
.on_commit(commit_value)
|
||||
.widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
];
|
||||
widgets.splice(label_count..label_count, checkbox);
|
||||
if !exposed {
|
||||
widgets.splice(label_count..label_count, optional_parameter_assist(enabled, node_id, bool_input_index));
|
||||
}
|
||||
|
||||
widgets
|
||||
@@ -1185,24 +1179,32 @@ pub fn optional_color_widget(parameter_widgets_info: ParameterWidgetsInfo, bool_
|
||||
let LayoutGroup::Row(mut row) = color_widget(parameter_widgets_info, color_button.disabled(enabled == Some(false))) else {
|
||||
return LayoutGroup::row(Vec::new());
|
||||
};
|
||||
if let Some(enabled) = enabled
|
||||
&& !exposed
|
||||
{
|
||||
let checkbox = [
|
||||
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
CheckboxInput::new(enabled)
|
||||
.on_update(update_value_at_index(|x: &CheckboxInput| TaggedValue::Bool(x.checked), node_id, bool_input_index))
|
||||
.on_commit(commit_value)
|
||||
.widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
];
|
||||
row.widgets.splice(label_count..label_count, checkbox);
|
||||
if !exposed {
|
||||
row.widgets.splice(label_count..label_count, optional_parameter_assist(enabled, node_id, bool_input_index));
|
||||
}
|
||||
|
||||
LayoutGroup::Row(row)
|
||||
}
|
||||
|
||||
/// The assist slot of an optional parameter's row: the checkbox of its gating bool input, or a blank while that bool is exposed with a row of its own.
|
||||
fn optional_parameter_assist(enabled: Option<bool>, node_id: NodeId, bool_input_index: usize) -> Vec<WidgetInstance> {
|
||||
let Some(enabled) = enabled else {
|
||||
let mut blank_assist = Vec::new();
|
||||
add_blank_assist(&mut blank_assist);
|
||||
return blank_assist;
|
||||
};
|
||||
|
||||
vec![
|
||||
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
CheckboxInput::new(enabled)
|
||||
.on_update(update_value_at_index(|x: &CheckboxInput| TaggedValue::Bool(x.checked), node_id, bool_input_index))
|
||||
.on_commit(commit_value)
|
||||
.widget_instance(),
|
||||
Separator::new(SeparatorStyle::Related).widget_instance(),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props: NumberInput) -> Vec<WidgetInstance> {
|
||||
let mut widgets = start_widgets(¶meter_widgets_info);
|
||||
|
||||
@@ -1693,9 +1695,9 @@ pub(crate) fn brightness_contrast_inspector(node_id: NodeId, context: &mut NodeI
|
||||
pub(crate) fn transfer_curves_inspector(node_id: NodeId, context: &mut NodeInspectorContext) -> Vec<LayoutGroup> {
|
||||
use graphene_std::raster::curves::*;
|
||||
|
||||
let mut channel_info = ParameterWidgetsInfo::new(node_id, ChannelInput, true, context);
|
||||
channel_info.exposable = false;
|
||||
let channel = enum_choice::<AdjustmentChannel>().for_socket(channel_info).inspector_row();
|
||||
let channel = enum_choice::<AdjustmentChannel>()
|
||||
.for_socket(ParameterWidgetsInfo::new(node_id, ChannelInput, true, context))
|
||||
.inspector_row();
|
||||
|
||||
let channel_value = match get_document_node(node_id, context).ok().and_then(|document_node| document_node.input_value(ChannelInput).cloned()) {
|
||||
Some(TaggedValue::AdjustmentChannel(channel)) => channel,
|
||||
@@ -1716,9 +1718,9 @@ pub(crate) fn transfer_curves_inspector(node_id: NodeId, context: &mut NodeInspe
|
||||
pub(crate) fn levels_inspector(node_id: NodeId, context: &mut NodeInspectorContext) -> Vec<LayoutGroup> {
|
||||
use graphene_std::raster::levels::*;
|
||||
|
||||
let mut channel_info = ParameterWidgetsInfo::new(node_id, ChannelInput, true, context);
|
||||
channel_info.exposable = false;
|
||||
let channel = enum_choice::<AdjustmentChannel>().for_socket(channel_info).inspector_row();
|
||||
let channel = enum_choice::<AdjustmentChannel>()
|
||||
.for_socket(ParameterWidgetsInfo::new(node_id, ChannelInput, true, context))
|
||||
.inspector_row();
|
||||
|
||||
let channel_value = match get_document_node(node_id, context).ok().and_then(|document_node| document_node.input_value(ChannelInput).cloned()) {
|
||||
Some(TaggedValue::AdjustmentChannel(channel)) => channel,
|
||||
@@ -2170,9 +2172,12 @@ pub(crate) fn hue_saturation_inspector(node_id: NodeId, context: &mut NodeInspec
|
||||
let (saturation_min, saturation_default) = if colorize_value { (0., 25.) } else { (-100., 0.) };
|
||||
|
||||
// Colorize replaces the ranges, so while it is on the selector stays but grayed out and the selected range's edges hide
|
||||
let mut range_info = ParameterWidgetsInfo::new(node_id, RangeInput, true, context);
|
||||
range_info.exposable = false;
|
||||
let mut layout = vec![enum_choice::<HueSaturationRange>().for_socket(range_info).disabled(colorize_value).inspector_row()];
|
||||
let mut layout = vec![
|
||||
enum_choice::<HueSaturationRange>()
|
||||
.for_socket(ParameterWidgetsInfo::new(node_id, RangeInput, true, context))
|
||||
.disabled(colorize_value)
|
||||
.inspector_row(),
|
||||
];
|
||||
|
||||
layout.extend([
|
||||
gradient_slider_row(
|
||||
@@ -2414,9 +2419,7 @@ pub(crate) fn vibrance_inspector(node_id: NodeId, context: &mut NodeInspectorCon
|
||||
pub(crate) fn color_balance_inspector(node_id: NodeId, context: &mut NodeInspectorContext) -> Vec<LayoutGroup> {
|
||||
use graphene_std::raster::color_balance::*;
|
||||
|
||||
let mut tone_info = ParameterWidgetsInfo::new(node_id, ToneInput, true, context);
|
||||
tone_info.exposable = false;
|
||||
let tone = enum_choice::<TonalRange>().for_socket(tone_info).inspector_row();
|
||||
let tone = enum_choice::<TonalRange>().for_socket(ParameterWidgetsInfo::new(node_id, ToneInput, true, context)).inspector_row();
|
||||
let preserve_luminosity = bool_widget(ParameterWidgetsInfo::new(node_id, PreserveLuminosityInput, true, context), CheckboxInput::default());
|
||||
|
||||
let document_node = match get_document_node(node_id, context) {
|
||||
@@ -2462,9 +2465,12 @@ pub(crate) fn black_and_white_inspector(node_id: NodeId, context: &mut NodeInspe
|
||||
let number_input = NumberInput::default().mode_increment().unit("%").min(-200.).max(300.);
|
||||
|
||||
let use_tint: ParameterRef = UseTintInput.into();
|
||||
let use_tint_row = exposed_parameter_row(&ParameterWidgetsInfo::new(node_id, UseTintInput, true, context));
|
||||
let tint = optional_color_widget(ParameterWidgetsInfo::new(node_id, TintInput, false, context), use_tint.input_index, ColorInput::default());
|
||||
|
||||
let mut layout = vec![tint];
|
||||
let mut layout = Vec::new();
|
||||
layout.extend(use_tint_row);
|
||||
layout.push(tint);
|
||||
let params: &[(ParameterRef, Color, f64)] = &[
|
||||
(RedsInput.into(), Color::RED, 40.),
|
||||
(YellowsInput.into(), Color::YELLOW, 60.),
|
||||
@@ -2494,9 +2500,9 @@ pub(crate) fn channel_mixer_inspector(node_id: NodeId, context: &mut NodeInspect
|
||||
use graphene_std::raster::channel_mixer::*;
|
||||
|
||||
let is_monochrome = bool_widget(ParameterWidgetsInfo::new(node_id, MonochromeInput, true, context), CheckboxInput::default());
|
||||
let mut parameter_info = ParameterWidgetsInfo::new(node_id, OutputChannelInput, true, context);
|
||||
parameter_info.exposable = false;
|
||||
let output_channel = enum_choice::<RedGreenBlue>().for_socket(parameter_info).inspector_row();
|
||||
let output_channel = enum_choice::<RedGreenBlue>()
|
||||
.for_socket(ParameterWidgetsInfo::new(node_id, OutputChannelInput, true, context))
|
||||
.inspector_row();
|
||||
|
||||
let document_node = match get_document_node(node_id, context) {
|
||||
Ok(document_node) => document_node,
|
||||
@@ -2557,9 +2563,9 @@ pub(crate) fn channel_mixer_inspector(node_id: NodeId, context: &mut NodeInspect
|
||||
pub(crate) fn selective_color_inspector(node_id: NodeId, context: &mut NodeInspectorContext) -> Vec<LayoutGroup> {
|
||||
use graphene_std::raster::selective_color::*;
|
||||
|
||||
let mut default_info = ParameterWidgetsInfo::new(node_id, ColorsInput, true, context);
|
||||
default_info.exposable = false;
|
||||
let colors = enum_choice::<SelectiveColorChoice>().for_socket(default_info).inspector_row();
|
||||
let colors = enum_choice::<SelectiveColorChoice>()
|
||||
.for_socket(ParameterWidgetsInfo::new(node_id, ColorsInput, true, context))
|
||||
.inspector_row();
|
||||
|
||||
let document_node = match get_document_node(node_id, context) {
|
||||
Ok(document_node) => document_node,
|
||||
@@ -3657,6 +3663,7 @@ impl<'a> ParameterWidgetsInfo<'a> {
|
||||
.displayed_type();
|
||||
let document_node = context.network_interface.document_node(&node_id, context.selection_network_path);
|
||||
let chain_expanded = expanded_input_chain(&node_id, context.inspector_expanded_input_chains, context.network_interface, context.selection_network_path) == Some(index);
|
||||
let exposable = !context.network_interface.is_internal_input(&node_id, index, context.selection_network_path);
|
||||
|
||||
ParameterWidgetsInfo {
|
||||
document_id: context.document_id,
|
||||
@@ -3671,7 +3678,7 @@ impl<'a> ParameterWidgetsInfo<'a> {
|
||||
description,
|
||||
input_type,
|
||||
blank_assist,
|
||||
exposable: true,
|
||||
exposable,
|
||||
chain_expanded,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ mod validation;
|
||||
mod view;
|
||||
|
||||
pub use editor_delta::{EditorDelta, NetworkMetadataChange, NodeMetadataChange};
|
||||
pub use resolved_types::type_feeds_connector;
|
||||
use store::Guarded;
|
||||
pub use store::NodeLocator;
|
||||
pub use template::*;
|
||||
|
||||
@@ -542,6 +542,19 @@ impl NodeNetworkInterface {
|
||||
self.view(network_path).ok().and_then(|view| view.persistent_input_metadata(node_id, index).ok())
|
||||
}
|
||||
|
||||
/// Whether the input is internal state of its proto node (named with a leading `_`), which is never exposed to the graph.
|
||||
pub fn is_internal_input(&self, node_id: &NodeId, index: usize, network_path: &[NodeId]) -> bool {
|
||||
let Some(DocumentNodeImplementation::ProtoNode(proto_node_identifier)) = self.implementation(node_id, network_path) else {
|
||||
return false;
|
||||
};
|
||||
let Ok(node_metadata) = graphene_std::registry::NODE_METADATA.lock() else { return false };
|
||||
|
||||
node_metadata
|
||||
.get(proto_node_identifier)
|
||||
.and_then(|metadata| metadata.fields.get(index))
|
||||
.is_some_and(|field| field.internal)
|
||||
}
|
||||
|
||||
pub fn set_input_override(&mut self, node_id: &NodeId, index: usize, widget_override: Option<String>, network_path: &[NodeId]) {
|
||||
let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) else {
|
||||
log::error!("Could not get node {node_id} in set_input_override");
|
||||
|
||||
+93
-25
@@ -4,6 +4,7 @@ use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{DocumentNodeImplementation, InlineRust, NodeInput};
|
||||
use graph_craft::proto::{GraphErrorType, GraphErrors};
|
||||
use graph_craft::{ProtoNodeIdentifier, Type, concrete};
|
||||
use graphene_std::NodeIOTypes;
|
||||
use graphene_std::uuid::NodeId;
|
||||
use interpreted_executor::dynamic_executor::{NodeTypes, ResolvedDocumentNodeTypesDelta};
|
||||
use interpreted_executor::node_registry::NODE_REGISTRY;
|
||||
@@ -11,6 +12,23 @@ use interpreted_executor::node_registry::NODE_REGISTRY;
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface, OutputConnector};
|
||||
|
||||
/// Whether a `source` type can feed a `connector` type, directly or through the `input_adapter` node the compiler inserts to convert elements (such as `Color` into `Graphic`).
|
||||
pub fn type_feeds_connector(source: &Type, connector: &Type) -> bool {
|
||||
let source = source.nested_type();
|
||||
let connector = connector.nested_type();
|
||||
if source == connector {
|
||||
return true;
|
||||
}
|
||||
|
||||
let (Type::Item(element) | Type::List(element)) = connector else { return false };
|
||||
let adapter = ProtoNodeIdentifier::with_owned_string(format!("input_adapter<{}>", element.identifier_name()));
|
||||
NODE_REGISTRY.get(&adapter).is_some_and(|implementations| {
|
||||
implementations
|
||||
.keys()
|
||||
.any(|node_io| node_io.return_value.nested_type() == connector && node_io.inputs.first().is_some_and(|input| input.nested_type() == source))
|
||||
})
|
||||
}
|
||||
|
||||
// This file contains utility methods for interfacing with the resolved types returned from the compiler
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ResolvedDocumentNodeTypes {
|
||||
@@ -290,31 +308,10 @@ impl NodeNetworkInterface {
|
||||
|
||||
intersection.into_iter().collect::<Vec<_>>()
|
||||
}
|
||||
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
|
||||
let Some(implementations) = NODE_REGISTRY.get(proto_node_identifier) else {
|
||||
// The compiler removes the passthrough node, so it's expected to be absent from the registry
|
||||
if proto_node_identifier != &graphene_std::ops::passthrough::IDENTIFIER {
|
||||
log::error!("Proto node `{proto_node_identifier:?}` not found in the node registry, in potential_valid_input_types");
|
||||
}
|
||||
return Vec::new();
|
||||
};
|
||||
let number_of_inputs = self.number_of_inputs(node_id, network_path);
|
||||
implementations
|
||||
.keys()
|
||||
.filter_map(|node_io| {
|
||||
// Check if this NodeIOTypes implementation is valid for the other inputs
|
||||
let valid_implementation = (0..number_of_inputs).filter(|iterator_index| iterator_index != input_index).all(|iterator_index| {
|
||||
let input_type = self.input_type_not_invalid(&InputConnector::node_at_index(*node_id, iterator_index), network_path);
|
||||
// TODO: Fix type checking for different call arguments
|
||||
// For example a node input of (Footprint) -> Vector would not be compatible with a node that is called with () and returns Vector
|
||||
node_io.inputs.get(iterator_index).map(|ty| ty.nested_type()) == input_type.compiled_nested_type()
|
||||
});
|
||||
|
||||
// If so, then return the input at the chosen index
|
||||
if valid_implementation { node_io.inputs.get(*input_index).cloned() } else { None }
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => self
|
||||
.implementations_matching_inputs(proto_node_identifier, node_id, Some(*input_index), network_path)
|
||||
.filter_map(|node_io| node_io.inputs.get(*input_index).cloned())
|
||||
.collect::<Vec<_>>(),
|
||||
DocumentNodeImplementation::Extract => {
|
||||
log::error!("Input types for extract node not supported");
|
||||
Vec::new()
|
||||
@@ -322,6 +319,55 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/// The types an output could produce: its compiled type, or else the return types of the registry implementations matching its node's inputs.
|
||||
pub fn potential_output_types(&self, output_connector: &OutputConnector, network_path: &[NodeId]) -> Vec<Type> {
|
||||
if let Some(compiled_type) = self.output_type(output_connector, network_path).compiled_nested_type() {
|
||||
return vec![compiled_type.clone()];
|
||||
}
|
||||
|
||||
// Nodes outside the compiled graph, such as disconnected ones, have no resolved type
|
||||
let OutputConnector::Node { node_id, output_index: 0 } = output_connector else {
|
||||
return Vec::new();
|
||||
};
|
||||
let Some(DocumentNodeImplementation::ProtoNode(proto_node_identifier)) = self.implementation(node_id, network_path) else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
self.implementations_matching_inputs(proto_node_identifier, node_id, None, network_path)
|
||||
.map(|node_io| node_io.return_value.nested_type().clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The registry implementations of a proto node whose inputs accept the node's current input types, ignoring `disregarded_input_index`.
|
||||
fn implementations_matching_inputs<'a>(
|
||||
&'a self,
|
||||
proto_node_identifier: &ProtoNodeIdentifier,
|
||||
node_id: &'a NodeId,
|
||||
disregarded_input_index: Option<usize>,
|
||||
network_path: &'a [NodeId],
|
||||
) -> impl Iterator<Item = &'static NodeIOTypes> + 'a {
|
||||
let implementations = NODE_REGISTRY.get(proto_node_identifier);
|
||||
|
||||
// The compiler removes the passthrough node, so it's expected to be absent from the registry
|
||||
if implementations.is_none() && proto_node_identifier != &graphene_std::ops::passthrough::IDENTIFIER {
|
||||
log::error!("Proto node `{proto_node_identifier:?}` not found in the node registry");
|
||||
}
|
||||
|
||||
let number_of_inputs = self.number_of_inputs(node_id, network_path);
|
||||
implementations.into_iter().flat_map(|implementations| implementations.keys()).filter(move |node_io| {
|
||||
(0..number_of_inputs).filter(|index| Some(*index) != disregarded_input_index).all(|index| {
|
||||
let input_type = self.input_type_not_invalid(&InputConnector::node_at_index(*node_id, index), network_path);
|
||||
// TODO: Fix type checking for different call arguments
|
||||
// For example a node input of (Footprint) -> Vector would not be compatible with a node that is called with () and returns Vector
|
||||
match (input_type.compiled_nested_type(), node_io.inputs.get(index)) {
|
||||
(Some(source), Some(connector)) => type_feeds_connector(source, connector),
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Performs a downstream traversal to ensure input type will work in the full context of the graph.
|
||||
pub fn complete_valid_input_types(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> Vec<Type> {
|
||||
match input_connector {
|
||||
@@ -465,3 +511,25 @@ impl NodeNetworkInterface {
|
||||
intersection.into_iter().collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::type_feeds_connector;
|
||||
use graph_craft::item;
|
||||
use graphene_std::vector::style::DashPattern;
|
||||
use graphene_std::{Color, Graphic};
|
||||
|
||||
#[test]
|
||||
fn input_adapter_conversions_feed_connectors() {
|
||||
assert!(type_feeds_connector(&item!(f64), &item!(f64)), "identical types should match directly");
|
||||
assert!(
|
||||
type_feeds_connector(&item!(Color), &item!(Graphic)),
|
||||
"a color paint should feed a graphic paint connector through its input adapter"
|
||||
);
|
||||
assert!(
|
||||
type_feeds_connector(&item!(f64), &item!(DashPattern)),
|
||||
"a number should feed a dash pattern connector through its input adapter"
|
||||
);
|
||||
assert!(!type_feeds_connector(&item!(f64), &item!(Graphic)), "a number has no conversion into a graphic");
|
||||
}
|
||||
}
|
||||
@@ -335,6 +335,28 @@ impl NodeNetworkInterface {
|
||||
self.deltas.clear();
|
||||
}
|
||||
|
||||
/// Records the open transaction's bookkeeping, so writes that are undone before [`Self::restore_transaction_checkpoint`] don't count toward it.
|
||||
pub fn transaction_checkpoint(&mut self) -> TransactionCheckpoint {
|
||||
self.scan_transaction_edited_nodes();
|
||||
|
||||
TransactionCheckpoint {
|
||||
status: self.transaction_status,
|
||||
edited_nodes: self.transaction_edited_nodes.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Puts back the open transaction's bookkeeping from [`Self::transaction_checkpoint`] once the writes made since then are undone, leaving their deltas unread.
|
||||
pub fn restore_transaction_checkpoint(&mut self, checkpoint: TransactionCheckpoint) {
|
||||
if self.transaction_status == TransactionStatus::Finished {
|
||||
return;
|
||||
}
|
||||
|
||||
self.transaction_status = checkpoint.status;
|
||||
self.transaction_edited_nodes_changed |= self.transaction_edited_nodes != checkpoint.edited_nodes;
|
||||
self.transaction_edited_nodes = checkpoint.edited_nodes;
|
||||
self.transaction_edited_nodes_scanned = self.deltas.len();
|
||||
}
|
||||
|
||||
/// Reads the open transaction's writes since the last call, returning whether that changed which nodes it has written to.
|
||||
pub fn update_transaction_edited_nodes(&mut self) -> bool {
|
||||
self.scan_transaction_edited_nodes();
|
||||
|
||||
@@ -920,6 +920,13 @@ pub enum TransactionStatus {
|
||||
Finished,
|
||||
}
|
||||
|
||||
/// The open transaction's bookkeeping from [`NodeNetworkInterface::transaction_checkpoint`], to put back once the writes made after it are undone.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TransactionCheckpoint {
|
||||
pub(super) status: TransactionStatus,
|
||||
pub(super) edited_nodes: HashSet<NodeId>,
|
||||
}
|
||||
|
||||
/// How [`NodeNetworkInterface::is_sole_dependent`] should treat a downstream connector it encounters.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum SoleDependentStep {
|
||||
|
||||
@@ -792,6 +792,16 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
});
|
||||
}
|
||||
PortfolioMessage::SelectDocument { document_id } => {
|
||||
// The document we are leaving won't get the pointer up that ends a wire drag in its graph, so abort the drag there before switching
|
||||
if self.active_document_id != Some(document_id)
|
||||
&& let Some(document) = self.active_document_mut()
|
||||
&& document.end_node_graph_wire_in_progress(responses)
|
||||
{
|
||||
responses.add(DocumentMessage::AbortTransaction);
|
||||
responses.add(PortfolioMessage::SelectDocument { document_id });
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-save the document we are leaving
|
||||
let mut node_graph_open = false;
|
||||
if let Some(document) = self.active_document() {
|
||||
|
||||
@@ -26,7 +26,8 @@ pub struct NodeMetadata {
|
||||
pub struct FieldMetadata {
|
||||
pub name: &'static str,
|
||||
pub description: &'static str,
|
||||
pub hidden: bool,
|
||||
/// Whether the parameter is internal state of its node (named with a leading `_`), which is never exposed to the graph.
|
||||
pub internal: bool,
|
||||
pub exposed: bool,
|
||||
pub widget_override: RegistryWidgetOverride,
|
||||
pub value_source: RegistryValueSource,
|
||||
|
||||
@@ -109,7 +109,12 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
})
|
||||
.collect();
|
||||
|
||||
let input_hidden = regular_field_names.iter().map(|name| name.to_string().starts_with('_')).collect::<Vec<_>>();
|
||||
// The primary input is not a parameter, so generators can name their unused one `_primary` without it becoming internal
|
||||
let input_internal = regular_field_names
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, name)| Some(index) != primary_regular_index && name.to_string().starts_with('_'))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let input_descriptions: Vec<_> = regular_fields.iter().map(|f| &f.description).collect();
|
||||
|
||||
@@ -941,7 +946,7 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
name: #input_names,
|
||||
widget_override: #widget_override,
|
||||
description: #input_descriptions,
|
||||
hidden: #input_hidden,
|
||||
internal: #input_internal,
|
||||
exposed: #exposed,
|
||||
value_source: #value_sources,
|
||||
default_colors: #default_colors,
|
||||
|
||||
@@ -844,6 +844,12 @@ fn parse_field(pat_ident: PatIdent, ty: Type, attrs: &[Attribute]) -> syn::Resul
|
||||
));
|
||||
}
|
||||
}
|
||||
if exposed && ident.to_string().starts_with('_') {
|
||||
return Err(Error::new_spanned(
|
||||
&pat_ident,
|
||||
"Parameters named with a leading `_` cannot be exposed (#[expose]). They are internal state, which is never exposed to the graph",
|
||||
));
|
||||
}
|
||||
|
||||
let value_source = match (default_value, scope) {
|
||||
(Some(_), Some(_)) => return Err(Error::new_spanned(&pat_ident, "Cannot have both `default` and `scope` attributes")),
|
||||
|
||||
@@ -18,10 +18,10 @@ use wgpu_executor::{WgpuExecutor, WgpuPipelineCache};
|
||||
pub async fn basic_brush<'a: 'n>(
|
||||
ctx: impl Ctx + ExtractFootprint,
|
||||
strokes: List<Graphic>,
|
||||
#[widget(ParsedWidgetOverride::Hidden)] cache: Item<BrushCache>,
|
||||
#[widget(ParsedWidgetOverride::Hidden)] _cache: Item<BrushCache>,
|
||||
#[scope(basic_brush_pipeline::IDENTIFIER)] pipeline: Item<WgpuPipelineCache>,
|
||||
) -> List<Raster<GPU>> {
|
||||
let (cache, pipeline) = (cache.into_element(), pipeline.into_element());
|
||||
let (cache, pipeline) = (_cache.into_element(), pipeline.into_element());
|
||||
let mut stack = vec![strokes.into_iter()];
|
||||
let mut strokes = Vec::new();
|
||||
while let Some(top) = stack.last_mut() {
|
||||
|
||||
@@ -116,7 +116,7 @@ fn write_inputs(page: &mut std::fs::File, valid_input_types: &[Vec<core_types::T
|
||||
.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(index, field)| !field.hidden || index == 0)
|
||||
.filter(|(_, field)| !field.internal)
|
||||
.map(|(index, field)| {
|
||||
// Parameter
|
||||
let parameter = field.name;
|
||||
|
||||
Reference in new issue
Block a user