Skip to content

Commit

Permalink
Rescale the image on resize. Solves #8
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpyLionnn committed Oct 22, 2023
1 parent 7646ce1 commit b37d376
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pan_zoom_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ impl PanZoomImage {
let mouse_pos = ui.input(|input| input.pointer.latest_pos().unwrap_or(egui::pos2(0.0, 0.0))).to_vec2();

let (rect, res) = ui.allocate_at_least(ui.available_size(), Sense::drag());
let rect_change = self.last_rect.max - rect.max;
// changing the scale when the window resizes
if rect_change.x > rect_change.y {
self.scale -= (rect_change.x / rect.width()) * self.scale;
}
else {
self.scale -= (rect_change.y / rect.height()) * self.scale;
}
self.last_rect = rect;
// them min scale that the image can fit on the screen
self.min_scale = self.calc_fit_scale(rect).min(1.0);
Expand Down

0 comments on commit b37d376

Please sign in to comment.