From b252cc661531a2960ac855fcce42452218959bc7 Mon Sep 17 00:00:00 2001 From: Sebastian Spaink Date: Mon, 21 Aug 2023 22:32:17 -0500 Subject: [PATCH] create save link --- .vscode/settings.json | 5 ---- Cargo.lock | 54 +++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 5 ++++ src/app.rs | 22 +++++++++++++++--- 4 files changed, 74 insertions(+), 12 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 97b6626..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rust-analyzer.linkedProjects": [ - ".\\image_gen\\Cargo.toml" - ] -} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 8ef0b44..16bbefc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -874,6 +874,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc978899517288e3ebbd1a3bfc1d9537dbb87eeab149e53ea490e63bcdff561a" +dependencies = [ + "serde", +] + [[package]] name = "errno" version = "0.3.1" @@ -1248,6 +1257,13 @@ dependencies = [ "tiff", ] +[[package]] +name = "image_gen" +version = "0.1.0" +dependencies = [ + "image", +] + [[package]] name = "indexmap" version = "2.0.0" @@ -1976,6 +1992,7 @@ dependencies = [ "env_logger", "image", "log", + "struct_iterable", "wasm-bindgen-futures", ] @@ -2029,18 +2046,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.163" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.163" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" dependencies = [ "proc-macro2", "quote", @@ -2184,6 +2201,35 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9df65f20698aeed245efdde3628a6b559ea1239bbb871af1b6e3b58c413b2bd1" +[[package]] +name = "struct_iterable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "849a064c6470a650b72e41fa6c057879b68f804d113af92900f27574828e7712" +dependencies = [ + "struct_iterable_derive", + "struct_iterable_internal", +] + +[[package]] +name = "struct_iterable_derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bb939ce88a43ea4e9d012f2f6b4cc789deb2db9d47bad697952a85d6978662c" +dependencies = [ + "erased-serde", + "proc-macro2", + "quote", + "struct_iterable_internal", + "syn 2.0.29", +] + +[[package]] +name = "struct_iterable_internal" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9426b2a0c03e6cc2ea8dbc0168dbbf943f88755e409fb91bcb8f6a268305f4a" + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index c208973..6ee6217 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" edition = "2021" rust-version = "1.65" +[workspace] + +members = ["image_gen"] + [dependencies] egui = "0.22.0" eframe = { version = "0.22.0", default-features = false, features = [ @@ -15,6 +19,7 @@ log = "0.4" egui_extras = { version = "0.22.0", features = ["image"] } image = { version = "0.24.7", features = ["png"] } +struct_iterable = "0.1.1" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/src/app.rs b/src/app.rs index 980a5fa..be10185 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,11 +1,12 @@ use crate::assets::{Assets, Image}; -use eframe::glow::COLOR; -use egui::{Color32, RichText}; +use egui::RichText; use egui_extras::RetainedImage; use std::collections::HashMap; +use struct_iterable::Iterable; const MAX_ROW: i32 = 2; +#[derive(Iterable)] struct Body { color: Option, eyes: Option, @@ -76,9 +77,24 @@ impl eframe::App for App { ); if ui.button(RichText::new("save").size(20.0)).clicked() { + + let mut name: String = "".to_owned(); + + for (field_name, value) in ferris.iter() { + if let Some(string_opt) = value.downcast_ref::>() { + if let Some(string) = string_opt.as_deref() { + if field_name == "color" { + name += string; + } else { + name += &format!("_{}", string); + } + } + } + } + ui.ctx().output_mut(|o| { o.open_url = Some(egui::output::OpenUrl { - url: "https://github.com".to_string(), + url: format!("https://raw.githubusercontent.com/sspaink/rustaceanize.me/master/pregen_crabs/{name}.png"), new_tab: true, }); });