use egui::emath::NumExt as _;
use egui::epaint::{Color32, Rgba, Stroke};
use crate::transform::{PlotBounds, PlotTransform};
use super::{Orientation, PlotPoint};
pub(super) trait RectElement {
fn name(&self) -> &str;
fn bounds_min(&self) -> PlotPoint;
fn bounds_max(&self) -> PlotPoint;
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.extend_with(&self.bounds_min());
bounds.extend_with(&self.bounds_max());
bounds
}
fn arguments_with_ruler(&self) -> Vec<PlotPoint> {
vec![self.bounds().center()]
}
fn values_with_ruler(&self) -> Vec<PlotPoint>;
fn orientation(&self) -> Orientation;
fn point_at(&self, argument: f64, value: f64) -> PlotPoint {
match self.orientation() {
Orientation::Horizontal => PlotPoint::new(value, argument),
Orientation::Vertical => PlotPoint::new(argument, value),
}
}
fn corner_value(&self) -> PlotPoint {
PlotPoint {
x: self.bounds_max().x,
y: self.bounds_max().y,
}
}
fn default_values_format(&self, transform: &PlotTransform) -> String;
}
pub(super) fn highlighted_color(mut stroke: Stroke, fill: Color32) -> (Stroke, Color32) {
stroke.width *= 2.0;
let mut fill = Rgba::from(fill);
if fill.is_additive() {
fill = 1.3 * fill;
} else {
let fill_alpha = (2.0 * fill.a()).at_most(1.0);
fill = fill.to_opaque().multiply(fill_alpha);
}
(stroke, fill.into())
}