(&mut self, ui: &mut egui::Ui)
| 18 | |
| 19 | impl InteractionExample { |
| 20 | pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response { |
| 21 | let id = ui.make_persistent_id("interaction_demo"); |
| 22 | |
| 23 | let plot = Plot::new("interaction_demo").id(id).height(300.0); |
| 24 | |
| 25 | let PlotResponse { |
| 26 | response, |
| 27 | inner: (screen_pos, pointer_coordinate, pointer_coordinate_drag_delta, bounds, hovered), |
| 28 | hovered_plot_item, |
| 29 | .. |
| 30 | } = plot.show(ui, |plot_ui| { |
| 31 | plot_ui.line( |
| 32 | Line::new("sin", PlotPoints::from_explicit_callback(move |x| x.sin(), .., 100)) |
| 33 | .color(egui::Color32::RED), |
| 34 | ); |
| 35 | plot_ui.line( |
| 36 | Line::new("cos", PlotPoints::from_explicit_callback(move |x| x.cos(), .., 100)) |
| 37 | .color(egui::Color32::BLUE), |
| 38 | ); |
| 39 | |
| 40 | ( |
| 41 | plot_ui.screen_from_plot(PlotPoint::new(0.0, 0.0)), |
| 42 | plot_ui.pointer_coordinate(), |
| 43 | plot_ui.pointer_coordinate_drag_delta(), |
| 44 | plot_ui.plot_bounds(), |
| 45 | plot_ui.response().hovered(), |
| 46 | ) |
| 47 | }); |
| 48 | |
| 49 | // Store for display in controls |
| 50 | self.last_bounds = Some(bounds); |
| 51 | self.last_screen_pos = screen_pos; |
| 52 | self.last_pointer_coordinate = pointer_coordinate; |
| 53 | self.last_pointer_drag_delta = pointer_coordinate_drag_delta; |
| 54 | self.last_hovered = hovered; |
| 55 | self.last_hovered_item = hovered_plot_item; |
| 56 | |
| 57 | response |
| 58 | } |
| 59 | |
| 60 | pub fn show_controls(&self, ui: &mut egui::Ui) -> Response { |
| 61 | if let Some(bounds) = &self.last_bounds { |
no test coverage detected