Skip to content

Commit

Permalink
Allow Plot::link_cursor to accept impl Into<Vec2b> (#66)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jetuk authored Jan 29, 2025
1 parent d318538 commit 8b03e5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec2b>) -> Self {
self.default_auto_bounds = auto_bounds.into();
self
}

Expand Down Expand Up @@ -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<Id>, link: Vec2b) -> Self {
self.linked_cursors = Some((group_id.into(), link));
pub fn link_cursor(mut self, group_id: impl Into<Id>, link: impl Into<Vec2b>) -> Self {
self.linked_cursors = Some((group_id.into(), link.into()));
self
}

Expand Down Expand Up @@ -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<Vec2b>,
complete_rect: Rect,
[x_axes, y_axes]: [&'a [AxisHints<'a>]; 2],
) -> ([Vec<AxisWidget<'a>>; 2], Rect) {
Expand All @@ -1288,6 +1288,7 @@ fn axis_widgets<'a>(
// | X-axis 1 | |
// + +--------------------+---+
//
let show_axes = show_axes.into();

let mut x_axis_widgets = Vec::<AxisWidget<'_>>::new();
let mut y_axis_widgets = Vec::<AxisWidget<'_>>::new();
Expand Down
4 changes: 2 additions & 2 deletions egui_plot/src/plot_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec2b>) {
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.
Expand Down
3 changes: 2 additions & 1 deletion egui_plot/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec2b>) -> 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.
Expand Down

0 comments on commit 8b03e5e

Please sign in to comment.