From f3633534e76874bc560a2f18da4270c3fa69bca1 Mon Sep 17 00:00:00 2001 From: Felix Zwettler Date: Tue, 22 Nov 2022 15:05:23 +0100 Subject: [PATCH] add set_plot_bounds method, giving users the ability to set the plot bounds themselves. (#2320) * add set_plot_bounds method * call it from_min_max for consistency with Rect Co-authored-by: Emil Ernerfeldt --- crates/egui/src/widgets/plot/mod.rs | 5 +++++ crates/egui/src/widgets/plot/transform.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 8367d9ab..a31b1dc7 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -1040,6 +1040,11 @@ impl PlotUi { *self.last_screen_transform.bounds() } + /// Set the plot bounds. Can be useful for implementing alternative plot navigation methods. + pub fn set_plot_bounds(&mut self, plot_bounds: PlotBounds) { + self.last_screen_transform.set_bounds(plot_bounds); + } + /// Move the plot bounds. Can be useful for implementing alternative plot navigation methods. pub fn translate_bounds(&mut self, delta_pos: Vec2) { self.last_screen_transform.translate_bounds(delta_pos); diff --git a/crates/egui/src/widgets/plot/transform.rs b/crates/egui/src/widgets/plot/transform.rs index 6abfe261..51c63e89 100644 --- a/crates/egui/src/widgets/plot/transform.rs +++ b/crates/egui/src/widgets/plot/transform.rs @@ -18,6 +18,10 @@ impl PlotBounds { max: [-f64::INFINITY; 2], }; + pub fn from_min_max(min: [f64; 2], max: [f64; 2]) -> Self { + Self { min, max } + } + pub fn min(&self) -> [f64; 2] { self.min }