80 lines
2.4 KiB
Rust
80 lines
2.4 KiB
Rust
use circle::Circle;
|
|
use eframe::egui::Ui;
|
|
use egui_plot::PlotUi;
|
|
use linepath::LinePath;
|
|
use obround::Obround;
|
|
use rectangle::Rectangle;
|
|
|
|
use crate::application::CanvasColour;
|
|
|
|
use super::{point::Point, ClipperPath, ClipperPaths, DrawableRaw, Unit};
|
|
|
|
pub mod circle;
|
|
pub mod linepath;
|
|
pub mod obround;
|
|
pub mod rectangle;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Element {
|
|
Circle(Circle),
|
|
Rectangle(Rectangle),
|
|
Line(LinePath),
|
|
Obround(Obround),
|
|
}
|
|
|
|
impl Element {
|
|
pub fn draw_egui_plot(&self, ui: &mut PlotUi, colour: CanvasColour, selected: bool) {
|
|
match self {
|
|
Element::Circle(c) => c.draw_egui_plot(ui, colour, selected),
|
|
Element::Rectangle(r) => r.draw_egui_plot(ui, colour, selected),
|
|
Element::Line(l) => l.draw_egui_plot(ui, colour, selected),
|
|
Element::Obround(o) => o.draw_egui_plot(ui, colour, selected),
|
|
}
|
|
}
|
|
|
|
pub fn draw_egui(&self, ui: &mut Ui, selected: bool) {
|
|
match self {
|
|
Element::Circle(c) => c.draw_egui(ui, selected),
|
|
Element::Rectangle(r) => r.draw_egui(ui, selected),
|
|
Element::Line(l) => l.draw_egui(ui, selected),
|
|
Element::Obround(o) => o.draw_egui(ui, selected),
|
|
}
|
|
}
|
|
|
|
pub fn canvas_pos(&self) -> Point {
|
|
match self {
|
|
Element::Circle(c) => c.canvas_pos(),
|
|
Element::Rectangle(r) => r.canvas_pos(),
|
|
Element::Line(l) => l.canvas_pos(),
|
|
Element::Obround(o) => o.canvas_pos(),
|
|
}
|
|
}
|
|
|
|
pub fn to_paths(&self) -> ClipperPaths {
|
|
match self {
|
|
Element::Circle(c) => c.to_paths(),
|
|
Element::Rectangle(r) => r.to_paths(),
|
|
Element::Line(l) => l.to_paths(),
|
|
Element::Obround(o) => o.to_paths(),
|
|
}
|
|
}
|
|
|
|
pub fn outline(&self) -> ClipperPath {
|
|
match self {
|
|
Element::Circle(c) => c.outline(),
|
|
Element::Rectangle(r) => r.outline(),
|
|
Element::Line(l) => l.outline(),
|
|
Element::Obround(o) => o.outline(),
|
|
}
|
|
}
|
|
|
|
pub fn to_unit(&self, origin: Unit, to: Unit) -> Self {
|
|
match self {
|
|
Element::Circle(c) => Element::Circle(c.to_unit(origin, to)),
|
|
Element::Rectangle(r) => Element::Rectangle(r.to_unit(origin, to)),
|
|
Element::Line(l) => Element::Line(l.to_unit(origin, to)),
|
|
Element::Obround(o) => Element::Obround(o.to_unit(origin, to)),
|
|
}
|
|
}
|
|
}
|