create widgets_ontop
This commit is contained in:
parent
0336a34e40
commit
9afa4d86bc
@ -4,7 +4,7 @@ use crate::math_app::AppSettings;
|
|||||||
use crate::misc::*;
|
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::{widgets_ontop, AutoComplete, Movement};
|
||||||
use eframe::{egui, emath, epaint};
|
use eframe::{egui, emath, epaint};
|
||||||
use egui::{
|
use egui::{
|
||||||
plot::{BarChart, PlotUi, Value},
|
plot::{BarChart, PlotUi, Value},
|
||||||
@ -207,13 +207,6 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the y offset multiplier of the `buttons_area` area
|
|
||||||
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
|
||||||
|
|
||||||
let buttons_area = egui::Area::new(format!("buttons_area_{}", i))
|
|
||||||
.fixed_pos(re.rect.min.offset_y(row_height * BUTTONS_Y_OFFSET))
|
|
||||||
.order(egui::Order::Foreground); // put it in the foreground so it's above the text edit box
|
|
||||||
|
|
||||||
/// Function that creates button that's used with the `button_area`
|
/// Function that creates button that's used with the `button_area`
|
||||||
fn button_area_button(text: impl Into<egui::WidgetText>) -> Button {
|
fn button_area_button(text: impl Into<egui::WidgetText>) -> Button {
|
||||||
Button::new(text.into()).frame(false)
|
Button::new(text.into()).frame(false)
|
||||||
@ -222,44 +215,53 @@ impl FunctionEntry {
|
|||||||
// returned at the end of this function to indicate whether or not this function should be removed from where it's stored
|
// returned at the end of this function to indicate whether or not this function should be removed from where it's stored
|
||||||
let mut should_remove: bool = false;
|
let mut should_remove: bool = false;
|
||||||
|
|
||||||
buttons_area.show(ui.ctx(), |ui| {
|
/// the y offset multiplier of the `buttons_area` area
|
||||||
ui.horizontal(|ui| {
|
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
||||||
// There's more than 1 function! Functions can now be deleted
|
|
||||||
should_remove = ui
|
|
||||||
.add_enabled(can_remove, button_area_button("✖"))
|
|
||||||
.on_hover_text("Delete Function")
|
|
||||||
.clicked();
|
|
||||||
|
|
||||||
// Toggle integral being enabled or not
|
widgets_ontop(
|
||||||
self.integral.bitxor_assign(
|
ui,
|
||||||
ui.add(button_area_button("∫"))
|
format!("buttons_area_{}", i),
|
||||||
.on_hover_text(match self.integral {
|
&re,
|
||||||
true => "Don't integrate",
|
row_height * BUTTONS_Y_OFFSET,
|
||||||
false => "Integrate",
|
|ui| {
|
||||||
})
|
ui.horizontal(|ui| {
|
||||||
.clicked(),
|
// There's more than 1 function! Functions can now be deleted
|
||||||
);
|
should_remove = ui
|
||||||
|
.add_enabled(can_remove, button_area_button("✖"))
|
||||||
|
.on_hover_text("Delete Function")
|
||||||
|
.clicked();
|
||||||
|
|
||||||
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
// Toggle integral being enabled or not
|
||||||
self.derivative.bitxor_assign(
|
self.integral.bitxor_assign(
|
||||||
ui.add(button_area_button("d/dx"))
|
ui.add(button_area_button("∫"))
|
||||||
.on_hover_text(match self.derivative {
|
.on_hover_text(match self.integral {
|
||||||
true => "Don't Differentiate",
|
true => "Don't integrate",
|
||||||
false => "Differentiate",
|
false => "Integrate",
|
||||||
})
|
})
|
||||||
.clicked(),
|
.clicked(),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.settings_opened.bitxor_assign(
|
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
||||||
ui.add(button_area_button("⚙"))
|
self.derivative.bitxor_assign(
|
||||||
.on_hover_text(match self.settings_opened {
|
ui.add(button_area_button("d/dx"))
|
||||||
true => "Close Settings",
|
.on_hover_text(match self.derivative {
|
||||||
false => "Open Settings",
|
true => "Don't Differentiate",
|
||||||
})
|
false => "Differentiate",
|
||||||
.clicked(),
|
})
|
||||||
);
|
.clicked(),
|
||||||
});
|
);
|
||||||
});
|
|
||||||
|
self.settings_opened.bitxor_assign(
|
||||||
|
ui.add(button_area_button("⚙"))
|
||||||
|
.on_hover_text(match self.settings_opened {
|
||||||
|
true => "Close Settings",
|
||||||
|
false => "Open Settings",
|
||||||
|
})
|
||||||
|
.clicked(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
should_remove
|
should_remove
|
||||||
}
|
}
|
||||||
|
|||||||
@ -490,7 +490,7 @@ impl MathApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl epi::App for MathApp {
|
impl epi::App for MathApp {
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// Called each time the UI needs repainting.
|
||||||
fn update(&mut self, ctx: &Context, _frame: &mut epi::Frame) {
|
fn update(&mut self, ctx: &Context, _frame: &mut epi::Frame) {
|
||||||
// start timer
|
// start timer
|
||||||
let start = instant::Instant::now();
|
let start = instant::Instant::now();
|
||||||
@ -501,8 +501,9 @@ impl epi::App for MathApp {
|
|||||||
false => Visuals::light(),
|
false => Visuals::light(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// if keyboard input isn't being grabed, check for key combos
|
// If keyboard input isn't being grabbed, check for key combos
|
||||||
if !ctx.wants_keyboard_input() {
|
if !ctx.wants_keyboard_input() {
|
||||||
|
// If `H` key is pressed, toggle Side Panel
|
||||||
self.opened
|
self.opened
|
||||||
.side_panel
|
.side_panel
|
||||||
.bitxor_assign(ctx.input_mut().consume_key(egui::Modifiers::NONE, Key::H));
|
.bitxor_assign(ctx.input_mut().consume_key(egui::Modifiers::NONE, Key::H));
|
||||||
|
|||||||
@ -100,6 +100,17 @@ pub fn move_cursor_to_end(ctx: &egui::Context, te_id: egui::Id) {
|
|||||||
TextEdit::store_state(ctx, te_id, state);
|
TextEdit::store_state(ctx, te_id, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn widgets_ontop<R>(
|
||||||
|
ui: &egui::Ui, id: String, re: &egui::Response, y_offset: f32,
|
||||||
|
add_contents: impl FnOnce(&mut egui::Ui) -> R,
|
||||||
|
) -> R {
|
||||||
|
let area = egui::Area::new(id)
|
||||||
|
.fixed_pos(re.rect.min.offset_y(y_offset))
|
||||||
|
.order(egui::Order::Foreground);
|
||||||
|
|
||||||
|
area.show(ui.ctx(), |ui| add_contents(ui)).inner
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod autocomplete_tests {
|
mod autocomplete_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user