From cf496668fb0beea745f3030e4abb187e85425c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tayfun=20Ya=C5=9Far?= <151904387+ysrtyfn@users.noreply.github.com> Date: Sat, 22 Jun 2024 11:10:52 +0300 Subject: [PATCH] Add artboard displayed names in the viewport (#1795) * possible location of the change is decided. * fix for issue #1774 * possible location of the change is decided. * fix for issue #1774 * fix for #1706 * fix for #1706, code reformatted * fix for #1706, Label input removed from Properties * fix for #1706 * deleted the comment --- .../graph_operation_message_handler.rs | 1 + .../document/graph_operation/utility_types.rs | 1 + .../node_graph/document_node_types.rs | 7 ++++--- .../node_graph/node_graph_message_handler.rs | 2 +- .../document/node_graph/node_properties.rs | 6 ++++-- .../tool/tool_messages/artboard_tool.rs | 1 + node-graph/gcore/src/graphic_element.rs | 8 +++++++- .../gcore/src/graphic_element/renderer.rs | 3 ++- node-graph/graph-craft/src/document.rs | 19 ++++++++++++++----- node-graph/graph-craft/src/document/value.rs | 11 +++++++++++ .../interpreted-executor/src/node_registry.rs | 12 ++++++------ 11 files changed, 52 insertions(+), 19 deletions(-) diff --git a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs index 67c8176f..a14828de 100644 --- a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs +++ b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs @@ -709,6 +709,7 @@ impl MessageHandler> for Gr responses.add(DocumentMessage::RenderRulers); responses.add(DocumentMessage::RenderScrollbars); responses.add(NodeGraphMessage::SendGraph); + responses.add(NodeGraphMessage::RunDocumentGraph); } } GraphOperationMessage::SetNodeInput { node_id, input_index, input } => { diff --git a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs index 9c4df664..487b0369 100644 --- a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs +++ b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs @@ -314,6 +314,7 @@ impl<'a> ModifyInputsContext<'a> { ModifyInputsContext::insert_node_as_primary_export(node_graph, document_network, new_id, artboard_node) } + pub fn insert_vector_data(&mut self, subpaths: Vec>, layer: NodeId) { let shape = { let node_type: &crate::messages::portfolio::document::node_graph::document_node_types::DocumentNodeDefinition = resolve_document_node_type("Shape").expect("Shape node does not exist"); diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs index fd26b391..3c0d7aca 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs @@ -266,13 +266,14 @@ fn static_nodes() -> Vec { name: "To Artboard".to_string(), manual_composition: Some(concrete!(Footprint)), inputs: vec![ - NodeInput::network(concrete!(graphene_core::GraphicGroup), 1), + NodeInput::network(concrete!(TaggedValue), 1), + NodeInput::value(TaggedValue::String(String::from("Artboard")), false), NodeInput::network(concrete!(TaggedValue), 2), NodeInput::network(concrete!(TaggedValue), 3), NodeInput::network(concrete!(TaggedValue), 4), NodeInput::network(concrete!(TaggedValue), 5), ], - implementation: DocumentNodeImplementation::proto("graphene_core::ConstructArtboardNode<_, _, _, _, _>"), + implementation: DocumentNodeImplementation::proto("graphene_core::ConstructArtboardNode<_, _, _, _, _, _>"), metadata: DocumentNodeMetadata { position: glam::IVec2::new(-10, -3) }, // To Artboard ..Default::default() }, @@ -309,7 +310,7 @@ fn static_nodes() -> Vec { }), inputs: vec![ DocumentInputType::value("Artboards", TaggedValue::ArtboardGroup(ArtboardGroup::EMPTY), true), - DocumentInputType::value("Over", TaggedValue::GraphicGroup(GraphicGroup::EMPTY), true), + DocumentInputType::value("Contents", TaggedValue::GraphicGroup(GraphicGroup::EMPTY), true), DocumentInputType::value("Location", TaggedValue::IVec2(glam::IVec2::ZERO), false), DocumentInputType::value("Dimensions", TaggedValue::IVec2(glam::IVec2::new(1920, 1080)), false), DocumentInputType::value("Background", TaggedValue::Color(Color::WHITE), false), diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index e2b6e725..b14e722f 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -1408,7 +1408,7 @@ impl<'a> MessageHandler> for NodeGrap self.update_click_target(node_id, document_network, self.network.clone()); responses.add(DocumentMessage::RenderRulers); responses.add(DocumentMessage::RenderScrollbars); - self.send_graph(document_network, document_metadata, collapsed, graph_view_overlay_open, responses); + responses.add(NodeGraphMessage::SendGraph); } } NodeGraphMessage::StartPreviewingWithoutRestore { node_id } => { 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 3d2b357a..a0535668 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_properties.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_properties.rs @@ -2448,8 +2448,10 @@ pub fn artboard_properties(document_node: &DocumentNode, node_id: NodeId, _conte let dimensions = vec2_widget(document_node, node_id, 3, "Dimensions", "W", "H", " px", None, add_blank_assist); let background = color_widget(document_node, node_id, 4, "Background", ColorButton::default().allow_none(false), true); let clip = bool_widget(document_node, node_id, 5, "Clip", true); - let clip = LayoutGroup::Row { widgets: clip }; - vec![location, dimensions, background, clip] + + let clip_row = LayoutGroup::Row { widgets: clip }; + + vec![location, dimensions, background, clip_row] } pub fn color_fill_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec { diff --git a/editor/src/messages/tool/tool_messages/artboard_tool.rs b/editor/src/messages/tool/tool_messages/artboard_tool.rs index c22991af..b0dbce7c 100644 --- a/editor/src/messages/tool/tool_messages/artboard_tool.rs +++ b/editor/src/messages/tool/tool_messages/artboard_tool.rs @@ -306,6 +306,7 @@ impl Fsm for ArtboardToolFsmState { id, artboard: graphene_core::Artboard { graphic_group: graphene_core::GraphicGroup::EMPTY, + label: String::from("Artboard"), location: start.round().as_ivec2(), dimensions: IVec2::splat(1), background: graphene_core::Color::WHITE, diff --git a/node-graph/gcore/src/graphic_element.rs b/node-graph/gcore/src/graphic_element.rs index b28f8a7d..dc24c0db 100644 --- a/node-graph/gcore/src/graphic_element.rs +++ b/node-graph/gcore/src/graphic_element.rs @@ -88,6 +88,7 @@ impl Default for GraphicElement { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Artboard { pub graphic_group: GraphicGroup, + pub label: String, pub location: IVec2, pub dimensions: IVec2, pub background: Color, @@ -98,6 +99,7 @@ impl Artboard { pub fn new(location: IVec2, dimensions: IVec2) -> Self { Self { graphic_group: GraphicGroup::EMPTY, + label: String::from("Artboard"), location: location.min(location + dimensions), dimensions: dimensions.abs(), background: Color::WHITE, @@ -165,8 +167,9 @@ fn to_graphic_group>(data: Data) -> GraphicGroup { data.into() } -pub struct ConstructArtboardNode { +pub struct ConstructArtboardNode { contents: Contents, + label: Label, location: Location, dimensions: Dimensions, background: Background, @@ -177,6 +180,7 @@ pub struct ConstructArtboardNode>( mut footprint: Footprint, contents: impl Node, + label: String, location: IVec2, dimensions: IVec2, background: Color, @@ -184,8 +188,10 @@ async fn construct_artboard>( ) -> Artboard { footprint.transform *= DAffine2::from_translation(location.as_dvec2()); let graphic_group = self.contents.eval(footprint).await; + Artboard { graphic_group, + label, location: location.min(location + dimensions), dimensions: dimensions.abs(), background, diff --git a/node-graph/gcore/src/graphic_element/renderer.rs b/node-graph/gcore/src/graphic_element/renderer.rs index 44ce1919..51155ca5 100644 --- a/node-graph/gcore/src/graphic_element/renderer.rs +++ b/node-graph/gcore/src/graphic_element/renderer.rs @@ -396,7 +396,7 @@ impl GraphicElementRendered for Artboard { }, |render| { // TODO: Use the artboard's layer name - render.svg.push("Artboard".into()); + render.svg.push(self.label.to_string().into()); }, ); } @@ -475,6 +475,7 @@ impl GraphicElementRendered for crate::ArtboardGroup { self.artboards.len() > 0 } } + impl GraphicElementRendered for ImageFrame { fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) { let transform: String = format_transform_matrix(self.transform * render.transform); diff --git a/node-graph/graph-craft/src/document.rs b/node-graph/graph-craft/src/document.rs index 8c13a0da..5ad1fc9f 100644 --- a/node-graph/graph-craft/src/document.rs +++ b/node-graph/graph-craft/src/document.rs @@ -1110,14 +1110,14 @@ impl NodeNetwork { } /// Remove all nodes that contain [`DocumentNodeImplementation::Network`] by moving the nested nodes into the parent network. - pub fn flatten(&mut self, node: NodeId) { - self.flatten_with_fns(node, merge_ids, || NodeId(generate_uuid())) + pub fn flatten(&mut self, node_id: NodeId) { + self.flatten_with_fns(node_id, merge_ids, || NodeId(generate_uuid())) } /// Remove all nodes that contain [`DocumentNodeImplementation::Network`] by moving the nested nodes into the parent network. - pub fn flatten_with_fns(&mut self, node: NodeId, map_ids: impl Fn(NodeId, NodeId) -> NodeId + Copy, gen_id: impl Fn() -> NodeId + Copy) { - let Some((id, mut node)) = self.nodes.remove_entry(&node) else { - warn!("The node which was supposed to be flattened does not exist in the network, id {node} network {self:#?}"); + pub fn flatten_with_fns(&mut self, node_id: NodeId, map_ids: impl Fn(NodeId, NodeId) -> NodeId + Copy, gen_id: impl Fn() -> NodeId + Copy) { + let Some((id, mut node)) = self.nodes.remove_entry(&node_id) else { + warn!("The node which was supposed to be flattened does not exist in the network, id {node_id} network {self:#?}"); return; }; @@ -1166,6 +1166,7 @@ impl NodeNetwork { } } } + // Replace value inputs with value nodes, added to flattened network for input in node.inputs.iter_mut() { let previous_input = std::mem::replace(input, NodeInput::network(concrete!(()), 0)); @@ -1201,8 +1202,16 @@ impl NodeNetwork { // Connect all network inputs to either the parent network nodes, or newly created value nodes for the parent node. inner_network.map_ids(|inner_id| map_ids(id, inner_id)); let new_nodes = inner_network.nodes.keys().cloned().collect::>(); + // Match the document node input and the inputs of the inner network for (nested_node_id, mut nested_node) in inner_network.nodes.into_iter() { + if nested_node.name == "To Artboard" { + let label_index = 1; + let label = if !node.alias.is_empty() { node.alias.clone() } else { node.name.clone() }; + let label_input = NodeInput::value(TaggedValue::String(label), false); + nested_node.inputs[label_index] = label_input; + } + for (nested_input_index, nested_input) in nested_node.clone().inputs.iter().enumerate() { if let NodeInput::Network { import_index, .. } = nested_input { let parent_input = node.inputs.get(*import_index).expect("Import index should always exist"); diff --git a/node-graph/graph-craft/src/document/value.rs b/node-graph/graph-craft/src/document/value.rs index 335a4c44..7b7fe4ec 100644 --- a/node-graph/graph-craft/src/document/value.rs +++ b/node-graph/graph-craft/src/document/value.rs @@ -238,6 +238,17 @@ impl<'a> TaggedValue { } } + pub fn to_string(&self) -> String { + match self { + TaggedValue::String(x) => x.to_string(), + TaggedValue::U32(x) => x.to_string(), + TaggedValue::U64(x) => x.to_string(), + TaggedValue::F64(x) => x.to_string(), + TaggedValue::Bool(x) => x.to_string(), + _ => panic!("Cannot convert to string"), + } + } + pub fn to_primitive_string(&self) -> String { match self { TaggedValue::None => "()".to_string(), diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index d86f464b..e8310384 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -89,10 +89,10 @@ macro_rules! async_node { ProtoNodeIdentifier::new(stringify!($path)), |mut args| { Box::pin(async move { - args.reverse(); - let node = <$path>::new($(graphene_std::any::downcast_node::<$arg, $type>(args.pop().expect("Not enough arguments provided to construct node"))),*); - let any: DynAnyNode<$input, _, _> = graphene_std::any::DynAnyNode::new(node); - Box::new(any) as TypeErasedBox + args.reverse(); + let node = <$path>::new($(graphene_std::any::downcast_node::<$arg, $type>(args.pop().expect("Not enough arguments provided to construct node"))),*); + let any: DynAnyNode<$input, _, _> = graphene_std::any::DynAnyNode::new(node); + Box::new(any) as TypeErasedBox }) }, { @@ -104,7 +104,7 @@ macro_rules! async_node { let params = vec![$(fn_type!($arg, $type)),*]; let mut node_io = NodeIO::<'_, $input>::to_node_io(&node, params); node_io.input = concrete!(<$input as StaticType>::Static); - node_io.input = concrete!(<$input as StaticType>::Static); + node_io.input = concrete!(<$input as StaticType>::Static); // Why are there 2 of them? node_io.output = concrete!(<$output as StaticType>::Static); node_io }, @@ -811,7 +811,7 @@ fn node_registry() -> HashMap, params: []), register_node!(graphene_core::ToGraphicGroupNode, input: GraphicGroup, params: []), register_node!(graphene_core::ToGraphicGroupNode, input: Artboard, params: []), - async_node!(graphene_core::ConstructArtboardNode<_, _, _, _, _>, input: Footprint, output: Artboard, fn_params: [Footprint => GraphicGroup, () => glam::IVec2, () => glam::IVec2, () => Color, () => bool]), + async_node!(graphene_core::ConstructArtboardNode<_, _, _, _, _, _>, input: Footprint, output: Artboard, fn_params: [Footprint => GraphicGroup, () => String, () => glam::IVec2, () => glam::IVec2, () => Color, () => bool]), async_node!(graphene_core::AddArtboardNode<_, _>, input: Footprint, output: ArtboardGroup, fn_params: [Footprint => ArtboardGroup, Footprint => Artboard]), ]; let mut map: HashMap> = HashMap::new();