update egui fork

This commit is contained in:
Simon Gardling 2022-06-19 00:16:49 -04:00
parent bb4640478a
commit c79be512ca
5 changed files with 84 additions and 58 deletions

12
Cargo.lock generated
View File

@ -685,7 +685,7 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
[[package]] [[package]]
name = "eframe" name = "eframe"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -705,7 +705,7 @@ dependencies = [
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"ahash", "ahash",
"epaint", "epaint",
@ -717,7 +717,7 @@ dependencies = [
[[package]] [[package]]
name = "egui-winit" name = "egui-winit"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"arboard", "arboard",
"egui", "egui",
@ -731,7 +731,7 @@ dependencies = [
[[package]] [[package]]
name = "egui_glow" name = "egui_glow"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -751,7 +751,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde", "serde",
@ -760,7 +760,7 @@ dependencies = [
[[package]] [[package]]
name = "epaint" name = "epaint"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#8defc5d340600618101a8f9a6a935cd739071b82" source = "git+https://github.com/Titaniumtown/egui.git#467c256edc701cd379d1a9915450d9e98ddee656"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash", "ahash",

View File

@ -149,7 +149,7 @@ impl FunctionEntry {
pub const fn is_some(&self) -> bool { !self.function.is_none() } pub const fn is_some(&self) -> bool { !self.function.is_none() }
pub fn settings_window(&mut self, ctx: &Context) { pub fn settings_window(&mut self, ctx: &mut Context) {
let mut invalidate_nth = false; let mut invalidate_nth = false;
egui::Window::new(format!("Settings: {}", self.raw_func_str)) egui::Window::new(format!("Settings: {}", self.raw_func_str))
.open(&mut self.settings_opened) .open(&mut self.settings_opened)

View File

@ -93,12 +93,13 @@ impl FunctionManager {
let mut movement: Movement = Movement::default(); let mut movement: Movement = Movement::default();
let size_multiplier = vec2(1.0, {
let had_focus = ui.ctx.memory().has_focus(*te_id);
(ui.ctx.animate_bool(*te_id, had_focus) * 1.5) + 1.0
});
let re = ui.add_sized( let re = ui.add_sized(
target_size target_size * size_multiplier,
* vec2(1.0, {
let had_focus = ui.ctx().memory().has_focus(*te_id);
(ui.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
.lock_focus(true) .lock_focus(true)
@ -116,7 +117,8 @@ impl FunctionManager {
new_string.retain(|c| crate::misc::is_valid_char(&c)); new_string.retain(|c| crate::misc::is_valid_char(&c));
// If not fully open, return here as buttons cannot yet be displayed, therefore the user is inable to mark it for deletion // If not fully open, return here as buttons cannot yet be displayed, therefore the user is inable to mark it for deletion
if ui.ctx().animate_bool(*te_id, re.has_focus()) == 1.0 { let animate_bool = ui.ctx.animate_bool(*te_id, re.has_focus());
if animate_bool == 1.0 {
function.autocomplete.update_string(&new_string); function.autocomplete.update_string(&new_string);
if function.autocomplete.hint.is_some() { if function.autocomplete.hint.is_some() {
@ -160,21 +162,21 @@ impl FunctionManager {
function.autocomplete.apply_hint(hints[function.autocomplete.i]); function.autocomplete.apply_hint(hints[function.autocomplete.i]);
// Don't need this here as it simply won't be display next frame // Don't need this here as it simply won't be display next frame
// ui.memory().close_popup(); // ui.memory_mut().close_popup();
movement = Movement::Complete; movement = Movement::Complete;
} else { } else {
ui.memory().open_popup(POPUP_ID); ui.memory_mut().open_popup(POPUP_ID);
} }
} }
// Push cursor to end if needed // Push cursor to end if needed
if movement == Movement::Complete { if movement == Movement::Complete {
let mut state = let mut state =
unsafe { TextEdit::load_state(ui.ctx(), *te_id).unwrap_unchecked() }; unsafe { TextEdit::load_state(ui.ctx, *te_id).unwrap_unchecked() };
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len()); let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
state.set_ccursor_range(Some(egui::text::CCursorRange::one(ccursor))); state.set_ccursor_range(Some(egui::text::CCursorRange::one(ccursor)));
TextEdit::store_state(ui.ctx(), *te_id, state); TextEdit::store_state(ui.ctx, *te_id, state);
} }
} }
@ -187,7 +189,7 @@ impl FunctionManager {
// 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
.add_enabled(can_remove, button_area_button("")) .add_enabled(can_remove, button_area_button(""))
.on_hover_text("Delete Function") .on_hover_text(ui.ctx, "Delete Function")
.clicked() .clicked()
{ {
remove_i = Some(i); remove_i = Some(i);
@ -197,30 +199,39 @@ impl FunctionManager {
// Toggle integral being enabled or not // Toggle integral being enabled or not
function.integral.bitxor_assign( function.integral.bitxor_assign(
ui.add(button_area_button("")) ui.add(button_area_button(""))
.on_hover_text(match function.integral { .on_hover_text(
ui.ctx,
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(button_area_button("d/dx")) ui.add(button_area_button("d/dx"))
.on_hover_text(match function.derivative { .on_hover_text(
ui.ctx,
match function.derivative {
true => "Don't Differentiate", true => "Don't Differentiate",
false => "Differentiate", false => "Differentiate",
}) },
)
.clicked(), .clicked(),
); );
// Toggle showing the settings window // Toggle showing the settings window
function.settings_opened.bitxor_assign( function.settings_opened.bitxor_assign(
ui.add(button_area_button("")) ui.add(button_area_button(""))
.on_hover_text(match function.settings_opened { .on_hover_text(
ui.ctx,
match function.settings_opened {
true => "Close Settings", true => "Close Settings",
false => "Open Settings", false => "Open Settings",
}) },
)
.clicked(), .clicked(),
); );
}); });
@ -228,7 +239,7 @@ impl FunctionManager {
}); });
} }
function.settings_window(ui.ctx()); function.settings_window(ui.ctx);
} }
// Remove function if the user requests it // Remove function if the user requests it

View File

@ -128,7 +128,7 @@ const FUNC_NAME: &str = "YTBN-FUNCTIONS";
impl MathApp { impl MathApp {
#[allow(dead_code)] // This is used lol #[allow(dead_code)] // This is used lol
/// Create new instance of [`MathApp`] and return it /// Create new instance of [`MathApp`] and return it
pub fn new(cc: &eframe::CreationContext<'_>) -> Self { pub fn new(cc: &mut eframe::CreationContext<'_, '_>) -> Self {
#[cfg(threading)] #[cfg(threading)]
tracing::info!("Threading: Enabled"); tracing::info!("Threading: Enabled");
@ -274,7 +274,7 @@ impl MathApp {
} }
/// Creates SidePanel which contains configuration options /// Creates SidePanel which contains configuration options
fn side_panel(&mut self, ctx: &Context) { fn side_panel(&mut self, ctx: &mut Context) {
// Side Panel which contains vital options to the operation of the application // Side Panel which contains vital options to the operation of the application
// (such as adding functions and other options) // (such as adding functions and other options)
SidePanel::left("side_panel") SidePanel::left("side_panel")
@ -369,19 +369,25 @@ impl MathApp {
ui.horizontal(|ui| { ui.horizontal(|ui| {
self.settings.do_extrema.bitxor_assign( self.settings.do_extrema.bitxor_assign(
ui.add(Button::new("Extrema")) ui.add(Button::new("Extrema"))
.on_hover_text(match self.settings.do_extrema { .on_hover_text(
ui.ctx,
match self.settings.do_extrema {
true => "Disable Displaying Extrema", true => "Disable Displaying Extrema",
false => "Display Extrema", false => "Display Extrema",
}) },
)
.clicked(), .clicked(),
); );
self.settings.do_roots.bitxor_assign( self.settings.do_roots.bitxor_assign(
ui.add(Button::new("Roots")) ui.add(Button::new("Roots"))
.on_hover_text(match self.settings.do_roots { .on_hover_text(
ui.ctx,
match self.settings.do_roots {
true => "Disable Displaying Roots", true => "Disable Displaying Roots",
false => "Display Roots", false => "Display Roots",
}) },
)
.clicked(), .clicked(),
); );
}); });
@ -422,7 +428,7 @@ impl MathApp {
impl App for MathApp { impl App for MathApp {
/// Called each time the UI needs repainting. /// Called each time the UI needs repainting.
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &mut Context, _frame: &mut eframe::Frame) {
// start timer // start timer
let start = if self.opened.info { let start = if self.opened.info {
Some(instant::Instant::now()) Some(instant::Instant::now())
@ -447,10 +453,13 @@ impl App for MathApp {
// Button in top bar to toggle showing the side panel // Button in top bar to toggle showing the side panel
self.opened.side_panel.bitxor_assign( self.opened.side_panel.bitxor_assign(
ui.add(Button::new("Panel")) ui.add(Button::new("Panel"))
.on_hover_text(match self.opened.side_panel { .on_hover_text(
ui.ctx,
match self.opened.side_panel {
true => "Hide Side Panel", true => "Hide Side Panel",
false => "Show Side Panel", false => "Show Side Panel",
}) },
)
.clicked(), .clicked(),
); );
@ -460,7 +469,7 @@ impl App for MathApp {
COLORS.len() > self.functions.len(), COLORS.len() > self.functions.len(),
Button::new("Add Function"), Button::new("Add Function"),
) )
.on_hover_text("Create and graph new function") .on_hover_text(ui.ctx, "Create and graph new function")
.clicked() .clicked()
{ {
self.functions.push_empty(); self.functions.push_empty();
@ -469,20 +478,26 @@ impl App for MathApp {
// Toggles opening the Help window // Toggles opening the Help window
self.opened.help.bitxor_assign( self.opened.help.bitxor_assign(
ui.add(Button::new("Help")) ui.add(Button::new("Help"))
.on_hover_text(match self.opened.help { .on_hover_text(
ui.ctx,
match self.opened.help {
true => "Close Help Window", true => "Close Help Window",
false => "Open Help Window", false => "Open Help Window",
}) },
)
.clicked(), .clicked(),
); );
// Toggles opening the Info window // Toggles opening the Info window
self.opened.info.bitxor_assign( self.opened.info.bitxor_assign(
ui.add(Button::new("Info")) ui.add(Button::new("Info"))
.on_hover_text(match self.opened.info { .on_hover_text(
ui.ctx,
match self.opened.info {
true => "Close Info Window", true => "Close Info Window",
false => "Open Info Window", false => "Open Info Window",
}) },
)
.clicked(), .clicked(),
); );

View File

@ -3,12 +3,12 @@ use std::hash::Hash;
/// Creates an area ontop of a widget with an y offset /// Creates an area ontop of a widget with an y offset
pub fn widgets_ontop<R>( pub fn widgets_ontop<R>(
ui: &egui::Ui, id: impl Hash, re: &egui::Response, y_offset: f32, ui: &mut egui::Ui, id: impl Hash, re: &egui::Response, y_offset: f32,
add_contents: impl FnOnce(&mut egui::Ui) -> R, add_contents: impl FnOnce(&mut egui::Ui) -> R,
) -> InnerResponse<R> { ) -> InnerResponse<R> {
let area = egui::Area::new(id) let area = egui::Area::new(id)
.fixed_pos(re.rect.min.offset_y(y_offset)) .fixed_pos(re.rect().min.offset_y(y_offset))
.order(egui::Order::Foreground); .order(egui::Order::Foreground);
area.show(ui.ctx(), |ui| add_contents(ui)) area.show(ui.ctx, |ui| add_contents(ui))
} }