use no border for the CentralPanel

This commit is contained in:
Simon Gardling 2022-04-22 00:42:17 -04:00
parent 9c6e18dc7f
commit fb0b076f62

View File

@ -531,64 +531,70 @@ impl epi::App for MathApp {
// Central panel which contains the central plot (or an error created when // Central panel which contains the central plot (or an error created when
// parsing) // parsing)
CentralPanel::default().show(ctx, |ui| { CentralPanel::default()
// Display an error if it exists .frame(egui::Frame::none())
let errors_formatted: String = self .show(ctx, |ui| {
.functions // Display an error if it exists
.iter() let errors_formatted: String = self
.map(|func| func.get_test_result()) .functions
.enumerate() .iter()
.filter(|(_, error)| error.is_some()) .map(|func| func.get_test_result())
.map(|(i, error)| { .enumerate()
// use unwrap_unchecked as None Errors are already filtered out .filter(|(_, error)| error.is_some())
unsafe { format!("(Function #{}) {}\n", i, error.as_ref().unwrap_unchecked()) } .map(|(i, error)| {
}) // use unwrap_unchecked as None Errors are already filtered out
.collect::<String>(); unsafe {
format!("(Function #{}) {}\n", i, error.as_ref().unwrap_unchecked())
}
})
.collect::<String>();
if !errors_formatted.is_empty() { if !errors_formatted.is_empty() {
ui.centered_and_justified(|ui| { ui.centered_and_justified(|ui| {
ui.heading(errors_formatted); ui.heading(errors_formatted);
}); });
return; return;
} }
let available_width: usize = (ui.available_width() as usize) + 1; // Used in later logic let available_width: usize = (ui.available_width() as usize) + 1; // Used in later logic
let width_changed = available_width != self.settings.plot_width; let width_changed = available_width != self.settings.plot_width;
if width_changed { if width_changed {
self.settings.plot_width = available_width; self.settings.plot_width = available_width;
} }
// Create and setup plot // Create and setup plot
Plot::new("plot") Plot::new("plot")
.set_margin_fraction(Vec2::ZERO) .set_margin_fraction(Vec2::ZERO)
.data_aspect(1.0) .data_aspect(1.0)
.include_y(0) .include_y(0)
.legend(egui::plot::Legend::default()) .legend(egui::plot::Legend::default())
.show(ui, |plot_ui| { .show(ui, |plot_ui| {
let bounds = plot_ui.plot_bounds(); let bounds = plot_ui.plot_bounds();
let minx_bounds: f64 = bounds.min()[0]; let minx_bounds: f64 = bounds.min()[0];
let maxx_bounds: f64 = bounds.max()[0]; let maxx_bounds: f64 = bounds.max()[0];
dyn_mut_iter(&mut self.functions) dyn_mut_iter(&mut self.functions)
.enumerate() .enumerate()
.for_each(|(_, function)| { .for_each(|(_, function)| {
function.calculate( function.calculate(
&minx_bounds, &minx_bounds,
&maxx_bounds, &maxx_bounds,
width_changed, width_changed,
&self.settings, &self.settings,
) )
}); });
area_list = self area_list = self
.functions .functions
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, function)| function.display(plot_ui, &self.settings, COLORS[i])) .map(|(i, function)| {
.collect(); function.display(plot_ui, &self.settings, COLORS[i])
}); })
}); .collect();
});
});
// Store list of functions' areas along with the time it took to process. // Store list of functions' areas along with the time it took to process.
self.last_info = (area_list, start.elapsed()); self.last_info = (area_list, start.elapsed());
} }