Skip to content

Commit 69d5e03

Browse files
flxztemilk
authored andcommitted
add set_plot_bounds method, giving users the ability to set the plot bounds themselves. (emilk#2320)
* add set_plot_bounds method * call it from_min_max for consistency with Rect Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
1 parent b85fe0d commit 69d5e03

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

crates/egui/src/widgets/plot/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ impl PlotUi {
12691269
*self.last_screen_transform.bounds()
12701270
}
12711271

1272+
/// Set the plot bounds. Can be useful for implementing alternative plot navigation methods.
1273+
pub fn set_plot_bounds(&mut self, plot_bounds: PlotBounds) {
1274+
self.last_screen_transform.set_bounds(plot_bounds);
1275+
}
1276+
12721277
/// Move the plot bounds. Can be useful for implementing alternative plot navigation methods.
12731278
pub fn translate_bounds(&mut self, delta_pos: Vec2) {
12741279
self.last_screen_transform.translate_bounds(delta_pos);

crates/egui/src/widgets/plot/transform.rs

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ impl PlotBounds {
1818
max: [-f64::INFINITY; 2],
1919
};
2020

21+
pub fn from_min_max(min: [f64; 2], max: [f64; 2]) -> Self {
22+
Self { min, max }
23+
}
24+
2125
pub fn min(&self) -> [f64; 2] {
2226
self.min
2327
}

0 commit comments

Comments
 (0)