no longer need text_boxes_focused
This commit is contained in:
parent
2fcc5c4372
commit
8b97f79d55
@ -86,15 +86,15 @@ impl Default for FunctionEntry {
|
|||||||
|
|
||||||
impl FunctionEntry {
|
impl FunctionEntry {
|
||||||
/// Create autocomplete ui and handle user input
|
/// Create autocomplete ui and handle user input
|
||||||
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, bool, Option<String>) {
|
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, Option<String>) {
|
||||||
let (output_string, in_focus) = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
|
let output_string = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
|
||||||
|
|
||||||
let changed = output_string != self.raw_func_str;
|
let changed = output_string != self.raw_func_str;
|
||||||
if changed {
|
if changed {
|
||||||
self.update_string(&output_string);
|
self.update_string(&output_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
(in_focus, changed, self.get_test_result())
|
(changed, self.get_test_result())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get function's cached test result
|
/// Get function's cached test result
|
||||||
|
|||||||
@ -314,9 +314,6 @@ pub struct MathApp {
|
|||||||
/// Stores whether or not dark mode is enabled
|
/// Stores whether or not dark mode is enabled
|
||||||
dark_mode: bool,
|
dark_mode: bool,
|
||||||
|
|
||||||
/// Stores whether or not the text boxes are focused
|
|
||||||
text_boxes_focused: bool,
|
|
||||||
|
|
||||||
/// Stores opened windows/elements for later reference
|
/// Stores opened windows/elements for later reference
|
||||||
opened: Opened,
|
opened: Opened,
|
||||||
|
|
||||||
@ -332,7 +329,6 @@ impl Default for MathApp {
|
|||||||
exists_error: false,
|
exists_error: false,
|
||||||
last_info: (vec![None], Duration::ZERO),
|
last_info: (vec![None], Duration::ZERO),
|
||||||
dark_mode: true,
|
dark_mode: true,
|
||||||
text_boxes_focused: false,
|
|
||||||
opened: Opened::default(),
|
opened: Opened::default(),
|
||||||
settings: AppSettings::default(),
|
settings: AppSettings::default(),
|
||||||
}
|
}
|
||||||
@ -460,7 +456,6 @@ impl MathApp {
|
|||||||
|
|
||||||
let functions_len = self.functions.len();
|
let functions_len = self.functions.len();
|
||||||
let mut remove_i: Option<usize> = None;
|
let mut remove_i: Option<usize> = None;
|
||||||
self.text_boxes_focused = false;
|
|
||||||
self.exists_error = false;
|
self.exists_error = false;
|
||||||
for (i, function) in self.functions.iter_mut().enumerate() {
|
for (i, function) in self.functions.iter_mut().enumerate() {
|
||||||
// Entry for a function
|
// Entry for a function
|
||||||
@ -498,11 +493,7 @@ impl MathApp {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Contains the function string in a text box that the user can edit
|
// Contains the function string in a text box that the user can edit
|
||||||
let (focused, changed, error) = function.auto_complete(ui, i as i32);
|
let (changed, error) = function.auto_complete(ui, i as i32);
|
||||||
|
|
||||||
if focused {
|
|
||||||
self.text_boxes_focused = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(error_string) = error {
|
if let Some(error_string) = error {
|
||||||
self.exists_error = true;
|
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.
|
// 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
|
// 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
|
// presses the h key in a text box as well
|
||||||
if !self.text_boxes_focused {
|
if !ctx.wants_keyboard_input() {
|
||||||
self.opened
|
self.opened
|
||||||
.side_panel
|
.side_panel
|
||||||
.bitxor_assign(ctx.input().key_down(Key::H));
|
.bitxor_assign(ctx.input_mut().consume_key(egui::Modifiers::NONE, Key::H));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize fonts
|
// Initialize fonts
|
||||||
@ -678,8 +669,6 @@ impl epi::App for MathApp {
|
|||||||
// If side panel is enabled, show it.
|
// If side panel is enabled, show it.
|
||||||
if self.opened.side_panel {
|
if self.opened.side_panel {
|
||||||
self.side_panel(ctx);
|
self.side_panel(ctx);
|
||||||
} else {
|
|
||||||
self.text_boxes_focused = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Referenced in plotting code, but needs to be here so it can be later
|
// Referenced in plotting code, but needs to be here so it can be later
|
||||||
|
|||||||
@ -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 new_string = string.clone();
|
||||||
|
|
||||||
let mut movement: Movement = Movement::None;
|
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));
|
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", func_i));
|
||||||
|
|
||||||
if self.hint.is_none() {
|
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();
|
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
|
// 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 re = func_edit.id(te_id).ui(ui);
|
||||||
|
|
||||||
let func_edit_focus = re.has_focus();
|
|
||||||
|
|
||||||
if ui.input().key_pressed(Key::ArrowDown) {
|
if ui.input().key_pressed(Key::ArrowDown) {
|
||||||
movement = Movement::Down;
|
movement = Movement::Down;
|
||||||
} else if ui.input().key_pressed(Key::ArrowUp) {
|
} else if ui.input().key_pressed(Key::ArrowUp) {
|
||||||
movement = Movement::Up;
|
movement = Movement::Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if movement != Movement::None {
|
|
||||||
// println!("{:?}", movement);
|
|
||||||
// }
|
|
||||||
|
|
||||||
self.interact_back(&mut new_string, &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)
|
// 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);
|
TextEdit::store_state(ui.ctx(), te_id, state);
|
||||||
}
|
}
|
||||||
(new_string, func_edit_focus)
|
new_string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user