cleanup some FunctionManager logic
This commit is contained in:
parent
a60f1cb83d
commit
4b29ce9333
@ -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,55 +169,50 @@ 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,
|
ui.horizontal(|ui| {
|
||||||
format!("buttons_area_{}", i),
|
// There's more than 1 function! Functions can now be deleted
|
||||||
&re,
|
if ui
|
||||||
crate::data::FONT_SIZE * BUTTONS_Y_OFFSET,
|
.add_enabled(can_remove, button_area_button("✖"))
|
||||||
|ui| {
|
.on_hover_text("Delete Function")
|
||||||
ui.horizontal(|ui| {
|
.clicked()
|
||||||
// There's more than 1 function! Functions can now be deleted
|
{
|
||||||
if ui
|
remove_i = Some(i);
|
||||||
.add_enabled(can_remove, button_area_button("✖"))
|
}
|
||||||
.on_hover_text("Delete Function")
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
remove_i = Some(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
let func_some = function.is_some();
|
let func_some = function.is_some();
|
||||||
// Toggle integral being enabled or not
|
// Toggle integral being enabled or not
|
||||||
function.integral.bitxor_assign(
|
function.integral.bitxor_assign(
|
||||||
ui.add_enabled(func_some, button_area_button("∫"))
|
ui.add_enabled(func_some, button_area_button("∫"))
|
||||||
.on_hover_text(match function.integral {
|
.on_hover_text(match function.integral {
|
||||||
true => "Don't integrate",
|
true => "Don't integrate",
|
||||||
false => "Integrate",
|
false => "Integrate",
|
||||||
})
|
})
|
||||||
.clicked(),
|
.clicked(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
||||||
function.derivative.bitxor_assign(
|
function.derivative.bitxor_assign(
|
||||||
ui.add_enabled(func_some, button_area_button("d/dx"))
|
ui.add_enabled(func_some, button_area_button("d/dx"))
|
||||||
.on_hover_text(match function.derivative {
|
.on_hover_text(match function.derivative {
|
||||||
true => "Don't Differentiate",
|
true => "Don't Differentiate",
|
||||||
false => "Differentiate",
|
false => "Differentiate",
|
||||||
})
|
})
|
||||||
.clicked(),
|
.clicked(),
|
||||||
);
|
);
|
||||||
|
|
||||||
function.settings_opened.bitxor_assign(
|
function.settings_opened.bitxor_assign(
|
||||||
ui.add_enabled(func_some, button_area_button("⚙"))
|
ui.add_enabled(func_some, button_area_button("⚙"))
|
||||||
.on_hover_text(match function.settings_opened {
|
.on_hover_text(match function.settings_opened {
|
||||||
true => "Close Settings",
|
true => "Close Settings",
|
||||||
false => "Open Settings",
|
false => "Open Settings",
|
||||||
})
|
})
|
||||||
.clicked(),
|
.clicked(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function.settings_window(ui.ctx());
|
function.settings_window(ui.ctx());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user