Skip to content

Commit

Permalink
add set_plot_bounds method, giving users the ability to set the plot …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
flxzt and emilk committed Dec 2, 2022
1 parent 3e96929 commit 373692c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/egui/src/widgets/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions crates/egui/src/widgets/plot/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 373692c

Please sign in to comment.