From 599e9193dd2c1d7b4c7064b8b1872fb28ffc685f Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 10 Jan 2023 10:31:14 +0100 Subject: [PATCH 01/10] add Plot::allow_auto_bounds --- CHANGELOG.md | 1 + crates/egui/src/widgets/plot/mod.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3adff09a184..45828ae1b16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG ## Unreleased ### Added ⭐ +* Add`Plot::allow_auto_bounds` auto bounds or keep bounds. Default: `true`. * `Event::Key` now has a `repeat` field that is set to `true` if the event was the result of a key-repeat ([#2435](https://github.com/emilk/egui/pull/2435)). * Add `Slider::drag_value_speed`, which lets you ask for finer precision when dragging the slider value rather than the actual slider. * Add `Memory::any_popup_open`, which returns true if any popup is currently open ([#2464](https://github.com/emilk/egui/pull/2464)). diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index bbefe4b44b7..204922a12f5 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -268,6 +268,7 @@ pub struct Plot { allow_scroll: bool, allow_double_click_reset: bool, allow_boxed_zoom: bool, + allow_auto_bounds: bool, auto_bounds: AxisBools, min_auto_bounds: PlotBounds, margin_fraction: Vec2, @@ -310,6 +311,7 @@ impl Plot { allow_scroll: true, allow_double_click_reset: true, allow_boxed_zoom: true, + allow_auto_bounds: true, auto_bounds: false.into(), min_auto_bounds: PlotBounds::NOTHING, margin_fraction: Vec2::splat(0.05), @@ -437,6 +439,14 @@ impl Plot { self } + /// Whether to allow auto bounds. Default: `true`. + /// `false` keep bounds, it gives the ability with a pointer down to the drawn outside the plot area + /// without ask auto bounds. + pub fn allow_auto_bounds(mut self, on: bool) -> Self { + self.allow_auto_bounds = on; + self + } + /// Config the button pointer to use for boxed zooming. Default: [`Secondary`](PointerButton::Secondary) pub fn boxed_zoom_pointer_button(mut self, boxed_zoom_pointer_button: PointerButton) -> Self { self.boxed_zoom_pointer_button = boxed_zoom_pointer_button; @@ -683,6 +693,7 @@ impl Plot { show_axes, linked_axes, linked_cursors, + allow_auto_bounds, clamp_grid, grid_spacers, @@ -839,6 +850,10 @@ impl Plot { } }; + if !allow_auto_bounds { + bounds_modified = true.into(); + } + // Allow double clicking to reset to the initial bounds? if allow_double_click_reset && response.double_clicked_by(PointerButton::Primary) { bounds_modified = false.into(); From 6b057c45f687b8c3231c5036fd2df92e6f383ee2 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Mon, 14 Aug 2023 21:58:18 +0200 Subject: [PATCH 02/10] reformulate docstring: allow_auto_bounds --- crates/egui/src/widgets/plot/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 204922a12f5..e80e7368d3e 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -440,8 +440,6 @@ impl Plot { } /// Whether to allow auto bounds. Default: `true`. - /// `false` keep bounds, it gives the ability with a pointer down to the drawn outside the plot area - /// without ask auto bounds. pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self From 53ed8ecaecca8ac1e60462e8aba70cbeb0631e05 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Mon, 14 Aug 2023 22:00:35 +0200 Subject: [PATCH 03/10] Update CHANGELOG.md Co-authored-by: Emil Ernerfeldt --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45828ae1b16..3adff09a184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,6 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG ## Unreleased ### Added ⭐ -* Add`Plot::allow_auto_bounds` auto bounds or keep bounds. Default: `true`. * `Event::Key` now has a `repeat` field that is set to `true` if the event was the result of a key-repeat ([#2435](https://github.com/emilk/egui/pull/2435)). * Add `Slider::drag_value_speed`, which lets you ask for finer precision when dragging the slider value rather than the actual slider. * Add `Memory::any_popup_open`, which returns true if any popup is currently open ([#2464](https://github.com/emilk/egui/pull/2464)). From 57d2642cc97952426d97e29323fc1bdc7666fb82 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Tue, 15 Aug 2023 08:51:38 +0200 Subject: [PATCH 04/10] Update formating --- crates/egui/src/widgets/plot/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index e80e7368d3e..a7c2b8efb84 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -848,7 +848,7 @@ impl Plot { } }; - if !allow_auto_bounds { + if !allow_auto_bounds { bounds_modified = true.into(); } From bd77c279259a364381fe969aa68098a7062f3235 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 16 Aug 2023 22:02:56 +0200 Subject: [PATCH 05/10] Update logic allow_auto_bounds --- crates/egui/src/widgets/plot/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 604795b7f65..341f80c864c 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -378,6 +378,8 @@ impl Plot { } /// Whether to allow auto bounds. Default: `true`. + /// If `false`, we set bounds_modified to true to prevent auto adjusting, + /// also we check if the user double clicked to reset bounds. If so, set bounds_modified to false. pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self @@ -950,14 +952,19 @@ impl Plot { }); }; + if !allow_auto_bounds { + bounds_modified = true.into(); + } + + let reset_bounds = allow_double_click_reset && response.double_clicked(); // Allow double clicking to reset to the initial bounds. - if allow_double_click_reset && response.double_clicked() { + if reset_bounds { bounds_modified = false.into(); } - // Apply bounds modifications. - if allow_auto_bounds { + if allow_auto_bounds && reset_bounds { + // Apply bounds modifications. for modification in bounds_modifications { match modification { BoundsModification::Set(new_bounds) => { From 3da8c63211f12c01c5b3d0dc657b94b4caeb03f0 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 16 Aug 2023 22:28:53 +0200 Subject: [PATCH 06/10] Update logic allow_auto_bounds --- crates/egui/src/widgets/plot/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 341f80c864c..f77ae1e5b9d 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -378,8 +378,8 @@ impl Plot { } /// Whether to allow auto bounds. Default: `true`. - /// If `false`, we set bounds_modified to true to prevent auto adjusting, - /// also we check if the user double clicked to reset bounds. If so, set bounds_modified to false. + /// If `false`, it set bounds_modified to true to prevent auto adjusting bounds, + /// also it check if the user double clicked to reset bounds. If so, set bounds_modified to false. pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self @@ -952,10 +952,6 @@ impl Plot { }); }; - if !allow_auto_bounds { - bounds_modified = true.into(); - } - let reset_bounds = allow_double_click_reset && response.double_clicked(); // Allow double clicking to reset to the initial bounds. @@ -963,7 +959,7 @@ impl Plot { bounds_modified = false.into(); } - if allow_auto_bounds && reset_bounds { + if allow_auto_bounds { // Apply bounds modifications. for modification in bounds_modifications { match modification { @@ -978,7 +974,9 @@ impl Plot { } } } else { - bounds_modified = true.into(); + if !reset_bounds { + bounds_modified = true.into(); + } } // Reset bounds to initial bounds if they haven't been modified. From ad805360e34b099ad08f2e397b8f33ed7db5cdf7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 16 Aug 2023 22:41:32 +0200 Subject: [PATCH 07/10] Update doc allow_auto_bounds --- crates/egui/src/widgets/plot/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index f77ae1e5b9d..272b2d65eb5 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -380,6 +380,8 @@ impl Plot { /// Whether to allow auto bounds. Default: `true`. /// If `false`, it set bounds_modified to true to prevent auto adjusting bounds, /// also it check if the user double clicked to reset bounds. If so, set bounds_modified to false. + /// Carreful, bounds can be saved as persisted data so we need to reset egui memory + /// for understanding thoroughly this functionality. pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self From 2617738e2faf57b132831f6b3e71c9b908969baa Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 16 Aug 2023 23:55:38 +0200 Subject: [PATCH 08/10] Update doc allow_auto_bounds if set_plot_bounds --- crates/egui/src/widgets/plot/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 272b2d65eb5..e54db0d0994 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -379,9 +379,17 @@ impl Plot { /// Whether to allow auto bounds. Default: `true`. /// If `false`, it set bounds_modified to true to prevent auto adjusting bounds, - /// also it check if the user double clicked to reset bounds. If so, set bounds_modified to false. - /// Carreful, bounds can be saved as persisted data so we need to reset egui memory - /// for understanding thoroughly this functionality. + /// also it check if the user double clicked to reset bounds. If so, it set bounds_modified to false. + /// + /// It's mainly needed when we start a new plot like when we reset the egui memory and + /// we haven't used it before (pan/zoom) because bounds can be saved as persisted data. + /// + /// + /// Currently, if `allow_auto_bounds(false)` and `plot_ui.set_plot_bounds(PlotBounds)` are used in + /// same time `set_plot_bounds` will be ignored. + /// + /// TODO: Refactor `Plot::allow_auto_bounds` and `Plot::set_plot_bounds` feature to work together. + /// pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self From d8a80d28b66fd6ad8041604734d00a273d23db87 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 17 Aug 2023 08:29:46 +0200 Subject: [PATCH 09/10] Update formating --- crates/egui/src/widgets/plot/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index c990ae43f44..e225ce97ff1 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -378,18 +378,16 @@ impl Plot { } /// Whether to allow auto bounds. Default: `true`. - /// If `false`, it set bounds_modified to true to prevent auto adjusting bounds, - /// also it check if the user double clicked to reset bounds. If so, it set bounds_modified to false. + /// If `false`, it set `bounds_modified` to true to prevent auto adjusting bounds, + /// also it check if the user double clicked to reset bounds. If so, it set `bounds_modified` to false. /// /// It's mainly needed when we start a new plot like when we reset the egui memory and /// we haven't used it before (pan/zoom) because bounds can be saved as persisted data. /// - /// /// Currently, if `allow_auto_bounds(false)` and `plot_ui.set_plot_bounds(PlotBounds)` are used in /// same time `set_plot_bounds` will be ignored. /// /// TODO: Refactor `Plot::allow_auto_bounds` and `Plot::set_plot_bounds` feature to work together. - /// pub fn allow_auto_bounds(mut self, on: bool) -> Self { self.allow_auto_bounds = on; self @@ -993,10 +991,8 @@ impl Plot { } } } - } else { - if !reset_bounds { - bounds_modified = true.into(); - } + } else if !reset_bounds { + bounds_modified = true.into(); } // Reset bounds to initial bounds if they haven't been modified. From f7b5fd6525d56c072cc201872b30101ae693957f Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 17 Aug 2023 09:55:40 +0200 Subject: [PATCH 10/10] update doc allow_auto_bounds --- crates/egui/src/widgets/plot/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index e225ce97ff1..15d3965d3d2 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -381,8 +381,8 @@ impl Plot { /// If `false`, it set `bounds_modified` to true to prevent auto adjusting bounds, /// also it check if the user double clicked to reset bounds. If so, it set `bounds_modified` to false. /// - /// It's mainly needed when we start a new plot like when we reset the egui memory and - /// we haven't used it before (pan/zoom) because bounds can be saved as persisted data. + /// It's needed when a new plot is started, such as when resetting egui memory and pan/zoom that + /// have not been used before, as the limits can be saved as persistent data. /// /// Currently, if `allow_auto_bounds(false)` and `plot_ui.set_plot_bounds(PlotBounds)` are used in /// same time `set_plot_bounds` will be ignored.