cleanup some FunctionManager logic

This commit is contained in:
Simon Gardling 2022-05-24 13:13:46 -04:00
parent a60f1cb83d
commit 4b29ce9333

View File

@ -74,7 +74,6 @@ const fn button_area_button(text: impl Into<WidgetText>) -> Button {
impl FunctionManager { impl FunctionManager {
pub fn display_entries(&mut self, ui: &mut egui::Ui) { pub fn display_entries(&mut self, ui: &mut egui::Ui) {
// ui.label("Functions:");
let can_remove = self.functions.len() > 1; let can_remove = self.functions.len() > 1;
let available_width = ui.available_width(); let available_width = ui.available_width();
@ -89,9 +88,8 @@ impl FunctionManager {
let re = ui.add_sized( let re = ui.add_sized(
target_size target_size
* vec2(1.0, { * vec2(1.0, {
let ctx = ui.ctx(); let had_focus = ui.ctx().memory().has_focus(*te_id);
let had_focus = ctx.memory().has_focus(*te_id); (ui.ctx().animate_bool(*te_id, had_focus) * 1.5) + 1.0
(ctx.animate_bool(*te_id, had_focus) * 1.5) + 1.0
}), }),
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
@ -99,10 +97,9 @@ impl FunctionManager {
.id(*te_id) // Set widget's id to `te_id` .id(*te_id) // Set widget's id to `te_id`
.hint_text({ .hint_text({
// If there's a single hint, go ahead and apply the hint here, if not, set the hint to an empty string // If there's a single hint, go ahead and apply the hint here, if not, set the hint to an empty string
if let Some(single_hint) = function.autocomplete.hint.single() { match function.autocomplete.hint.single() {
*single_hint Some(single_hint) => *single_hint,
} else { None => "",
""
} }
}), }),
); );
@ -172,13 +169,9 @@ impl FunctionManager {
/// The y offset multiplier of the `buttons_area` area /// The y offset multiplier of the `buttons_area` area
const BUTTONS_Y_OFFSET: f32 = 1.32; const BUTTONS_Y_OFFSET: f32 = 1.32;
const Y_OFFSET: f32 = crate::data::FONT_SIZE * BUTTONS_Y_OFFSET;
widgets_ontop( widgets_ontop(ui, format!("buttons_area_{}", i), &re, Y_OFFSET, |ui| {
ui,
format!("buttons_area_{}", i),
&re,
crate::data::FONT_SIZE * BUTTONS_Y_OFFSET,
|ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
// There's more than 1 function! Functions can now be deleted // There's more than 1 function! Functions can now be deleted
if ui if ui
@ -219,8 +212,7 @@ impl FunctionManager {
.clicked(), .clicked(),
); );
}); });
}, });
);
} }
function.settings_window(ui.ctx()); function.settings_window(ui.ctx());