changes
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#![feature(const_option_ext)]
|
#![feature(const_option_ext)]
|
||||||
#![feature(const_slice_index)]
|
#![feature(const_slice_index)]
|
||||||
#![feature(slice_split_at_unchecked)]
|
#![feature(slice_split_at_unchecked)]
|
||||||
|
#![feature(inline_const)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#![feature(const_option_ext)]
|
#![feature(const_option_ext)]
|
||||||
#![feature(const_slice_index)]
|
#![feature(const_slice_index)]
|
||||||
#![feature(slice_split_at_unchecked)]
|
#![feature(slice_split_at_unchecked)]
|
||||||
|
#![feature(inline_const)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|||||||
138
src/math_app.rs
138
src/math_app.rs
@@ -239,11 +239,11 @@ impl MathApp {
|
|||||||
cc.egui_ctx.set_fonts(data.fonts);
|
cc.egui_ctx.set_fonts(data.fonts);
|
||||||
|
|
||||||
// Set dark mode by default
|
// Set dark mode by default
|
||||||
cc.egui_ctx.set_visuals(crate::style::STYLE);
|
cc.egui_ctx.set_visuals(const { crate::style::dark() });
|
||||||
|
|
||||||
// Set spacing
|
// Set spacing
|
||||||
let mut style: egui::Style = (*cc.egui_ctx.style()).clone();
|
let mut style: egui::Style = (*cc.egui_ctx.style()).clone();
|
||||||
style.spacing = crate::style::SPACING;
|
style.spacing = const { crate::style::spacing() };
|
||||||
cc.egui_ctx.set_style(style);
|
cc.egui_ctx.set_style(style);
|
||||||
|
|
||||||
tracing::info!("Initialized! Took: {:?}", start.elapsed());
|
tracing::info!("Initialized! Took: {:?}", start.elapsed());
|
||||||
@@ -514,75 +514,81 @@ impl App for MathApp {
|
|||||||
self.side_panel(ctx);
|
self.side_panel(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
const EMPTY_FRAME: Frame = Frame {
|
|
||||||
inner_margin: Margin::symmetric(0.0, 0.0),
|
|
||||||
rounding: Rounding::none(),
|
|
||||||
fill: crate::style::STYLE.window_fill(),
|
|
||||||
..Frame::none()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Central panel which contains the central plot (or an error created when parsing)
|
// Central panel which contains the central plot (or an error created when parsing)
|
||||||
CentralPanel::default().frame(EMPTY_FRAME).show(ctx, |ui| {
|
CentralPanel::default()
|
||||||
// Display an error if it exists
|
.frame(
|
||||||
let errors_formatted: String = self
|
const {
|
||||||
.functions
|
Frame {
|
||||||
.get_entries()
|
inner_margin: Margin::symmetric(0.0, 0.0),
|
||||||
.iter()
|
rounding: Rounding::none(),
|
||||||
.map(|(_, func)| func.get_test_result())
|
fill: crate::style::STYLE.window_fill(),
|
||||||
.enumerate()
|
..Frame::none()
|
||||||
.filter(|(_, error)| error.is_some())
|
}
|
||||||
.map(|(i, error)| {
|
},
|
||||||
// use unwrap_unchecked as None Errors are already filtered out
|
)
|
||||||
unsafe { format!("(Function #{}) {}\n", i, error.as_ref().unwrap_unchecked()) }
|
.show(ctx, |ui| {
|
||||||
})
|
// Display an error if it exists
|
||||||
.collect::<String>();
|
let errors_formatted: String = self
|
||||||
|
.functions
|
||||||
|
.get_entries()
|
||||||
|
.iter()
|
||||||
|
.map(|(_, func)| func.get_test_result())
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, error)| error.is_some())
|
||||||
|
.map(|(i, error)| {
|
||||||
|
// use unwrap_unchecked as None Errors are already filtered out
|
||||||
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let available_width: usize = (ui.available_width() as usize) + 1; // Used in later logic
|
|
||||||
let width_changed = available_width != self.settings.plot_width;
|
|
||||||
self.settings.plot_width = available_width;
|
|
||||||
|
|
||||||
// Create and setup plot
|
|
||||||
Plot::new("plot")
|
|
||||||
.set_margin_fraction(Vec2::ZERO)
|
|
||||||
.data_aspect(1.0)
|
|
||||||
.include_y(0)
|
|
||||||
.show(ui, |plot_ui| {
|
|
||||||
let bounds = plot_ui.plot_bounds();
|
|
||||||
let min_x: f64 = bounds.min()[0];
|
|
||||||
let max_x: f64 = bounds.max()[0];
|
|
||||||
let min_max_changed =
|
|
||||||
(min_x != self.settings.min_x) | (max_x != self.settings.max_x);
|
|
||||||
self.settings.min_x = min_x;
|
|
||||||
self.settings.max_x = max_x;
|
|
||||||
|
|
||||||
dyn_mut_iter(self.functions.get_entries_mut()).for_each(|(_, function)| {
|
|
||||||
function.calculate(width_changed, min_max_changed, &self.settings)
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let area: Vec<Option<f64>> = self
|
let available_width: usize = (ui.available_width() as usize) + 1; // Used in later logic
|
||||||
.functions
|
let width_changed = available_width != self.settings.plot_width;
|
||||||
.get_entries()
|
self.settings.plot_width = available_width;
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, (_, function))| {
|
|
||||||
function.display(plot_ui, &self.settings, COLORS[i])
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
self.last_info.0 = if area.iter().any(|e| e.is_some()) {
|
// Create and setup plot
|
||||||
Some(format!("Area: {}", option_vec_printer(area.as_slice())))
|
Plot::new("plot")
|
||||||
} else {
|
.set_margin_fraction(Vec2::ZERO)
|
||||||
None
|
.data_aspect(1.0)
|
||||||
};
|
.include_y(0)
|
||||||
});
|
.show(ui, |plot_ui| {
|
||||||
});
|
let bounds = plot_ui.plot_bounds();
|
||||||
|
let min_x: f64 = bounds.min()[0];
|
||||||
|
let max_x: f64 = bounds.max()[0];
|
||||||
|
let min_max_changed =
|
||||||
|
(min_x != self.settings.min_x) | (max_x != self.settings.max_x);
|
||||||
|
self.settings.min_x = min_x;
|
||||||
|
self.settings.max_x = max_x;
|
||||||
|
|
||||||
|
dyn_mut_iter(self.functions.get_entries_mut()).for_each(|(_, function)| {
|
||||||
|
function.calculate(width_changed, min_max_changed, &self.settings)
|
||||||
|
});
|
||||||
|
|
||||||
|
let area: Vec<Option<f64>> = self
|
||||||
|
.functions
|
||||||
|
.get_entries()
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, (_, function))| {
|
||||||
|
function.display(plot_ui, &self.settings, COLORS[i])
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
self.last_info.0 = if area.iter().any(|e| e.is_some()) {
|
||||||
|
Some(format!("Area: {}", option_vec_printer(area.as_slice())))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Calculate and store the last time it took to draw the frame
|
// Calculate and store the last time it took to draw the frame
|
||||||
self.last_info.1 = start.map(|a| format!("Took: {:?}", a.elapsed()));
|
self.last_info.1 = start.map(|a| format!("Took: {:?}", a.elapsed()));
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ pub const fn dark() -> Visuals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SPACING: Spacing = spacing();
|
|
||||||
|
|
||||||
pub const fn spacing() -> Spacing {
|
pub const fn spacing() -> Spacing {
|
||||||
Spacing {
|
Spacing {
|
||||||
item_spacing: vec2(8.0, 3.0),
|
item_spacing: vec2(8.0, 3.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user