From 683a471dbbcce6ecc77698ecd5f0b45e45ceddb6 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Sun, 3 Apr 2022 14:24:59 -0400 Subject: [PATCH] fix autocomplete pop ups --- src/function.rs | 4 ++-- src/math_app.rs | 2 +- src/widgets.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/function.rs b/src/function.rs index e55a66d..2b411a3 100644 --- a/src/function.rs +++ b/src/function.rs @@ -91,9 +91,9 @@ impl FunctionEntry { pub fn get_func_raw(&self) -> String { self.raw_func_str.to_string() } pub fn auto_complete( - &mut self, ui: &mut egui::Ui, string: &mut String, + &mut self, ui: &mut egui::Ui, string: &mut String, i: i32, ) -> (bool, bool, Option) { - let (output_string, in_focus) = self.autocomplete.ui(ui, string.to_string()); + let (output_string, in_focus) = self.autocomplete.ui(ui, string.to_string(), i); let changed = output_string != *string; if changed { diff --git a/src/math_app.rs b/src/math_app.rs index 6877e09..bc31dac 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -485,7 +485,7 @@ impl MathApp { // Contains the function string in a text box that the user can edit let (focused, changed, error) = - function.auto_complete(ui, &mut self.func_strs[i]); + function.auto_complete(ui, &mut self.func_strs[i], i as i32); if focused { self.text_boxes_focused = true; } diff --git a/src/widgets.rs b/src/widgets.rs index 2784cfa..8bc1716 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -33,13 +33,13 @@ impl AutoComplete { } } - pub fn ui(&mut self, ui: &mut egui::Ui, string: String) -> (String, bool) { + pub fn ui(&mut self, ui: &mut egui::Ui, string: String, func_i: i32) -> (String, bool) { let mut new_string = string.clone(); // Put here so these key presses don't interact with other elements let enter_pressed = ui.input_mut().consume_key(Modifiers::NONE, Key::Enter); let tab_pressed = ui.input_mut().consume_key(Modifiers::NONE, Key::Tab); - let te_id = ui.make_persistent_id("text_edit_ac".to_string()); + let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", func_i)); // update self self.changed(string.clone());