Skip to content

Commit

Permalink
fix: reset processes whenever an edit is (going to be) made
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
DakshG07 committed Sep 2, 2023
1 parent 5fb026c commit 4070bb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 19 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Pos2>, // Current path
selected: usize, // Current selected node (edit mode)
processed: Vec<Process>, // Processed fields
overlay: Option<egui::DroppedFile>, // Uploaded overlay
result: Option<String>, // Final string
height: f32, // Height of field
width: f32, // Width of field
scale: f32, // Scale to display
mode: CursorMode, // Cursor mode
path: Vec<Pos2>, // Current path
selected: usize, // Current selected node (edit mode)
processed: Vec<Process>, // Processed fields
#[serde(skip)]
overlay: Option<RetainedImage>, // Uploaded overlay
result: Option<String>, // Final string
}

#[derive(serde::Deserialize, serde::Serialize, Eq, PartialEq)]
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<Pos2> = None;
// Line stroke
Expand Down

0 comments on commit 4070bb8

Please sign in to comment.