refactor function entry

This commit is contained in:
Simon Gardling 2022-04-18 11:05:58 -04:00
parent 64ace24dc7
commit d2a873339d

View File

@ -219,17 +219,21 @@ impl FunctionEntry {
let mut should_remove: bool = false; let mut should_remove: bool = false;
fn button_area_button(text: impl Into<egui::WidgetText>) -> Button {
Button::new(text.into()).frame(false)
}
buttons_area.show(ui.ctx(), |ui| { buttons_area.show(ui.ctx(), |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
should_remove = ui should_remove = ui
.add_enabled(can_remove, Button::new("").frame(false)) .add_enabled(can_remove, button_area_button(""))
.on_hover_text("Delete Function") .on_hover_text("Delete Function")
.clicked(); .clicked();
// Toggle integral being enabled or not // Toggle integral being enabled or not
self.integral.bitxor_assign( self.integral.bitxor_assign(
ui.add(Button::new("").frame(false)) ui.add(button_area_button(""))
.on_hover_text(match self.integral { .on_hover_text(match self.integral {
true => "Don't integrate", true => "Don't integrate",
false => "Integrate", false => "Integrate",
@ -239,7 +243,7 @@ impl FunctionEntry {
// 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)
self.derivative.bitxor_assign( self.derivative.bitxor_assign(
ui.add(Button::new("d/dx").frame(false)) ui.add(button_area_button("d/dx"))
.on_hover_text(match self.derivative { .on_hover_text(match self.derivative {
true => "Don't Differentiate", true => "Don't Differentiate",
false => "Differentiate", false => "Differentiate",
@ -248,7 +252,7 @@ impl FunctionEntry {
); );
self.settings_opened.bitxor_assign( self.settings_opened.bitxor_assign(
ui.add(Button::new("").frame(false)) ui.add(button_area_button(""))
.on_hover_text(match self.settings_opened { .on_hover_text(match self.settings_opened {
true => "Close Settings", true => "Close Settings",
false => "Open Settings", false => "Open Settings",
@ -257,7 +261,7 @@ impl FunctionEntry {
); );
}); });
}); });
return should_remove; should_remove
} }
pub fn settings_window(&mut self, ctx: &Context) { pub fn settings_window(&mut self, ctx: &Context) {