MCPcopy Create free account
hub / github.com/emilk/egui_plot / show_plot

Method show_plot

examples/custom_plot_manipulation/src/app.rs:33–99  ·  view source on GitHub ↗
(&self, ui: &mut egui::Ui)

Source from the content-addressed store, hash-verified

31
32impl CustomPlotManipulationExample {
33 pub fn show_plot(&self, ui: &mut egui::Ui) -> Response {
34 let (scroll, pointer_down, modifiers) = ui.input(|i| {
35 let scroll = i.events.iter().find_map(|e| match e {
36 Event::MouseWheel {
37 unit: _, // TODO(anyone): we should respect this
38 delta,
39 ..
40 } => Some(*delta),
41 _ => None,
42 });
43 (scroll, i.pointer.primary_down(), i.modifiers)
44 });
45
46 egui_plot::Plot::new("plot")
47 .allow_zoom(false)
48 .allow_drag(false)
49 .allow_scroll(false)
50 .invert_x(false)
51 .invert_y(true)
52 .legend(Legend::default())
53 .show(ui, |plot_ui| {
54 if let Some(mut scroll) = scroll {
55 if modifiers.ctrl == self.ctrl_to_zoom {
56 scroll = Vec2::splat(scroll.x + scroll.y);
57 let mut zoom_factor = Vec2::from([
58 (scroll.x * self.zoom_speed / 10.0).exp(),
59 (scroll.y * self.zoom_speed / 10.0).exp(),
60 ]);
61 if self.lock_x {
62 zoom_factor.x = 1.0;
63 }
64 if self.lock_y {
65 zoom_factor.y = 1.0;
66 }
67 plot_ui.zoom_bounds_around_hovered(zoom_factor);
68 } else {
69 if modifiers.shift == self.shift_to_horizontal {
70 scroll = Vec2::new(scroll.y, scroll.x);
71 }
72 if self.lock_x {
73 scroll.x = 0.0;
74 }
75 if self.lock_y {
76 scroll.y = 0.0;
77 }
78 let delta_pos = self.scroll_speed * scroll;
79 plot_ui.translate_bounds(delta_pos);
80 }
81 }
82 if plot_ui.response().hovered() && pointer_down {
83 let mut pointer_translate = -plot_ui.pointer_coordinate_drag_delta();
84 if self.lock_x {
85 pointer_translate.x = 0.0;
86 }
87 if self.lock_y {
88 pointer_translate.y = 0.0;
89 }
90 plot_ui.translate_bounds(pointer_translate);

Callers 1

show_uiMethod · 0.45

Calls 14

showMethod · 0.80
legendMethod · 0.80
invert_yMethod · 0.80
invert_xMethod · 0.80
allow_scrollMethod · 0.80
allow_dragMethod · 0.80
allow_zoomMethod · 0.80
responseMethod · 0.80
lineMethod · 0.80
translate_boundsMethod · 0.45

Tested by

no test coverage detected