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

View File

@ -149,7 +149,7 @@ impl FunctionEntry {
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;
egui::Window::new(format!("Settings: {}", self.raw_func_str))
.open(&mut self.settings_opened)

View File

@ -93,12 +93,13 @@ impl FunctionManager {
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(
target_size
* 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
}),
target_size * size_multiplier,
egui::TextEdit::singleline(&mut new_string)
.hint_forward(true) // Make the hint appear after the last text in the textbox
.lock_focus(true)
@ -116,7 +117,8 @@ impl FunctionManager {
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 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);
if function.autocomplete.hint.is_some() {
@ -160,21 +162,21 @@ impl FunctionManager {
function.autocomplete.apply_hint(hints[function.autocomplete.i]);
// 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;
} else {
ui.memory().open_popup(POPUP_ID);
ui.memory_mut().open_popup(POPUP_ID);
}
}
// Push cursor to end if needed
if movement == Movement::Complete {
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());
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
if ui
.add_enabled(can_remove, button_area_button(""))
.on_hover_text("Delete Function")
.on_hover_text(ui.ctx, "Delete Function")
.clicked()
{
remove_i = Some(i);
@ -197,30 +199,39 @@ impl FunctionManager {
// Toggle integral being enabled or not
function.integral.bitxor_assign(
ui.add(button_area_button(""))
.on_hover_text(match function.integral {
true => "Don't integrate",
false => "Integrate",
})
.on_hover_text(
ui.ctx,
match function.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)
function.derivative.bitxor_assign(
ui.add(button_area_button("d/dx"))
.on_hover_text(match function.derivative {
true => "Don't Differentiate",
false => "Differentiate",
})
.on_hover_text(
ui.ctx,
match function.derivative {
true => "Don't Differentiate",
false => "Differentiate",
},
)
.clicked(),
);
// Toggle showing the settings window
function.settings_opened.bitxor_assign(
ui.add(button_area_button(""))
.on_hover_text(match function.settings_opened {
true => "Close Settings",
false => "Open Settings",
})
.on_hover_text(
ui.ctx,
match function.settings_opened {
true => "Close Settings",
false => "Open Settings",
},
)
.clicked(),
);
});
@ -228,7 +239,7 @@ impl FunctionManager {
});
}
function.settings_window(ui.ctx());
function.settings_window(ui.ctx);
}
// Remove function if the user requests it

View File

@ -128,7 +128,7 @@ const FUNC_NAME: &str = "YTBN-FUNCTIONS";
impl MathApp {
#[allow(dead_code)] // This is used lol
/// 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)]
tracing::info!("Threading: Enabled");
@ -274,7 +274,7 @@ impl MathApp {
}
/// 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
// (such as adding functions and other options)
SidePanel::left("side_panel")
@ -369,19 +369,25 @@ impl MathApp {
ui.horizontal(|ui| {
self.settings.do_extrema.bitxor_assign(
ui.add(Button::new("Extrema"))
.on_hover_text(match self.settings.do_extrema {
true => "Disable Displaying Extrema",
false => "Display Extrema",
})
.on_hover_text(
ui.ctx,
match self.settings.do_extrema {
true => "Disable Displaying Extrema",
false => "Display Extrema",
},
)
.clicked(),
);
self.settings.do_roots.bitxor_assign(
ui.add(Button::new("Roots"))
.on_hover_text(match self.settings.do_roots {
true => "Disable Displaying Roots",
false => "Display Roots",
})
.on_hover_text(
ui.ctx,
match self.settings.do_roots {
true => "Disable Displaying Roots",
false => "Display Roots",
},
)
.clicked(),
);
});
@ -422,7 +428,7 @@ impl MathApp {
impl App for MathApp {
/// 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
let start = if self.opened.info {
Some(instant::Instant::now())
@ -447,10 +453,13 @@ impl App for MathApp {
// Button in top bar to toggle showing the side panel
self.opened.side_panel.bitxor_assign(
ui.add(Button::new("Panel"))
.on_hover_text(match self.opened.side_panel {
true => "Hide Side Panel",
false => "Show Side Panel",
})
.on_hover_text(
ui.ctx,
match self.opened.side_panel {
true => "Hide Side Panel",
false => "Show Side Panel",
},
)
.clicked(),
);
@ -460,7 +469,7 @@ impl App for MathApp {
COLORS.len() > self.functions.len(),
Button::new("Add Function"),
)
.on_hover_text("Create and graph new function")
.on_hover_text(ui.ctx, "Create and graph new function")
.clicked()
{
self.functions.push_empty();
@ -469,20 +478,26 @@ impl App for MathApp {
// Toggles opening the Help window
self.opened.help.bitxor_assign(
ui.add(Button::new("Help"))
.on_hover_text(match self.opened.help {
true => "Close Help Window",
false => "Open Help Window",
})
.on_hover_text(
ui.ctx,
match self.opened.help {
true => "Close Help Window",
false => "Open Help Window",
},
)
.clicked(),
);
// Toggles opening the Info window
self.opened.info.bitxor_assign(
ui.add(Button::new("Info"))
.on_hover_text(match self.opened.info {
true => "Close Info Window",
false => "Open Info Window",
})
.on_hover_text(
ui.ctx,
match self.opened.info {
true => "Close Info Window",
false => "Open Info Window",
},
)
.clicked(),
);

View File

@ -3,12 +3,12 @@ use std::hash::Hash;
/// Creates an area ontop of a widget with an y offset
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,
) -> InnerResponse<R> {
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);
area.show(ui.ctx(), |ui| add_contents(ui))
area.show(ui.ctx, |ui| add_contents(ui))
}