Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions egui_plot/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,16 @@ impl<'a> Plot<'a> {
}
}

/// Returns shapes (e.g. the boxed zoom rect) that should be painted on top of the plot contents.
fn handle_interactions(
&self,
ui: &Ui,
mem: &mut PlotMemory,
plot_ui: &mut PlotUi<'_>,
plot_rect: Rect,
axis_responses: &AxisResponses,
) {
) -> Vec<Shape> {
let mut foreground_shapes = Vec::new();
let response = &mut plot_ui.response;
let allow_drag = self.allow_drag.and(ui.is_enabled());
let allow_zoom = self.allow_zoom.and(ui.is_enabled());
Expand Down Expand Up @@ -1182,8 +1184,8 @@ impl<'a> Plot<'a> {
egui::StrokeKind::Middle,
), // Inner stroke
);
ui.painter().with_clip_rect(plot_rect).add(boxed_zoom_rect.0);
ui.painter().with_clip_rect(plot_rect).add(boxed_zoom_rect.1);
foreground_shapes.push(Shape::Rect(boxed_zoom_rect.0));
foreground_shapes.push(Shape::Rect(boxed_zoom_rect.1));
}
// when the click is release perform the zoom
if response.drag_stopped() {
Expand Down Expand Up @@ -1240,6 +1242,8 @@ impl<'a> Plot<'a> {
}
}
}

foreground_shapes
}

fn render_axis_widgets(&self, ui: &mut Ui, mem: &mut PlotMemory, mut axis_widgets: AxisWidgets<'_>) {
Expand Down Expand Up @@ -1656,7 +1660,7 @@ impl<'a> Plot<'a> {
self.compute_bounds(ui, &mut mem, &plot_ui, plot_rect);

// Handle interactions (modifies plot_ui.response in place)
self.handle_interactions(ui, &mut mem, &mut plot_ui, plot_rect, &axis_responses);
let foreground_shapes = self.handle_interactions(ui, &mut mem, &mut plot_ui, plot_rect, &axis_responses);

// Render axis widgets
self.render_axis_widgets(ui, &mut mem, axis_widgets);
Expand All @@ -1674,6 +1678,9 @@ impl<'a> Plot<'a> {
let painter = ui.painter().with_clip_rect(*mem.transform.frame());
painter.extend(shapes);

// Paint interaction shapes (e.g. the boxed zoom rect) on top of the plot contents.
painter.extend(foreground_shapes);

// Show coordinates in a corner of the plot
// Use ui to access style information and draw the coordinate text overlay
Self::show_coordinates(
Expand Down
Loading