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::parsing::{process_func_str, BackingFunction};
|
||||
use crate::suggestions::Hint;
|
||||
use crate::widgets::{AutoComplete, Movement};
|
||||
use crate::widgets::{widgets_ontop, AutoComplete, Movement};
|
||||
use eframe::{egui, emath, epaint};
|
||||
use egui::{
|
||||
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`
|
||||
fn button_area_button(text: impl Into<egui::WidgetText>) -> Button {
|
||||
Button::new(text.into()).frame(false)
|
||||
@ -222,7 +215,15 @@ impl FunctionEntry {
|
||||
// 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;
|
||||
|
||||
buttons_area.show(ui.ctx(), |ui| {
|
||||
/// the y offset multiplier of the `buttons_area` area
|
||||
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
||||
|
||||
widgets_ontop(
|
||||
ui,
|
||||
format!("buttons_area_{}", i),
|
||||
&re,
|
||||
row_height * BUTTONS_Y_OFFSET,
|
||||
|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
// There's more than 1 function! Functions can now be deleted
|
||||
should_remove = ui
|
||||
@ -259,7 +260,8 @@ impl FunctionEntry {
|
||||
.clicked(),
|
||||
);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
should_remove
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ impl 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) {
|
||||
// start timer
|
||||
let start = instant::Instant::now();
|
||||
@ -501,8 +501,9 @@ impl epi::App for MathApp {
|
||||
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 `H` key is pressed, toggle Side Panel
|
||||
self.opened
|
||||
.side_panel
|
||||
.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);
|
||||
}
|
||||
|
||||
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)]
|
||||
mod autocomplete_tests {
|
||||
use super::*;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user