WIP function display improvements
This commit is contained in:
parent
15d9184788
commit
5f9b3823ff
105
src/function.rs
105
src/function.rs
@ -5,14 +5,15 @@ use crate::misc::*;
|
|||||||
use crate::parsing::{process_func_str, BackingFunction};
|
use crate::parsing::{process_func_str, BackingFunction};
|
||||||
use crate::suggestions::Hint;
|
use crate::suggestions::Hint;
|
||||||
use crate::widgets::{AutoComplete, Movement};
|
use crate::widgets::{AutoComplete, Movement};
|
||||||
use eframe::{egui, epaint};
|
use eframe::{egui, emath, epaint};
|
||||||
use egui::{
|
use egui::{
|
||||||
plot::{BarChart, PlotUi, Value},
|
plot::{BarChart, PlotUi, Value},
|
||||||
text::CCursor,
|
text::CCursor,
|
||||||
text_edit::CursorRange,
|
text_edit::CursorRange,
|
||||||
widgets::plot::Bar,
|
widgets::plot::Bar,
|
||||||
Button, Checkbox, Context, Key, Modifiers, TextEdit, Widget,
|
Button, Checkbox, Context, Key, Modifiers, TextEdit,
|
||||||
};
|
};
|
||||||
|
use emath::{pos2, vec2};
|
||||||
use epaint::{
|
use epaint::{
|
||||||
text::cursor::{Cursor, PCursor, RCursor},
|
text::cursor::{Cursor, PCursor, RCursor},
|
||||||
Color32,
|
Color32,
|
||||||
@ -106,53 +107,21 @@ impl FunctionEntry {
|
|||||||
pub fn function_entry(
|
pub fn function_entry(
|
||||||
&mut self, ui: &mut egui::Ui, remove_i: &mut Option<usize>, can_remove: bool, i: usize,
|
&mut self, ui: &mut egui::Ui, remove_i: &mut Option<usize>, can_remove: bool, i: usize,
|
||||||
) {
|
) {
|
||||||
ui.horizontal(|ui| {
|
let output_string = self.autocomplete.string.clone();
|
||||||
// There's more than 1 function! Functions can now be deleted
|
self.update_string(&output_string);
|
||||||
if ui
|
|
||||||
.add_enabled(can_remove, Button::new("X").frame(true))
|
|
||||||
.on_hover_text("Delete Function")
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
*remove_i = Some(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle integral being enabled or not
|
|
||||||
self.integral.bitxor_assign(
|
|
||||||
ui.add(Button::new("∫"))
|
|
||||||
.on_hover_text(match self.integral {
|
|
||||||
true => "Don't integrate",
|
|
||||||
false => "Integrate",
|
|
||||||
})
|
|
||||||
.clicked(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
|
||||||
self.derivative.bitxor_assign(
|
|
||||||
ui.add(Button::new("d/dx"))
|
|
||||||
.on_hover_text(match self.derivative {
|
|
||||||
true => "Don't Differentiate",
|
|
||||||
false => "Differentiate",
|
|
||||||
})
|
|
||||||
.clicked(),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.settings_opened.bitxor_assign(
|
|
||||||
ui.add(Button::new("⚙"))
|
|
||||||
.on_hover_text(match self.settings_opened {
|
|
||||||
true => "Close Settings",
|
|
||||||
false => "Open Settings",
|
|
||||||
})
|
|
||||||
.clicked(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Contains the function string in a text box that the user can edit
|
|
||||||
// self.autocomplete.update_string(&self.raw_func_str);
|
|
||||||
let mut movement: Movement = Movement::default();
|
let mut movement: Movement = Movement::default();
|
||||||
|
|
||||||
let mut new_string = self.autocomplete.string.clone();
|
let mut new_string = self.autocomplete.string.clone();
|
||||||
|
|
||||||
|
let row_height = ui
|
||||||
|
.fonts()
|
||||||
|
.row_height(&egui::FontSelection::default().resolve(ui.style()));
|
||||||
|
|
||||||
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", i));
|
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", i));
|
||||||
let re = egui::TextEdit::singleline(&mut new_string)
|
let re = ui.add_sized(
|
||||||
|
vec2(ui.available_width(), row_height * 2.5),
|
||||||
|
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)
|
||||||
.id(te_id)
|
.id(te_id)
|
||||||
@ -162,8 +131,8 @@ impl FunctionEntry {
|
|||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
.ui(ui);
|
);
|
||||||
|
|
||||||
self.autocomplete.update_string(&new_string);
|
self.autocomplete.update_string(&new_string);
|
||||||
|
|
||||||
@ -229,8 +198,50 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let output_string = self.autocomplete.string.clone();
|
let buttons_area = egui::Area::new(format!("buttons_area_{}", i))
|
||||||
self.update_string(&output_string);
|
.fixed_pos(pos2(re.rect.min.x, re.rect.min.y + (row_height * 1.3)))
|
||||||
|
.order(egui::Order::Foreground);
|
||||||
|
|
||||||
|
buttons_area.show(ui.ctx(), |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
// There's more than 1 function! Functions can now be deleted
|
||||||
|
if ui
|
||||||
|
.add_enabled(can_remove, Button::new("X").frame(false))
|
||||||
|
.on_hover_text("Delete Function")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
*remove_i = Some(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle integral being enabled or not
|
||||||
|
self.integral.bitxor_assign(
|
||||||
|
ui.add(Button::new("∫").frame(false))
|
||||||
|
.on_hover_text(match self.integral {
|
||||||
|
true => "Don't integrate",
|
||||||
|
false => "Integrate",
|
||||||
|
})
|
||||||
|
.clicked(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
||||||
|
self.derivative.bitxor_assign(
|
||||||
|
ui.add(Button::new("d/dx").frame(false))
|
||||||
|
.on_hover_text(match self.derivative {
|
||||||
|
true => "Don't Differentiate",
|
||||||
|
false => "Differentiate",
|
||||||
|
})
|
||||||
|
.clicked(),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.settings_opened.bitxor_assign(
|
||||||
|
ui.add(Button::new("⚙").frame(false))
|
||||||
|
.on_hover_text(match self.settings_opened {
|
||||||
|
true => "Close Settings",
|
||||||
|
false => "Open Settings",
|
||||||
|
})
|
||||||
|
.clicked(),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user