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

Method handle_interactions

egui_plot/src/plot.rs:1099–1241  ·  view source on GitHub ↗
(
        &self,
        ui: &Ui,
        mem: &mut PlotMemory,
        plot_ui: &mut PlotUi<'_>,
        plot_rect: Rect,
        axis_responses: &AxisResponses,
    )

Source from the content-addressed store, hash-verified

1097 }
1098
1099 fn handle_interactions(
1100 &self,
1101 ui: &Ui,
1102 mem: &mut PlotMemory,
1103 plot_ui: &mut PlotUi<'_>,
1104 plot_rect: Rect,
1105 axis_responses: &AxisResponses,
1106 ) {
1107 let response = &mut plot_ui.response;
1108 let allow_drag = self.allow_drag.and(ui.is_enabled());
1109 let allow_zoom = self.allow_zoom.and(ui.is_enabled());
1110 let allow_scroll = self.allow_scroll.and(ui.is_enabled());
1111
1112 // Dragging
1113 if allow_drag.any() && response.dragged_by(self.pan_pointer_button) {
1114 *response = response.clone().on_hover_cursor(CursorIcon::Grabbing);
1115 let mut delta = -response.drag_delta();
1116 if !allow_drag.x {
1117 delta.x = 0.0;
1118 }
1119 if !allow_drag.y {
1120 delta.y = 0.0;
1121 }
1122 mem.transform.translate_bounds((delta.x as f64, delta.y as f64));
1123 mem.auto_bounds = mem.auto_bounds.and(!allow_drag);
1124 }
1125
1126 // Drag axes to zoom:
1127 for d in 0..2 {
1128 if self.allow_axis_zoom_drag[d]
1129 && let Some(axis_response) = axis_responses[d].iter().find(|r| r.dragged_by(PointerButton::Primary))
1130 && let Some(drag_start_pos) = ui.input(|i| i.pointer.press_origin())
1131 {
1132 let delta = axis_response.drag_delta();
1133
1134 let axis_zoom = 1.0 + (0.02 * delta[d]).clamp(-1.0, 1.0);
1135
1136 let zoom = if self.data_aspect.is_some() {
1137 // Zoom both axes equally to maintain aspect ratio:
1138 Vec2::splat(axis_zoom)
1139 } else {
1140 let mut zoom = Vec2::splat(1.0);
1141 zoom[d] = axis_zoom;
1142 zoom
1143 };
1144
1145 if zoom != Vec2::splat(1.0) {
1146 let mut zoom_center = plot_rect.center();
1147 zoom_center[d] = drag_start_pos[d];
1148 mem.transform.zoom(zoom, zoom_center);
1149 mem.auto_bounds = false.into();
1150 }
1151 }
1152 }
1153
1154 // Zooming
1155 if self.allow_boxed_zoom {
1156 // Save last click to allow boxed zooming

Callers 1

show_dynMethod · 0.80

Calls 9

centerMethod · 0.80
addMethod · 0.80
value_from_positionMethod · 0.80
minMethod · 0.80
maxMethod · 0.80
is_validMethod · 0.80
translate_boundsMethod · 0.45
zoomMethod · 0.45
set_boundsMethod · 0.45

Tested by

no test coverage detected