Skip to content

Commit

Permalink
egui_plot: use f64 for translate (#4637)
Browse files Browse the repository at this point in the history
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/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 for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to 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! I will review your PR, but my time is limited!
-->

Can fix translating with high zoom out
#3462



* Maybe related to #3656
  • Loading branch information
Its-Just-Nans authored Jun 18, 2024
1 parent 413843d commit 44d7aab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions crates/egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ impl<'a> Plot<'a> {
mem.auto_bounds = false.into();
}
BoundsModification::Translate(delta) => {
let delta = (delta.x as f64, delta.y as f64);
bounds.translate(delta);
mem.auto_bounds = false.into();
}
Expand Down Expand Up @@ -1034,7 +1035,8 @@ impl<'a> Plot<'a> {
if !allow_drag.y {
delta.y = 0.0;
}
mem.transform.translate_bounds(delta);
mem.transform
.translate_bounds((delta.x as f64, delta.y as f64));
mem.auto_bounds = mem.auto_bounds.and(!allow_drag);
}

Expand Down Expand Up @@ -1123,7 +1125,8 @@ impl<'a> Plot<'a> {
scroll_delta.y = 0.0;
}
if scroll_delta != Vec2::ZERO {
mem.transform.translate_bounds(-scroll_delta);
mem.transform
.translate_bounds((-scroll_delta.x as f64, -scroll_delta.y as f64));
mem.auto_bounds = false.into();
}
}
Expand Down
18 changes: 9 additions & 9 deletions crates/egui_plot/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl PlotBounds {
}

#[inline]
pub fn translate(&mut self, delta: Vec2) {
self.translate_x(delta.x as f64);
self.translate_y(delta.y as f64);
pub fn translate(&mut self, delta: (f64, f64)) {
self.translate_x(delta.0);
self.translate_y(delta.1);
}

#[inline]
Expand Down Expand Up @@ -321,16 +321,16 @@ impl PlotTransform {
self.bounds = bounds;
}

pub fn translate_bounds(&mut self, mut delta_pos: Vec2) {
pub fn translate_bounds(&mut self, mut delta_pos: (f64, f64)) {
if self.x_centered {
delta_pos.x = 0.;
delta_pos.0 = 0.;
}
if self.y_centered {
delta_pos.y = 0.;
delta_pos.1 = 0.;
}
delta_pos.x *= self.dvalue_dpos()[0] as f32;
delta_pos.y *= self.dvalue_dpos()[1] as f32;
self.bounds.translate(delta_pos);
delta_pos.0 *= self.dvalue_dpos()[0];
delta_pos.1 *= self.dvalue_dpos()[1];
self.bounds.translate((delta_pos.0, delta_pos.1));
}

/// Zoom by a relative factor with the given screen position as center.
Expand Down

0 comments on commit 44d7aab

Please sign in to comment.