Skip to content

Commit 8b03e5e

Browse files
authored
Allow Plot::link_cursor to accept impl Into<Vec2b> (#66)
Updates the `link` argument to the `impl Into<Vec2b>` to be consistent with `link_axis`. This makes it slightly cleaner to use. <!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui_plot/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo f or a new example. * Do NOT open PR:s from your `master` or `main` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! We will review your PR, but our time is limited! --> * [x] I have followed the instructions in the PR template
1 parent d318538 commit 8b03e5e

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

egui_plot/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ impl<'a> Plot<'a> {
520520
///
521521
/// This is enabled by default.
522522
#[inline]
523-
pub fn auto_bounds(mut self, auto_bounds: Vec2b) -> Self {
524-
self.default_auto_bounds = auto_bounds;
523+
pub fn auto_bounds(mut self, auto_bounds: impl Into<Vec2b>) -> Self {
524+
self.default_auto_bounds = auto_bounds.into();
525525
self
526526
}
527527

@@ -587,8 +587,8 @@ impl<'a> Plot<'a> {
587587
/// Add this plot to a cursor link group so that this plot will share the cursor position with other plots
588588
/// in the same group. A plot cannot belong to more than one cursor group.
589589
#[inline]
590-
pub fn link_cursor(mut self, group_id: impl Into<Id>, link: Vec2b) -> Self {
591-
self.linked_cursors = Some((group_id.into(), link));
590+
pub fn link_cursor(mut self, group_id: impl Into<Id>, link: impl Into<Vec2b>) -> Self {
591+
self.linked_cursors = Some((group_id.into(), link.into()));
592592
self
593593
}
594594

@@ -1262,7 +1262,7 @@ impl<'a> Plot<'a> {
12621262
/// Returns the rect left after adding axes.
12631263
fn axis_widgets<'a>(
12641264
mem: Option<&PlotMemory>,
1265-
show_axes: Vec2b,
1265+
show_axes: impl Into<Vec2b>,
12661266
complete_rect: Rect,
12671267
[x_axes, y_axes]: [&'a [AxisHints<'a>]; 2],
12681268
) -> ([Vec<AxisWidget<'a>>; 2], Rect) {
@@ -1288,6 +1288,7 @@ fn axis_widgets<'a>(
12881288
// | X-axis 1 | |
12891289
// + +--------------------+---+
12901290
//
1291+
let show_axes = show_axes.into();
12911292

12921293
let mut x_axis_widgets = Vec::<AxisWidget<'_>>::new();
12931294
let mut y_axis_widgets = Vec::<AxisWidget<'_>>::new();

egui_plot/src/plot_ui.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ impl PlotUi {
5656
}
5757

5858
/// Set the auto-bounds mode for the plot axes.
59-
pub fn set_auto_bounds(&mut self, auto_bounds: Vec2b) {
59+
pub fn set_auto_bounds(&mut self, auto_bounds: impl Into<Vec2b>) {
6060
self.bounds_modifications
61-
.push(BoundsModification::AutoBounds(auto_bounds));
61+
.push(BoundsModification::AutoBounds(auto_bounds.into()));
6262
}
6363

6464
/// Can be used to check if the plot was hovered or clicked.

egui_plot/src/transform.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,12 @@ pub struct PlotTransform {
279279
}
280280

281281
impl PlotTransform {
282-
pub fn new(frame: Rect, bounds: PlotBounds, center_axis: Vec2b) -> Self {
282+
pub fn new(frame: Rect, bounds: PlotBounds, center_axis: impl Into<Vec2b>) -> Self {
283283
debug_assert!(
284284
0.0 <= frame.width() && 0.0 <= frame.height(),
285285
"Bad plot frame: {frame:?}"
286286
);
287+
let center_axis = center_axis.into();
287288

288289
// Since the current Y bounds an affect the final X bounds and vice versa, we need to keep
289290
// the original version of the `bounds` before we start modifying it.

0 commit comments

Comments
 (0)