From 8b03e5e99bd6f9f12bf54153e657e68f73bbea98 Mon Sep 17 00:00:00 2001 From: James Tomlinson Date: Wed, 29 Jan 2025 10:43:16 +0000 Subject: [PATCH] Allow Plot::link_cursor to accept `impl Into` (#66) Updates the `link` argument to the `impl Into` to be consistent with `link_axis`. This makes it slightly cleaner to use. * [x] I have followed the instructions in the PR template --- egui_plot/src/lib.rs | 11 ++++++----- egui_plot/src/plot_ui.rs | 4 ++-- egui_plot/src/transform.rs | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/egui_plot/src/lib.rs b/egui_plot/src/lib.rs index d5b0fe5..31ad57b 100644 --- a/egui_plot/src/lib.rs +++ b/egui_plot/src/lib.rs @@ -520,8 +520,8 @@ impl<'a> Plot<'a> { /// /// This is enabled by default. #[inline] - pub fn auto_bounds(mut self, auto_bounds: Vec2b) -> Self { - self.default_auto_bounds = auto_bounds; + pub fn auto_bounds(mut self, auto_bounds: impl Into) -> Self { + self.default_auto_bounds = auto_bounds.into(); self } @@ -587,8 +587,8 @@ impl<'a> Plot<'a> { /// Add this plot to a cursor link group so that this plot will share the cursor position with other plots /// in the same group. A plot cannot belong to more than one cursor group. #[inline] - pub fn link_cursor(mut self, group_id: impl Into, link: Vec2b) -> Self { - self.linked_cursors = Some((group_id.into(), link)); + pub fn link_cursor(mut self, group_id: impl Into, link: impl Into) -> Self { + self.linked_cursors = Some((group_id.into(), link.into())); self } @@ -1262,7 +1262,7 @@ impl<'a> Plot<'a> { /// Returns the rect left after adding axes. fn axis_widgets<'a>( mem: Option<&PlotMemory>, - show_axes: Vec2b, + show_axes: impl Into, complete_rect: Rect, [x_axes, y_axes]: [&'a [AxisHints<'a>]; 2], ) -> ([Vec>; 2], Rect) { @@ -1288,6 +1288,7 @@ fn axis_widgets<'a>( // | X-axis 1 | | // + +--------------------+---+ // + let show_axes = show_axes.into(); let mut x_axis_widgets = Vec::>::new(); let mut y_axis_widgets = Vec::>::new(); diff --git a/egui_plot/src/plot_ui.rs b/egui_plot/src/plot_ui.rs index fdd38c3..ff20ac1 100644 --- a/egui_plot/src/plot_ui.rs +++ b/egui_plot/src/plot_ui.rs @@ -56,9 +56,9 @@ impl PlotUi { } /// Set the auto-bounds mode for the plot axes. - pub fn set_auto_bounds(&mut self, auto_bounds: Vec2b) { + pub fn set_auto_bounds(&mut self, auto_bounds: impl Into) { self.bounds_modifications - .push(BoundsModification::AutoBounds(auto_bounds)); + .push(BoundsModification::AutoBounds(auto_bounds.into())); } /// Can be used to check if the plot was hovered or clicked. diff --git a/egui_plot/src/transform.rs b/egui_plot/src/transform.rs index d75829b..7f2b2dd 100644 --- a/egui_plot/src/transform.rs +++ b/egui_plot/src/transform.rs @@ -279,11 +279,12 @@ pub struct PlotTransform { } impl PlotTransform { - pub fn new(frame: Rect, bounds: PlotBounds, center_axis: Vec2b) -> Self { + pub fn new(frame: Rect, bounds: PlotBounds, center_axis: impl Into) -> Self { debug_assert!( 0.0 <= frame.width() && 0.0 <= frame.height(), "Bad plot frame: {frame:?}" ); + let center_axis = center_axis.into(); // Since the current Y bounds an affect the final X bounds and vice versa, we need to keep // the original version of the `bounds` before we start modifying it.