File picker on saving on desktop

This commit is contained in:
Piotr Siuszko 2023-12-08 08:53:08 +01:00
parent a1675b6892
commit 0d85d6a2e1
1 changed files with 13 additions and 9 deletions

View File

@ -3,6 +3,7 @@ use std::{collections::HashMap, io::Cursor};
use egui::{CollapsingHeader, Color32, DroppedFile, FontFamily, FontId, Image, RichText, Vec2}; use egui::{CollapsingHeader, Color32, DroppedFile, FontFamily, FontId, Image, RichText, Vec2};
use image::DynamicImage; use image::DynamicImage;
use rfd::FileDialog;
use serde_json::Value; use serde_json::Value;
use texture_packer::{importer::ImageImporter, TexturePacker, TexturePackerConfig}; use texture_packer::{importer::ImageImporter, TexturePacker, TexturePackerConfig};
pub const MY_ACCENT_COLOR32: Color32 = Color32::from_rgb(230, 102, 1); pub const MY_ACCENT_COLOR32: Color32 = Color32::from_rgb(230, 102, 1);
@ -211,15 +212,18 @@ impl TemplateApp {
{ {
let data = self.data.clone().unwrap().data; let data = self.data.clone().unwrap().data;
use std::io::Write; use std::io::Write;
let mut file = std::fs::File::create("result.png").unwrap(); let path_buf = FileDialog::new().set_directory(".").add_filter("Image", &["png"]).set_file_name("output.png").save_file();
let write_result = file.write_all(&data); if let Some(path) = path_buf {
if write_result.is_err() { let mut file = std::fs::File::create(path).unwrap();
self.error = Some(format!( let write_result = file.write_all(&data);
"Could not make atlas, error: {:?}", if write_result.is_err() {
write_result.unwrap_err() self.error = Some(format!(
)); "Could not make atlas, error: {:?}",
} else { write_result.unwrap_err()
println!("Output texture stored in {:?}", file); ));
} else {
println!("Output texture stored in {:?}", file);
}
} }
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]