240 lines
12 KiB
Rust
240 lines
12 KiB
Rust
|
use eframe::{
|
||
|
egui::{self, Vec2},
|
||
|
emath::TSTransform,
|
||
|
};
|
||
|
|
||
|
use super::{
|
||
|
canvas::draw_canvas,
|
||
|
panels::{actions::draw_action_panel, header::draw_header, sidebar::draw_sidebar},
|
||
|
Application,
|
||
|
};
|
||
|
|
||
|
impl eframe::App for Application {
|
||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||
|
// let window_size = ctx.screen_rect().size();
|
||
|
|
||
|
draw_header(ctx, self);
|
||
|
|
||
|
draw_sidebar(ctx, self);
|
||
|
|
||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||
|
// ui.horizontal(|ui| {
|
||
|
// let name_label = ui.label("Your name: ");
|
||
|
// ui.text_edit_singleline(&mut self.name)
|
||
|
// .labelled_by(name_label.id);
|
||
|
// });
|
||
|
// ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
|
||
|
// if ui.button("Increment").clicked() {
|
||
|
// self.age += 1;
|
||
|
// }
|
||
|
// ui.label(format!("Hello '{}', age {}", self.name, self.age));
|
||
|
|
||
|
// // ui.image(egui::include_image!(
|
||
|
// // "../../../crates/egui/assets/ferris.png"
|
||
|
// // ));
|
||
|
|
||
|
let pointer_pos = ui.ctx().input(|i| i.pointer.hover_pos());
|
||
|
|
||
|
draw_action_panel(ui, self);
|
||
|
|
||
|
// ui.label(
|
||
|
// "Pan, zoom in, and zoom out with scrolling (see the plot demo for more instructions). \
|
||
|
// Double click on the background to reset.",
|
||
|
// );
|
||
|
// ui.vertical_centered(|ui| {
|
||
|
// ui.add(crate::egui_github_link_file!());
|
||
|
// });
|
||
|
// if let Some(pos) = pointer_pos {
|
||
|
// ui.label(format!("Translation: {:?}", self.transform.translation));
|
||
|
// ui.label(format!("ScLING: {}", self.transform.scaling));
|
||
|
// ui.label(format!("Canvas start: {}", self.canvas.1.min));
|
||
|
// }
|
||
|
ui.separator();
|
||
|
|
||
|
// ui.allocate_ui(ui.available_size(), |ui| {
|
||
|
// egui::TopBottomPanel::bottom("BottomCanvas")
|
||
|
// .show_separator_line(false)
|
||
|
// .exact_height(15.)
|
||
|
// .show_inside(ui, |ui| {});
|
||
|
// egui::SidePanel::left("LeftCanvas")
|
||
|
// .show_separator_line(false)
|
||
|
// .exact_width(15.)
|
||
|
// .show_inside(ui, |ui| {});
|
||
|
|
||
|
// egui::CentralPanel::default()
|
||
|
// .frame(egui::Frame::none().inner_margin(0.).outer_margin(0.))
|
||
|
// .show_inside(ui, |ui| {
|
||
|
// let sin: egui_plot::PlotPoints = (0..1000)
|
||
|
// .map(|i| {
|
||
|
// let x = i as f64 * 0.01;
|
||
|
// [x, x.sin()]
|
||
|
// })
|
||
|
// .collect();
|
||
|
// let line = egui_plot::Line::new(sin);
|
||
|
// egui_plot::Plot::new("my_plot")
|
||
|
// .view_aspect(2.0)
|
||
|
// .data_aspect(1.0)
|
||
|
// .show(ui, |plot_ui| {
|
||
|
// super::canvas::gerbers::draw_gerbers_(plot_ui, self);
|
||
|
// super::canvas::excellons::draw_excellons_(plot_ui, self);
|
||
|
// super::canvas::geometries::draw_geometries_(plot_ui, self)
|
||
|
// // plot_ui.line(line);
|
||
|
// // for (_, (name, geo)) in &self.gerbers {
|
||
|
// // let path = geo.outline_union.iter().map(|path| {
|
||
|
// // let mut points = path
|
||
|
// // .iter()
|
||
|
// // .map(|p| [p.x(), p.y()])
|
||
|
// // .collect::<Vec<[f64; 2]>>();
|
||
|
|
||
|
// // points.push(points[0]);
|
||
|
|
||
|
// // (
|
||
|
// // egui_plot::Line::new(egui_plot::PlotPoints::from(
|
||
|
// // points.clone(),
|
||
|
// // ))
|
||
|
// // .color(egui::Color32::DARK_BLUE),
|
||
|
// // egui_plot::Polygon::new(egui_plot::PlotPoints::from(
|
||
|
// // points,
|
||
|
// // ))
|
||
|
// // .fill_color(egui::Color32::LIGHT_GREEN),
|
||
|
// // )
|
||
|
// // });
|
||
|
|
||
|
// // for line in path {
|
||
|
// // plot_ui.line(line.0);
|
||
|
// // plot_ui.polygon(line.1);
|
||
|
// // }
|
||
|
|
||
|
// // let circle_points: egui_plot::PlotPoints = (0..=400)
|
||
|
// // .map(|i| {
|
||
|
// // let t = egui::remap(
|
||
|
// // i as f64,
|
||
|
// // 0.0..=(400 as f64),
|
||
|
// // 0.0..=std::f64::consts::TAU,
|
||
|
// // );
|
||
|
// // let r = 10.;
|
||
|
// // [r * t.cos() + 20. as f64, r * t.sin() + 20. as f64]
|
||
|
// // })
|
||
|
// // .collect();
|
||
|
|
||
|
// // let poly = egui_plot::Polygon::new(
|
||
|
// // egui_plot::PlotPoints::from(circle_points),
|
||
|
// // )
|
||
|
// // .fill_color(egui::Color32::LIGHT_GREEN);
|
||
|
// // plot_ui.polygon(poly);
|
||
|
// // }
|
||
|
// });
|
||
|
|
||
|
// // let (id, rect) = ui.allocate_space(ui.available_size());
|
||
|
// // let response = ui.interact(rect, id, egui::Sense::click_and_drag());
|
||
|
// // self.canvas = (id, rect);
|
||
|
// // // Allow dragging the background as well.
|
||
|
// // if response.dragged() {
|
||
|
// // self.transform.translation += response.drag_delta();
|
||
|
// // }
|
||
|
|
||
|
// // // Plot-like reset
|
||
|
// // if response.double_clicked() {
|
||
|
// // self.transform = TSTransform::default();
|
||
|
// // self.transform = TSTransform::from_translation(Vec2::new(
|
||
|
// // rect.width() / 2.,
|
||
|
// // rect.height() / 2.,
|
||
|
// // ));
|
||
|
// // }
|
||
|
|
||
|
// // let transform =
|
||
|
// // TSTransform::from_translation(ui.min_rect().left_top().to_vec2())
|
||
|
// // * self.transform;
|
||
|
|
||
|
// // if let Some(pointer) = ui.ctx().input(|i| i.pointer.hover_pos()) {
|
||
|
// // // Note: doesn't catch zooming / panning if a button in this PanZoom container is hovered.
|
||
|
// // if response.hovered() {
|
||
|
// // let pointer_in_layer = transform.inverse() * pointer;
|
||
|
// // let zoom_delta = ui.ctx().input(|i| i.zoom_delta());
|
||
|
// // let pan_delta = ui.ctx().input(|i| i.smooth_scroll_delta);
|
||
|
|
||
|
// // // Zoom in on pointer:
|
||
|
// // self.transform = self.transform
|
||
|
// // * TSTransform::from_translation(pointer_in_layer.to_vec2())
|
||
|
// // * TSTransform::from_scaling(zoom_delta)
|
||
|
// // * TSTransform::from_translation(-pointer_in_layer.to_vec2());
|
||
|
|
||
|
// // // Pan:
|
||
|
// // self.transform =
|
||
|
// // TSTransform::from_translation(pan_delta) * self.transform;
|
||
|
// // }
|
||
|
// // }
|
||
|
|
||
|
// // self.test_transform = transform;
|
||
|
// })
|
||
|
// });
|
||
|
|
||
|
// let (id, rect) = ui.allocate_space(Vec2::new(ui.available_width(), 15.));
|
||
|
// ui.painter().add(RectShape::stroke(
|
||
|
// rect,
|
||
|
// Rounding::same(0.),
|
||
|
// egui::Stroke::new(0.2, Color32::BLACK),
|
||
|
// ));
|
||
|
|
||
|
// let (id, rect) = ui.allocate_space(Vec2::new(10., ui.available_height()));
|
||
|
// ui.painter().add(RectShape::stroke(
|
||
|
// rect,
|
||
|
// Rounding::same(0.),
|
||
|
// egui::Stroke::new(0.2, Color32::BLACK),
|
||
|
// ));
|
||
|
|
||
|
// let (id, rect) = ui.allocate_space(ui.available_size());
|
||
|
// let response = ui.interact(rect, id, egui::Sense::click_and_drag());
|
||
|
// self.canvas = (id, rect);
|
||
|
// // Allow dragging the background as well.
|
||
|
// if response.dragged() {
|
||
|
// self.transform.translation += response.drag_delta();
|
||
|
// }
|
||
|
|
||
|
// // Plot-like reset
|
||
|
// if response.double_clicked() {
|
||
|
// self.transform = TSTransform::default();
|
||
|
// self.transform =
|
||
|
// TSTransform::from_translation(Vec2::new(rect.width() / 2., rect.height() / 2.));
|
||
|
// }
|
||
|
|
||
|
// let transform =
|
||
|
// TSTransform::from_translation(ui.min_rect().left_top().to_vec2()) * self.transform;
|
||
|
|
||
|
// if let Some(pointer) = ui.ctx().input(|i| i.pointer.hover_pos()) {
|
||
|
// // Note: doesn't catch zooming / panning if a button in this PanZoom container is hovered.
|
||
|
// if response.hovered() {
|
||
|
// let pointer_in_layer = transform.inverse() * pointer;
|
||
|
// let zoom_delta = ui.ctx().input(|i| i.zoom_delta());
|
||
|
// let pan_delta = ui.ctx().input(|i| i.smooth_scroll_delta);
|
||
|
|
||
|
// // Zoom in on pointer:
|
||
|
// self.transform = self.transform
|
||
|
// * TSTransform::from_translation(pointer_in_layer.to_vec2())
|
||
|
// * TSTransform::from_scaling(zoom_delta)
|
||
|
// * TSTransform::from_translation(-pointer_in_layer.to_vec2());
|
||
|
|
||
|
// // Pan:
|
||
|
// self.transform = TSTransform::from_translation(pan_delta) * self.transform;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// self.test_transform = transform;
|
||
|
|
||
|
// let p = ui.painter_at(rect);
|
||
|
// p.add(RectShape::filled(
|
||
|
// Rect::from_center_size(rect.center(), Vec2::new(rect.width(), 1.)),
|
||
|
// Rounding::ZERO,
|
||
|
// Color32::LIGHT_RED,
|
||
|
// ));
|
||
|
// p.add(RectShape::filled(
|
||
|
// Rect::from_center_size(rect.center(), Vec2::new(1., rect.height())),
|
||
|
// Rounding::ZERO,
|
||
|
// Color32::LIGHT_RED,
|
||
|
// ));
|
||
|
|
||
|
draw_canvas(ui, self);
|
||
|
});
|
||
|
}
|
||
|
}
|