paiagram_core/export.rs
1//! Definitions for how to export the current diagram to another format, e.g., an image.
2
3use bevy::prelude::*;
4
5pub mod graphviz;
6pub mod oudia;
7// pub mod typst_timetable;
8
9// TODO: plugins
10// TODO: make it so that wasm extensions can use this interface
11// TODO: wasm interface should additionally support requesting fonts
12/// How to export the current world to another format.
13pub trait ExportObject {
14 /// Export contents to a `Vec<u8>` buffer, with optional parameters
15 fn export_to_buffer(&mut self, buffer: &mut Vec<u8>);
16 /// Export contents and save them on disk, with optional parameters
17 fn export_to_file(&mut self) {
18 let mut buffer = Vec::new();
19 self.export_to_buffer(&mut buffer);
20 let mut filename = String::new();
21 filename.push_str(self.filename().as_ref());
22 filename.push_str(self.extension().as_ref());
23 paiagram_rw::write::write_file(filename, move |writer| writer.write_all(&buffer));
24 }
25 /// the filename
26 fn filename(&self) -> impl AsRef<str> {
27 "exported_file"
28 }
29 /// The extension name with the dot
30 fn extension(&self) -> impl AsRef<str>;
31}