custom function colors

This commit is contained in:
Simon Gardling 2022-04-04 13:59:18 -04:00
parent 5d71c82c0d
commit 6041da764b
3 changed files with 28 additions and 4 deletions

View File

@ -2,6 +2,7 @@ use crate::function::Riemann;
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
use const_format::formatc; use const_format::formatc;
use eframe::epaint::Color32;
use shadow_rs::shadow; use shadow_rs::shadow;
shadow!(build); shadow!(build);
@ -46,3 +47,24 @@ const_assert!(DEFAULT_MAX_X > DEFAULT_MIN_X);
/// Default number of integral boxes /// Default number of integral boxes
pub const DEFAULT_INTEGRAL_NUM: usize = 100; pub const DEFAULT_INTEGRAL_NUM: usize = 100;
pub const COLORS: &'static [Color32; 14] = &[
Color32::RED,
// Color32::GREEN,
// Color32::YELLOW,
// Color32::BLUE,
Color32::BROWN,
Color32::GOLD,
Color32::GRAY,
Color32::WHITE,
Color32::LIGHT_YELLOW,
Color32::LIGHT_GREEN,
// Color32::LIGHT_BLUE,
Color32::LIGHT_GRAY,
Color32::LIGHT_RED,
Color32::DARK_GRAY,
Color32::DARK_RED,
Color32::KHAKI,
Color32::DARK_GREEN,
Color32::DARK_BLUE,
];

View File

@ -327,7 +327,9 @@ impl FunctionEntry {
/// Displays the function's output on PlotUI `plot_ui` with settings /// Displays the function's output on PlotUI `plot_ui` with settings
/// `settings`. Returns an `Option<f64>` of the calculated integral /// `settings`. Returns an `Option<f64>` of the calculated integral
pub fn display(&self, plot_ui: &mut PlotUi, settings: &AppSettings) -> Option<f64> { pub fn display(
&self, plot_ui: &mut PlotUi, settings: &AppSettings, main_plot_color: Color32,
) -> Option<f64> {
if self.test_result.is_some() { if self.test_result.is_some() {
return None; return None;
} }
@ -341,7 +343,7 @@ impl FunctionEntry {
back_data back_data
.clone() .clone()
.to_line() .to_line()
.color(Color32::RED) .color(main_plot_color)
.name(self.get_func_raw()), .name(self.get_func_raw()),
); );
} }

View File

@ -593,7 +593,7 @@ impl epi::App for MathApp {
// Button to add a new function // Button to add a new function
if ui if ui
.add(Button::new("Add Function")) .add_enabled(14 > self.func_strs.len(), Button::new("Add Function"))
.on_hover_text("Create and graph new function") .on_hover_text("Create and graph new function")
.clicked() .clicked()
{ {
@ -755,7 +755,7 @@ impl epi::App for MathApp {
.functions .functions
.iter() .iter()
.enumerate() .enumerate()
.map(|(_, function)| function.display(plot_ui, &self.settings)) .map(|(i, function)| function.display(plot_ui, &self.settings, COLORS[i]))
.collect(); .collect();
}); });
}); });