From 2fe0eebb6dd51b12a17af002a12a11e4f478fc48 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 1 Mar 2022 21:53:27 -0500 Subject: [PATCH] add option to remove functions --- src/egui_app.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/egui_app.rs b/src/egui_app.rs index b09f72a..88761a4 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -246,12 +246,20 @@ impl epi::App for MathApp { egui::Slider::new(&mut self.integral_num, INTEGRAL_NUM_RANGE).text("Interval"), ); + let mut remove_i: Option = None; for (i, function) in self.functions.iter_mut().enumerate() { let mut integral_toggle: bool = false; let integral_enabled = function.integral; // Entry for a function ui.horizontal(|ui| { ui.label("Function: "); + if ui + .add(Button::new("X")) + .on_hover_text("Delete Function") + .clicked() + { + remove_i = Some(i); + } if ui .add(Button::new("∫")) .on_hover_text(if integral_enabled { @@ -292,6 +300,13 @@ impl epi::App for MathApp { } } + if self.functions.len() > 1 { + if let Some(remove_i_unwrap) = remove_i { + self.functions.remove(remove_i_unwrap); + self.func_strs.remove(remove_i_unwrap); + } + } + // Open Source and Licensing information ui.hyperlink_to( "I'm Opensource!",