Skip to content

Add properties panel entries for artboards #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions editor/src/communication/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,32 @@ mod test {
let (all, non_selected, selected) = verify_order(editor.dispatcher.message_handlers.portfolio_message_handler.active_document_mut());
assert_eq!(all, non_selected.into_iter().chain(selected.into_iter()).collect::<Vec<_>>());
}

#[test]
fn check_if_graphite_file_version_upgrade_is_needed() {
init_logger();
set_uuid_seed(0);
let mut editor = Editor::new();
let test_file = include_str!("./graphite-test-document.graphite");
let responses = editor.handle_message(PortfolioMessage::OpenDocumentFile {
document_name: "Graphite Version Test".into(),
document_serialized_content: test_file.into(),
});

for response in responses {
if let FrontendMessage::DisplayDialogError { title, description } = response {
println!();
println!("-------------------------------------------------");
println!("Failed test due to receiving a DisplayDialogError while loading the graphite sample file!");
println!("This is most likely caused by forgetting to bump the `GRAPHITE_DOCUMENT_VERSION` in `editor/src/consts.rs`");
println!("Once bumping this version number please replace the `graphite-test-document.graphite` with a valid file");
println!("DisplayDialogError details:");
println!("Title: {}", title);
println!("description: {}", description);
println!("-------------------------------------------------");
println!();
panic!()
}
}
}
}
1 change: 1 addition & 0 deletions editor/src/communication/graphite-test-document.graphite
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"graphene_document":{"root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":919378319526168453,"layer_ids":[919378319526168452],"layers":[{"visible":true,"name":null,"data":{"Shape":{"path":[{"MoveTo":{"x":0.0,"y":0.0}},{"LineTo":{"x":1.0,"y":0.0}},{"LineTo":{"x":1.0,"y":1.0}},{"LineTo":{"x":0.0,"y":1.0}},"ClosePath"],"style":{"stroke":null,"fill":{"Solid":{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0}}},"render_index":1,"closed":true}},"transform":{"matrix2":[303.890625,0.0,-0.0,362.10546875],"translation":[-148.83984375,-235.8828125]},"blend_mode":"Normal","opacity":1.0}]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"saved_document_identifier":0,"name":"Untitled Document","layer_metadata":[[[919378319526168452],{"selected":true,"expanded":false}],[[],{"selected":false,"expanded":true}]],"layer_range_selection_reference":[919378319526168452],"movement_handler":{"pan":[-118.8,-45.60000000000001],"panning":false,"snap_tilt":false,"snap_tilt_released":false,"tilt":0.0,"tilting":false,"zoom":1.0,"zooming":false,"snap_zoom":false,"mouse_position":[0.0,0.0]},"artboard_message_handler":{"artboards_graphene_document":{"root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":0,"layer_ids":[],"layers":[]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"artboard_ids":[]},"properties_panel_message_handler":{"active_selection":[[919378319526168452],"Artwork"]},"overlays_visible":true,"snapping_enabled":true,"view_mode":"Normal","version":"0.0.5"}
2 changes: 1 addition & 1 deletion editor/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ pub const FILE_EXPORT_SUFFIX: &str = ".svg";
pub const COLOR_ACCENT: Color = Color::from_unsafe(0x00 as f32 / 255., 0xA8 as f32 / 255., 0xFF as f32 / 255.);

// Document
pub const GRAPHITE_DOCUMENT_VERSION: &str = "0.0.4";
pub const GRAPHITE_DOCUMENT_VERSION: &str = "0.0.5";
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f32 = 1.05;
14 changes: 13 additions & 1 deletion editor/src/document/artboard_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::message_prelude::*;
use graphene::color::Color;
use graphene::document::Document as GrapheneDocument;
use graphene::layers::style::{self, Fill, ViewMode};
use graphene::DocumentResponse;
use graphene::Operation as DocumentOperation;

use glam::DAffine2;
Expand Down Expand Up @@ -31,7 +32,18 @@ impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
// Sub-messages
#[remain::unsorted]
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(*operation) {
Ok(_) => (),
Ok(Some(document_responses)) => {
for response in document_responses {
match &response {
DocumentResponse::LayerChanged { path } => responses.push_back(PropertiesPanelMessage::CheckSelectedWasUpdated { path: path.clone() }.into()),
DocumentResponse::DeletedLayer { path } => responses.push_back(PropertiesPanelMessage::CheckSelectedWasDeleted { path: path.clone() }.into()),
DocumentResponse::DocumentChanged => responses.push_back(ArtboardMessage::RenderArtboards.into()),
_ => {}
};
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
}
Ok(None) => {}
Err(e) => log::error!("Artboard Error: {:?}", e),
},

Expand Down
20 changes: 17 additions & 3 deletions editor/src/document/document_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::clipboards::Clipboard;
use super::layer_panel::{layer_panel_entry, LayerDataTypeDiscriminant, LayerMetadata, LayerPanelEntry, RawBuffer};
use super::properties_panel_message_handler::PropertiesPanelMessageHandlerData;
use super::utility_types::TargetDocument;
use super::utility_types::{AlignAggregate, AlignAxis, DocumentSave, FlipAxis};
use super::{vectorize_layer_metadata, PropertiesPanelMessageHandler};
use super::{ArtboardMessageHandler, MovementMessageHandler, OverlaysMessageHandler, TransformLayerMessageHandler};
Expand Down Expand Up @@ -503,7 +505,6 @@ impl DocumentMessageHandler {
impl PropertyHolder for DocumentMessageHandler {
fn properties(&self) -> WidgetLayout {
WidgetLayout::new(vec![LayoutRow::Row {
name: "".into(),
widgets: vec![
WidgetHolder::new(Widget::OptionalInput(OptionalInput {
checked: self.snapping_enabled,
Expand Down Expand Up @@ -704,7 +705,14 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
}
#[remain::unsorted]
PropertiesPanel(message) => {
self.properties_panel_message_handler.process_action(message, &self.graphene_document, responses);
self.properties_panel_message_handler.process_action(
message,
PropertiesPanelMessageHandlerData {
artwork_document: &self.graphene_document,
artboard_document: &self.artboard_message_handler.artboards_graphene_document,
},
responses,
);
}

// Messages
Expand All @@ -721,7 +729,13 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
if selected_paths.is_empty() {
responses.push_back(PropertiesPanelMessage::ClearSelection.into())
} else {
responses.push_back(PropertiesPanelMessage::SetActiveLayers { paths: selected_paths }.into())
responses.push_back(
PropertiesPanelMessage::SetActiveLayers {
paths: selected_paths,
document: TargetDocument::Artwork,
}
.into(),
)
}

// TODO: Correctly update layer panel in clear_selection instead of here
Expand Down
6 changes: 4 additions & 2 deletions editor/src/document/properties_panel_message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::message_prelude::*;

use super::utility_types::TargetDocument;

use graphene::layers::style::{Fill, Stroke};
use serde::{Deserialize, Serialize};

Expand All @@ -15,10 +17,10 @@ pub enum PropertiesPanelMessage {
ModifyStroke { stroke: Stroke },
ModifyTransform { value: f64, transform_op: TransformOp },
ResendActiveProperties,
SetActiveLayers { paths: Vec<Vec<LayerId>> },
SetActiveLayers { paths: Vec<Vec<LayerId>>, document: TargetDocument },
}

#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
#[derive(PartialEq, Clone, Copy, Debug, Serialize, Deserialize)]
pub enum TransformOp {
X,
Y,
Expand Down
Loading