aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/export.rs
diff options
context:
space:
mode:
authorRubén Beltrán del Río <jj@r.bdr.sh>2026-01-16 00:36:23 +0100
committerRubén Beltrán del Río <jj@r.bdr.sh>2026-01-16 00:58:35 +0100
commit4211b2ae06777d5bbe8261a1ab5c0dd057829a35 (patch)
tree15d501e3c101abfa5f6657b023f385e4272fbcc4 /src/handlers/export.rs
parent04b1e6080d99601b8d6343be3140f545cd8f9eae (diff)
Add export image
Diffstat (limited to 'src/handlers/export.rs')
-rw-r--r--src/handlers/export.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/handlers/export.rs b/src/handlers/export.rs
new file mode 100644
index 0000000..7438ef9
--- /dev/null
+++ b/src/handlers/export.rs
@@ -0,0 +1,26 @@
+use std::path::PathBuf;
+
+use crate::AppModel;
+use crate::actions::ImageFormat;
+use crate::dialogs;
+use wmap_renderer::{render_to_png, render_to_svg};
+
+/// Exports the map to an image file in the specified format.
+pub fn export_to_file(model: &AppModel, path: PathBuf, format: ImageFormat) {
+ let result: Result<(), String> = match format {
+ ImageFormat::Png => {
+ render_to_png(&model.map, model.stage_type, &model.render_configuration)
+ .map_err(|e| e.to_string())
+ .and_then(|data| std::fs::write(&path, data).map_err(|e| e.to_string()))
+ }
+ ImageFormat::Svg => {
+ render_to_svg(&model.map, model.stage_type, &model.render_configuration)
+ .map_err(|e| e.to_string())
+ .and_then(|data| std::fs::write(&path, data).map_err(|e| e.to_string()))
+ }
+ };
+
+ if let Err(error) = result {
+ dialogs::show_error(&model.window, "Error Exporting Image", &error);
+ }
+}