use egui::{Response, Sense, vec2};
use super::told;
use crate::mark::Shape;
use crate::ui::theme::{ROW, hue};
pub const MARK: &str = "mark";
pub fn mark(ui: &mut egui::Ui, help: &str) -> Response {
let (rect, seat) = ui.allocate_exact_size(vec2(ROW, ROW), Sense::click());
super::dress(ui, &seat, rect, MARK);
paint(ui.painter(), rect);
told(seat.on_hover_cursor(egui::CursorIcon::PointingHand), help)
}
fn paint(painter: &egui::Painter, rect: egui::Rect) {
let side = rect.width().min(rect.height());
let origin = rect.center() - vec2(side, side) / 2.0;
let at = |(x, y): crate::mark::Point| origin + vec2(x * side, y * side);
for shape in crate::mark::mark() {
painter.add(match &shape {
Shape::Trace { path, width, fill } => egui::Shape::line(
path.iter().map(|point| at(*point)).collect(),
egui::Stroke::new(width * side, hue(*fill)),
),
Shape::Lune { ribs, fill } => egui::Shape::convex_polygon(
Shape::outline(ribs).into_iter().map(at).collect(),
hue(*fill),
egui::Stroke::NONE,
),
Shape::Disc {
cx,
cy,
radius,
fill,
} => egui::Shape::circle_filled(at((*cx, *cy)), radius * side, hue(*fill)),
});
}
}