-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add animation export support to the File > Export dialog #4156
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| use graphite_editor::messages::frontend::utility_types::ExportAnimationFrame; | ||
| #[cfg(target_os = "macos")] | ||
| use graphite_editor::messages::layout::utility_types::layout_widget::LayoutTarget; | ||
| use graphite_editor::messages::prelude::FrontendMessage; | ||
|
|
@@ -59,6 +60,61 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD | |
| context: SaveFileDialogContext::File { content }, | ||
| }); | ||
| } | ||
| FrontendMessage::TriggerExportAnimation { | ||
| name, | ||
| extension, | ||
| mime, | ||
| size, | ||
| folder, | ||
| frames, | ||
| } => { | ||
| // Materialize each frame to bytes; SVG strings are encoded as UTF-8. | ||
| // Raster-needs-canvas-rasterize frames can't be encoded here without a Rust SVG rasterizer, | ||
| // so fall through to the frontend zip path in that case. | ||
| // TODO: This fallback is inconsistent with the desktop folder-save flow for the rest of the animation | ||
| // export — desktop users will see a .zip download instead of a folder. Once SVG rasterization moves to | ||
| // Rust (resvg), this fallback can be removed and all frame paths can save into the chosen folder. | ||
| let mut needs_frontend_rasterization = false; | ||
| let mut materialized = Vec::with_capacity(frames.len()); | ||
| // Dynamic zero-pad width so files keep sorting in playback order beyond 9,999 frames. | ||
| let pad_width = frames.len().to_string().len().max(4); | ||
| let safe_base = graphite_editor::messages::frontend::utility_types::sanitize_filename_component(&name); | ||
| for (index, frame) in frames.iter().enumerate() { | ||
| let filename = format!("{safe_base}_{:0pad$}.{extension}", index + 1, pad = pad_width); | ||
| let bytes = match frame { | ||
| ExportAnimationFrame::Svg(svg) if extension == "svg" => svg.as_bytes().to_vec(), | ||
| ExportAnimationFrame::Bytes(bytes) => bytes.to_vec(), | ||
| ExportAnimationFrame::Svg(_) => { | ||
| needs_frontend_rasterization = true; | ||
| break; | ||
| } | ||
| }; | ||
| materialized.push((filename, bytes)); | ||
| } | ||
|
|
||
| if needs_frontend_rasterization { | ||
| return Some(FrontendMessage::TriggerExportAnimation { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Forwarding (Based on your team's feedback about aligning behavior with comments and TODO expectations.) Prompt for AI agents |
||
| name, | ||
| extension, | ||
| mime, | ||
| size, | ||
| folder, | ||
| frames, | ||
| }); | ||
| } | ||
|
|
||
| // The dialog name is the folder the frames go into (analogous to the .zip on web). | ||
| dispatcher.respond(DesktopFrontendMessage::SaveFileDialog { | ||
| title: "Save Animation Frames Folder As".to_string(), | ||
| default_filename: safe_base, | ||
| default_folder: folder, | ||
| filters: Vec::new(), | ||
| context: SaveFileDialogContext::MultipleFiles { | ||
| files: materialized, | ||
| expected_extension: extension, | ||
| }, | ||
| }); | ||
| } | ||
| FrontendMessage::TriggerVisitLink { url } => { | ||
| dispatcher.respond(DesktopFrontendMessage::OpenUrl(url)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Sanitize generated frame names before joining them to the export folder.
Prompt for AI agents