Skip to content

Commit 2dfcac7

Browse files
committed
Add viewing/editing layer names, add Blend Mode node, and clean up Layer node
1 parent 165c747 commit 2dfcac7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+431
-457
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
// VS Code config
4444
"html.format.wrapLineLength": 200,
4545
"files.eol": "\n",
46-
"files.insertFinalNewline": true
46+
"files.insertFinalNewline": true,
47+
"files.associations": {
48+
"*.graphite": "json"
49+
}
4750
}

demo-artwork/_upgrade-to-document-nodes.py_archive

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -267,60 +267,6 @@ def update_layer(layer, indent, layer_node_id, next_id, opacity):
267267
"lambda": False
268268
}
269269
},
270-
{
271-
"Network": {
272-
"Concrete": {
273-
"name": "alloc::string::String",
274-
"size": 12,
275-
"align": 4
276-
}
277-
}
278-
},
279-
{
280-
"Network": {
281-
"Concrete": {
282-
"name": "graphene_core::raster::adjustments::BlendMode",
283-
"size": 4,
284-
"align": 4
285-
}
286-
}
287-
},
288-
{
289-
"Network": {
290-
"Concrete": {
291-
"name": "f32",
292-
"size": 4,
293-
"align": 4
294-
}
295-
}
296-
},
297-
{
298-
"Network": {
299-
"Concrete": {
300-
"name": "bool",
301-
"size": 1,
302-
"align": 1
303-
}
304-
}
305-
},
306-
{
307-
"Network": {
308-
"Concrete": {
309-
"name": "bool",
310-
"size": 1,
311-
"align": 1
312-
}
313-
}
314-
},
315-
{
316-
"Network": {
317-
"Concrete": {
318-
"name": "bool",
319-
"size": 1,
320-
"align": 1
321-
}
322-
}
323-
},
324270
{
325271
"Network": {
326272
"Fn": [

demo-artwork/just-a-potted-cactus-v2.graphite

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

demo-artwork/valley-of-spires-v2.graphite

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

document-legacy/src/document.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,13 +1031,6 @@ impl Document {
10311031
layer.visible = visible;
10321032
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
10331033
}
1034-
Operation::SetLayerName { path, name } => {
1035-
self.mark_as_dirty(&path)?;
1036-
let layer = self.layer_mut(&path)?;
1037-
layer.name = if name.as_str() == "" { None } else { Some(name) };
1038-
1039-
Some(vec![LayerChanged { path }])
1040-
}
10411034
Operation::SetLayerBlendMode { path, blend_mode } => {
10421035
self.mark_as_dirty(&path)?;
10431036
self.layer_mut(&path)?.blend_mode = blend_mode;

document-legacy/src/document_metadata.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ impl DocumentMetadata {
215215
}
216216

217217
fn first_child_layer<'a>(graph: &'a NodeNetwork, node: &DocumentNode) -> Option<(&'a DocumentNode, NodeId)> {
218-
graph.primary_flow_from_node(Some(node.inputs[0].as_node()?)).find(|(node, _)| node.name == "Layer")
218+
graph.primary_flow_from_node(Some(node.inputs[0].as_node()?)).find(|(node, _)| node.is_layer())
219219
}
220+
220221
fn sibling_below<'a>(graph: &'a NodeNetwork, node: &DocumentNode) -> Option<(&'a DocumentNode, NodeId)> {
221-
node.inputs[7].as_node().and_then(|id| graph.nodes.get(&id).filter(|node| node.name == "Layer").map(|node| (node, id)))
222+
let construct_layer_node = &node.inputs[1];
223+
construct_layer_node.as_node().and_then(|id| graph.nodes.get(&id).filter(|node| node.is_layer()).map(|node| (node, id)))
222224
}
223225

224226
// transforms
@@ -265,7 +267,7 @@ pub fn is_folder(layer: LayerNodeIdentifier, network: &NodeNetwork) -> bool {
265267
|| network
266268
.primary_flow_from_node(Some(layer.to_node()))
267269
.skip(1)
268-
.any(|(node, _)| node.name == "Artboard" || node.name == "Layer")
270+
.any(|(node, _)| node.name == "Artboard" || node.is_layer())
269271
}
270272

271273
// click targets
@@ -640,7 +642,7 @@ pub struct NodeRelations {
640642
}
641643

642644
fn is_layer_node(node: NodeId, network: &NodeNetwork) -> bool {
643-
node == LayerNodeIdentifier::ROOT.to_node() || network.nodes.get(&node).is_some_and(|node| node.name == "Layer")
645+
node == LayerNodeIdentifier::ROOT.to_node() || network.nodes.get(&node).is_some_and(|node| node.is_layer())
644646
}
645647

646648
#[test]

document-legacy/src/operation.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ pub enum Operation {
107107
path: Vec<LayerId>,
108108
visible: bool,
109109
},
110-
SetLayerName {
111-
path: Vec<LayerId>,
112-
name: String,
113-
},
114110
SetLayerPreserveAspect {
115111
layer_path: Vec<LayerId>,
116112
preserve_aspect: bool,

editor/src/messages/portfolio/document/document_message.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ pub enum DocumentMessage {
159159
layer_path: Vec<LayerId>,
160160
set_expanded: bool,
161161
},
162-
SetLayerName {
163-
layer_path: Vec<LayerId>,
164-
name: String,
165-
},
166162
SetOpacityForSelectedLayers {
167163
opacity: f64,
168164
},

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Default for DocumentMessageHandler {
8282
document_legacy: DocumentLegacy::default(),
8383
saved_document_identifier: 0,
8484
auto_saved_document_identifier: 0,
85-
name: String::from("Untitled Document"),
85+
name: DEFAULT_DOCUMENT_NAME.to_string(),
8686
version: GRAPHITE_DOCUMENT_VERSION.to_string(),
8787
commit_hash: crate::application::GRAPHITE_GIT_COMMIT_HASH.to_string(),
8888

@@ -211,7 +211,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
211211
// Messages
212212
AbortTransaction => {
213213
if !self.undo_in_progress {
214-
self.undo(responses).unwrap_or_else(|e| warn!("{e}"));
214+
self.undo(responses);
215215
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
216216
}
217217
}
@@ -329,8 +329,8 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
329329
responses.add_front(DocumentMessage::DirtyRenderDocument);
330330
}
331331
}
332-
DocumentHistoryBackward => self.undo(responses).unwrap_or_else(|e| warn!("{e}")),
333-
DocumentHistoryForward => self.redo(responses).unwrap_or_else(|e| warn!("{e}")),
332+
DocumentHistoryBackward => self.undo(responses),
333+
DocumentHistoryForward => self.redo(responses),
334334
DocumentStructureChanged => {
335335
let data_buffer: RawBuffer = self.serialize_root().as_slice().into();
336336
responses.add(FrontendMessage::UpdateDocumentLayerTreeStructure { data_buffer })
@@ -577,7 +577,11 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
577577

578578
responses.add(DocumentMessage::StartTransaction);
579579

580-
let image_frame = ImageFrame { image, transform: DAffine2::IDENTITY };
580+
let image_frame = ImageFrame {
581+
image,
582+
transform: DAffine2::IDENTITY,
583+
blend_mode: BlendMode::Normal,
584+
};
581585

582586
use crate::messages::tool::common_functionality::graph_modification_utils;
583587
let layer = graph_modification_utils::new_image_layer(image_frame, generate_uuid(), self.new_layer_parent(), responses);
@@ -649,7 +653,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
649653
});
650654
}
651655
RollbackTransaction => {
652-
self.rollback(responses).unwrap_or_else(|e| warn!("{e}"));
656+
self.rollback(responses);
653657
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
654658
}
655659
SaveDocument => {
@@ -771,15 +775,6 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
771775
responses.add(DocumentStructureChanged);
772776
responses.add(LayerChanged { affected_layer_path: layer_path })
773777
}
774-
SetLayerName { layer_path, name } => {
775-
if let Some(layer) = self.layer_panel_entry_from_path(&layer_path, &render_data) {
776-
// Only save the history state if the name actually changed to something different
777-
if layer.name != name {
778-
self.backup(responses);
779-
responses.add(DocumentOperation::SetLayerName { path: layer_path, name });
780-
}
781-
}
782-
}
783778
SetOpacityForSelectedLayers { opacity } => {
784779
self.backup(responses);
785780
let opacity = opacity.clamp(0., 1.);
@@ -1238,9 +1233,9 @@ impl DocumentMessageHandler {
12381233
});
12391234
}
12401235

1241-
pub fn rollback(&mut self, responses: &mut VecDeque<Message>) -> Result<(), EditorError> {
1236+
pub fn rollback(&mut self, responses: &mut VecDeque<Message>) {
12421237
self.backup(responses);
1243-
self.undo(responses)
1238+
self.undo(responses);
12441239
// TODO: Consider if we should check if the document is saved
12451240
}
12461241

@@ -1257,72 +1252,62 @@ impl DocumentMessageHandler {
12571252
DocumentSave { document, layer_metadata }
12581253
}
12591254

1260-
pub fn undo(&mut self, responses: &mut VecDeque<Message>) -> Result<(), EditorError> {
1255+
pub fn undo(&mut self, responses: &mut VecDeque<Message>) {
12611256
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
12621257
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
12631258

12641259
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
12651260

1266-
match self.document_undo_history.pop_back() {
1267-
Some(DocumentSave { document, layer_metadata }) => {
1268-
// Update the currently displayed layer on the Properties panel if the selection changes after an undo action
1269-
// Also appropriately update the Properties panel if an undo action results in a layer being deleted
1270-
let prev_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then_some(layer_id.clone())).collect();
1271-
1272-
if prev_selected_paths != selected_paths {
1273-
responses.add(BroadcastEvent::SelectionChanged);
1274-
}
1261+
if let Some(DocumentSave { document, layer_metadata }) = self.document_undo_history.pop_back() {
1262+
// Update the currently displayed layer on the Properties panel if the selection changes after an undo action
1263+
// Also appropriately update the Properties panel if an undo action results in a layer being deleted
1264+
let prev_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then_some(layer_id.clone())).collect();
12751265

1276-
let document_save = self.replace_document(DocumentSave { document, layer_metadata });
1277-
1278-
self.document_redo_history.push_back(document_save);
1279-
if self.document_redo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1280-
self.document_redo_history.pop_front();
1281-
}
1266+
if prev_selected_paths != selected_paths {
1267+
responses.add(BroadcastEvent::SelectionChanged);
1268+
}
12821269

1283-
for layer in self.layer_metadata.keys() {
1284-
responses.add(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() })
1285-
}
1270+
let document_save = self.replace_document(DocumentSave { document, layer_metadata });
12861271

1287-
responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
1272+
self.document_redo_history.push_back(document_save);
1273+
if self.document_redo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1274+
self.document_redo_history.pop_front();
1275+
}
12881276

1289-
Ok(())
1277+
for layer in self.layer_metadata.keys() {
1278+
responses.add(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() })
12901279
}
1291-
None => Err(EditorError::NoTransactionInProgress),
1280+
1281+
responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
12921282
}
12931283
}
12941284

1295-
pub fn redo(&mut self, responses: &mut VecDeque<Message>) -> Result<(), EditorError> {
1285+
pub fn redo(&mut self, responses: &mut VecDeque<Message>) {
12961286
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
12971287
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
12981288

12991289
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
13001290

1301-
match self.document_redo_history.pop_back() {
1302-
Some(DocumentSave { document, layer_metadata }) => {
1303-
// Update currently displayed layer on property panel if selection changes after redo action
1304-
// Also appropriately update property panel if redo action results in a layer being added
1305-
let next_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then_some(layer_id.clone())).collect();
1306-
1307-
if next_selected_paths != selected_paths {
1308-
responses.add(BroadcastEvent::SelectionChanged);
1309-
}
1310-
1311-
let document_save = self.replace_document(DocumentSave { document, layer_metadata });
1312-
self.document_undo_history.push_back(document_save);
1313-
if self.document_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1314-
self.document_undo_history.pop_front();
1315-
}
1291+
if let Some(DocumentSave { document, layer_metadata }) = self.document_redo_history.pop_back() {
1292+
// Update currently displayed layer on property panel if selection changes after redo action
1293+
// Also appropriately update property panel if redo action results in a layer being added
1294+
let next_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then_some(layer_id.clone())).collect();
13161295

1317-
for layer in self.layer_metadata.keys() {
1318-
responses.add(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() })
1319-
}
1296+
if next_selected_paths != selected_paths {
1297+
responses.add(BroadcastEvent::SelectionChanged);
1298+
}
13201299

1321-
responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
1300+
let document_save = self.replace_document(DocumentSave { document, layer_metadata });
1301+
self.document_undo_history.push_back(document_save);
1302+
if self.document_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1303+
self.document_undo_history.pop_front();
1304+
}
13221305

1323-
Ok(())
1306+
for layer in self.layer_metadata.keys() {
1307+
responses.add(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() })
13241308
}
1325-
None => Err(EditorError::NoTransactionInProgress),
1309+
1310+
responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
13261311
}
13271312
}
13281313

editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a> ModifyInputsContext<'a> {
5252
error!("Tried to modify root layer");
5353
return None;
5454
};
55-
while document.network.nodes.get(&id)?.name != "Layer" {
55+
while !document.network.nodes.get(&id)?.is_layer() {
5656
id = document.outwards_links.get(&id)?.first().copied()?;
5757
}
5858
document.layer_node = Some(id);
@@ -112,7 +112,7 @@ impl<'a> ModifyInputsContext<'a> {
112112
// Locate the node output of the first sibling layer to the new layer
113113
if let Some((node_id, output_index)) = self.skip_artboards(&mut output) {
114114
let sibling_node = self.network.nodes.get(&node_id)?;
115-
if sibling_node.name == "Layer" {
115+
if sibling_node.is_layer() {
116116
// There is already a layer node
117117
sibling_layer = Some(NodeOutput::new(node_id, 0));
118118
} else {
@@ -125,8 +125,8 @@ impl<'a> ModifyInputsContext<'a> {
125125
// Skip some layer nodes
126126
for _ in 0..skip_layer_nodes {
127127
if let Some(old_sibling) = &sibling_layer {
128-
output = NodeOutput::new(old_sibling.node_id, 7);
129-
sibling_layer = self.network.nodes.get(&old_sibling.node_id)?.inputs[7].as_node().map(|node| NodeOutput::new(node, 0));
128+
output = NodeOutput::new(old_sibling.node_id, 1);
129+
sibling_layer = self.network.nodes.get(&old_sibling.node_id)?.inputs[1].as_node().map(|node| NodeOutput::new(node, 0));
130130
shift = IVec2::new(0, 3);
131131
}
132132
}
@@ -139,14 +139,14 @@ impl<'a> ModifyInputsContext<'a> {
139139
// Create node
140140
let layer_node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
141141
let new_id = if let Some(sibling_layer) = sibling_layer {
142-
self.insert_between(new_id, sibling_layer, output, layer_node, 7, 0, shift)
142+
self.insert_between(new_id, sibling_layer, output, layer_node, 1, 0, shift)
143143
} else {
144144
self.insert_node_before(new_id, output.node_id, output.node_output_index, layer_node, shift)
145145
};
146146

147147
// Update the document metadata structure
148148
if let Some(new_id) = new_id {
149-
let parent = if self.network.nodes.get(&output_node_id).is_some_and(|node| node.name == "Layer") {
149+
let parent = if self.network.nodes.get(&output_node_id).is_some_and(|node| node.is_layer()) {
150150
LayerNodeIdentifier::new(output_node_id, self.network)
151151
} else {
152152
LayerNodeIdentifier::ROOT
@@ -498,7 +498,7 @@ impl<'a> ModifyInputsContext<'a> {
498498

499499
LayerNodeIdentifier::new(id, self.network).delete(self.document_metadata);
500500

501-
let new_input = node.inputs[7].clone();
501+
let new_input = node.inputs[1].clone();
502502
let deleted_position = node.metadata.position;
503503

504504
for post_node in self.outwards_links.get(&id).unwrap_or(&Vec::new()) {

editor/src/messages/portfolio/document/node_graph/node_graph_message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ pub enum NodeGraphMessage {
103103
node_id: NodeId,
104104
hidden: bool,
105105
},
106+
SetName {
107+
node_id: NodeId,
108+
name: String,
109+
},
110+
SetNameImpl {
111+
node_id: NodeId,
112+
name: String,
113+
},
106114
TogglePreview {
107115
node_id: NodeId,
108116
},

0 commit comments

Comments
 (0)