From 4070bb85e0a1b172047a2b1e3f7d62bcbdb1ee36 Mon Sep 17 00:00:00 2001 From: Dukk Date: Sat, 2 Sep 2023 18:43:02 -0400 Subject: [PATCH] fix: reset processes whenever an edit is (going to be) made Instead of making things unnecessarily complicated everywhere, I just decided that switching to any tools that could *possibly* edit the path will result in the processes being reset (even if you don't actually edit the path). --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/app.rs | 28 +++++++++++++++++++--------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7578b2..5560208 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -769,6 +769,16 @@ dependencies = [ "winit", ] +[[package]] +name = "egui_extras" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9278f4337b526f0d57e5375e5a7340a311fa6ee8f9fcc75721ac50af13face02" +dependencies = [ + "egui", + "serde", +] + [[package]] name = "egui_glow" version = "0.22.0" @@ -1648,6 +1658,7 @@ version = "0.1.0" dependencies = [ "eframe", "egui", + "egui_extras", "env_logger", "log", "serde", diff --git a/Cargo.toml b/Cargo.toml index a68c8bb..0e26fb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ log = "0.4" # You only need serde if you want app persistence: serde = { version = "1", features = ["derive"] } +egui_extras = "0.22.0" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/src/app.rs b/src/app.rs index ff69eb0..5d8d4a8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7,6 +7,7 @@ */ use eframe::egui::Visuals; use egui::{Color32, Pos2, Sense, Stroke, Vec2}; +use egui_extras::RetainedImage; // Uncomment this section to get access to the console_log macro // Use console_log to print things to console. println macro doesn't work // here, so you'll need it. @@ -40,15 +41,16 @@ macro_rules! console_log { pub struct PathyApp { // this how you opt-out of serialization of a member //#[serde(skip)] - height: f32, // Height of field - width: f32, // Width of field - scale: f32, // Scale to display - mode: CursorMode, // Cursor mode - path: Vec, // Current path - selected: usize, // Current selected node (edit mode) - processed: Vec, // Processed fields - overlay: Option, // Uploaded overlay - result: Option, // Final string + height: f32, // Height of field + width: f32, // Width of field + scale: f32, // Scale to display + mode: CursorMode, // Cursor mode + path: Vec, // Current path + selected: usize, // Current selected node (edit mode) + processed: Vec, // Processed fields + #[serde(skip)] + overlay: Option, // Uploaded overlay + result: Option, // Final string } #[derive(serde::Deserialize, serde::Serialize, Eq, PartialEq)] @@ -297,18 +299,24 @@ impl eframe::App for PathyApp { } if ui.button("Create").clicked() { *mode = CursorMode::Create; + // Reset processes + *processed = Vec::new(); } if ui.button("Edit").clicked() { *mode = CursorMode::Edit; + *processed = Vec::new(); } if ui.button("Delete").clicked() { *mode = CursorMode::Delete; + *processed = Vec::new(); } if ui.button("Trim").clicked() { *mode = CursorMode::Trim; + *processed = Vec::new(); } if ui.button("Clear").clicked() { *path = Vec::new(); // Clear path + *processed = Vec::new(); } if ui.button("Preprocess").clicked() { *processed = Self::preprocess(path, (*scale, aspecty), (*width, *height)); @@ -338,6 +346,8 @@ impl eframe::App for PathyApp { Color32::from_gray(64), Stroke::new(5.0, Color32::WHITE), ); + // Check for dropped files + // // Variable we'll use to render lines let mut prev: Option = None; // Line stroke