mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
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
This commit is contained in:
parent
5ed5f55dfb
commit
cf496668fb
11 changed files with 52 additions and 19 deletions
|
@ -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: Into<GraphicGroup>>(data: Data) -> GraphicGroup {
|
|||
data.into()
|
||||
}
|
||||
|
||||
pub struct ConstructArtboardNode<Contents, Location, Dimensions, Background, Clip> {
|
||||
pub struct ConstructArtboardNode<Contents, Label, Location, Dimensions, Background, Clip> {
|
||||
contents: Contents,
|
||||
label: Label,
|
||||
location: Location,
|
||||
dimensions: Dimensions,
|
||||
background: Background,
|
||||
|
@ -177,6 +180,7 @@ pub struct ConstructArtboardNode<Contents, Location, Dimensions, Background, Cli
|
|||
async fn construct_artboard<Fut: Future<Output = GraphicGroup>>(
|
||||
mut footprint: Footprint,
|
||||
contents: impl Node<Footprint, Output = Fut>,
|
||||
label: String,
|
||||
location: IVec2,
|
||||
dimensions: IVec2,
|
||||
background: Color,
|
||||
|
@ -184,8 +188,10 @@ async fn construct_artboard<Fut: Future<Output = GraphicGroup>>(
|
|||
) -> 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,
|
||||
|
|
|
@ -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<Color> {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
let transform: String = format_transform_matrix(self.transform * render.transform);
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
|
||||
// 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");
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
|||
register_node!(graphene_core::ToGraphicGroupNode, input: ImageFrame<Color>, 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<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> = HashMap::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue