dynamically show function settings

This commit is contained in:
Simon Gardling 2022-04-14 13:39:02 -04:00
parent 0c3939d4a7
commit 21c5fb762d

View File

@ -76,6 +76,8 @@ pub struct FunctionEntry {
curr_nth: usize, curr_nth: usize,
pub settings_opened: bool, pub settings_opened: bool,
auto_complete_focused: bool,
} }
impl Default for FunctionEntry { impl Default for FunctionEntry {
@ -99,6 +101,7 @@ impl Default for FunctionEntry {
test_result: None, test_result: None,
curr_nth: 3, curr_nth: 3,
settings_opened: false, settings_opened: false,
auto_complete_focused: false,
} }
} }
} }
@ -114,13 +117,22 @@ impl FunctionEntry {
let mut new_string = self.autocomplete.string.clone(); let mut new_string = self.autocomplete.string.clone();
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", i));
let row_height = ui let row_height = ui
.fonts() .fonts()
.row_height(&egui::FontSelection::default().resolve(ui.style())); .row_height(&egui::FontSelection::default().resolve(ui.style()));
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", i)); let max_size = vec2(
ui.available_width(),
if self.auto_complete_focused {
row_height * 2.5
} else {
row_height
},
);
let re = ui.add_sized( let re = ui.add_sized(
vec2(ui.available_width(), row_height * 2.5), max_size,
egui::TextEdit::singleline(&mut new_string) egui::TextEdit::singleline(&mut new_string)
.hint_forward(true) // Make the hint appear after the last text in the textbox .hint_forward(true) // Make the hint appear after the last text in the textbox
.lock_focus(true) .lock_focus(true)
@ -133,10 +145,15 @@ impl FunctionEntry {
} }
}), }),
); );
self.auto_complete_focused = re.has_focus();
if !self.auto_complete_focused {
return;
}
self.autocomplete.update_string(&new_string); self.autocomplete.update_string(&new_string);
if !self.autocomplete.hint.is_none() && re.has_focus() { if !self.autocomplete.hint.is_none() {
if !self.autocomplete.hint.is_single() { if !self.autocomplete.hint.is_single() {
if ui.input().key_pressed(Key::ArrowDown) { if ui.input().key_pressed(Key::ArrowDown) {
movement = Movement::Down; movement = Movement::Down;