From 0fe0c8115cf2ca5604b359ffd8fd3984d93ab1f6 Mon Sep 17 00:00:00 2001 From: Andrew Langmeier Date: Mon, 10 Oct 2022 03:57:25 -0400 Subject: [PATCH] Add ability to control double click reset in plot widget (#2115) * Add ability to control double click reset in plot widget * improve docstring * small optimization Co-authored-by: Emil Ernerfeldt --- crates/egui/src/widgets/plot/mod.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index c114d594..e9338428 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -266,10 +266,11 @@ pub struct Plot { allow_zoom: bool, allow_drag: bool, allow_scroll: bool, + allow_double_click_reset: bool, + allow_boxed_zoom: bool, auto_bounds: AxisBools, min_auto_bounds: PlotBounds, margin_fraction: Vec2, - allow_boxed_zoom: bool, boxed_zoom_pointer_button: PointerButton, linked_axes: Option, linked_cursors: Option, @@ -304,10 +305,11 @@ impl Plot { allow_zoom: true, allow_drag: true, allow_scroll: true, + allow_double_click_reset: true, + allow_boxed_zoom: true, auto_bounds: false.into(), min_auto_bounds: PlotBounds::NOTHING, margin_fraction: Vec2::splat(0.05), - allow_boxed_zoom: true, boxed_zoom_pointer_button: PointerButton::Secondary, linked_axes: None, linked_cursors: None, @@ -406,6 +408,13 @@ impl Plot { self } + /// Whether to allow double clicking to reset the view. + /// Default: `true`. + pub fn allow_double_click_reset(mut self, on: bool) -> Self { + self.allow_double_click_reset = on; + self + } + /// Set the side margin as a fraction of the plot size. Only used for auto bounds. /// /// For instance, a value of `0.1` will add 10% space on both sides. @@ -629,8 +638,9 @@ impl Plot { center_x_axis, center_y_axis, allow_zoom, - allow_scroll, allow_drag, + allow_scroll, + allow_double_click_reset, allow_boxed_zoom, boxed_zoom_pointer_button: boxed_zoom_pointer, auto_bounds, @@ -805,8 +815,8 @@ impl Plot { } }; - // Allow double clicking to reset to the initial bounds. - if response.double_clicked_by(PointerButton::Primary) { + // Allow double clicking to reset to the initial bounds? + if allow_double_click_reset && response.double_clicked_by(PointerButton::Primary) { bounds_modified = false.into(); }