Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui_plot: use f64 for translate #4637

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading