egui_plot: use `f64` for translate (#4637)

<!--
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
https://github.com/emilk/egui/issues/3462



* Maybe related to https://github.com/emilk/egui/issues/3656
This commit is contained in:
n4n5 2024-06-18 22:55:08 +02:00 committed by GitHub
parent 413843dd7c
commit 44d7aab53d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 11 deletions

View File

@ -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();
}
@ -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);
}
@ -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();
}
}

View File

@ -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]
@ -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.