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 <emil.ernerfeldt@gmail.com>
This commit is contained in:
Felix Zwettler 2022-11-22 15:05:23 +01:00 committed by GitHub
parent bde47c9957
commit f3633534e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -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);

View file

@ -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
}