no longer need text_boxes_focused

This commit is contained in:
Simon Gardling 2022-04-07 18:47:08 -04:00
parent 2fcc5c4372
commit 8b97f79d55
3 changed files with 10 additions and 27 deletions

View File

@ -86,15 +86,15 @@ impl Default for FunctionEntry {
impl FunctionEntry {
/// Create autocomplete ui and handle user input
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, bool, Option<String>) {
let (output_string, in_focus) = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, Option<String>) {
let output_string = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
let changed = output_string != self.raw_func_str;
if changed {
self.update_string(&output_string);
}
(in_focus, changed, self.get_test_result())
(changed, self.get_test_result())
}
/// Get function's cached test result

View File

@ -314,9 +314,6 @@ pub struct MathApp {
/// Stores whether or not dark mode is enabled
dark_mode: bool,
/// Stores whether or not the text boxes are focused
text_boxes_focused: bool,
/// Stores opened windows/elements for later reference
opened: Opened,
@ -332,7 +329,6 @@ impl Default for MathApp {
exists_error: false,
last_info: (vec![None], Duration::ZERO),
dark_mode: true,
text_boxes_focused: false,
opened: Opened::default(),
settings: AppSettings::default(),
}
@ -460,7 +456,6 @@ impl MathApp {
let functions_len = self.functions.len();
let mut remove_i: Option<usize> = None;
self.text_boxes_focused = false;
self.exists_error = false;
for (i, function) in self.functions.iter_mut().enumerate() {
// Entry for a function
@ -498,11 +493,7 @@ impl MathApp {
);
// Contains the function string in a text box that the user can edit
let (focused, changed, error) = function.auto_complete(ui, i as i32);
if focused {
self.text_boxes_focused = true;
}
let (changed, error) = function.auto_complete(ui, i as i32);
if let Some(error_string) = error {
self.exists_error = true;
@ -548,10 +539,10 @@ impl epi::App for MathApp {
// if text boxes aren't in focus, allow H keybind to toggle side panel.
// this is behind this check as if it wasn't, it would trigger if the user
// presses the h key in a text box as well
if !self.text_boxes_focused {
if !ctx.wants_keyboard_input() {
self.opened
.side_panel
.bitxor_assign(ctx.input().key_down(Key::H));
.bitxor_assign(ctx.input_mut().consume_key(egui::Modifiers::NONE, Key::H));
}
// Initialize fonts
@ -678,8 +669,6 @@ impl epi::App for MathApp {
// If side panel is enabled, show it.
if self.opened.side_panel {
self.side_panel(ctx);
} else {
self.text_boxes_focused = false;
}
// Referenced in plotting code, but needs to be here so it can be later

View File

@ -81,7 +81,7 @@ impl<'a> AutoComplete<'a> {
}
}
pub fn ui(&mut self, ui: &mut egui::Ui, string: String, func_i: i32) -> (String, bool) {
pub fn ui(&mut self, ui: &mut egui::Ui, string: String, func_i: i32) -> String {
let mut new_string = string.clone();
let mut movement: Movement = Movement::None;
@ -97,9 +97,9 @@ impl<'a> AutoComplete<'a> {
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", func_i));
if self.hint.is_none() {
let re = func_edit.id(te_id).ui(ui);
let _ = func_edit.id(te_id).ui(ui);
let return_string = (&new_string).to_string();
return (return_string, re.has_focus());
return return_string;
}
// Put here so these key presses don't interact with other elements
@ -116,18 +116,12 @@ impl<'a> AutoComplete<'a> {
let re = func_edit.id(te_id).ui(ui);
let func_edit_focus = re.has_focus();
if ui.input().key_pressed(Key::ArrowDown) {
movement = Movement::Down;
} else if ui.input().key_pressed(Key::ArrowUp) {
movement = Movement::Up;
}
// if movement != Movement::None {
// println!("{:?}", movement);
// }
self.interact_back(&mut new_string, &movement);
// TODO: fix clicking on labels (no clue why it doesn't work, time to take a walk)
@ -173,7 +167,7 @@ impl<'a> AutoComplete<'a> {
})));
TextEdit::store_state(ui.ctx(), te_id, state);
}
(new_string, func_edit_focus)
new_string
}
}