From 1d987a341a80dcea4eef02506f6bb77a852f5840 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 17 Sep 2025 01:56:16 +0200 Subject: [PATCH] Refactor visibility calculations in VideoEditor to ensure proper cropping bounds This commit updates the visibility width and height calculations in the VideoEditor class to use the minimum of the new dimensions and the window dimensions when cropping due to zoom. This change enhances the accuracy of the displayed area during zoom operations, ensuring that the canvas scaling is correctly applied and improving the overall user experience in video editing. --- croppa/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index 5fad58b..64f1172 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -1328,10 +1328,11 @@ class VideoEditor: offy = 0 zx = rx2 * self.zoom_factor - offx zy = ry2 * self.zoom_factor - offy - visible_w = new_w if not cropped_due_to_zoom else self.window_width - visible_h = new_h if not cropped_due_to_zoom else self.window_height + visible_w = new_w if not cropped_due_to_zoom else min(new_w, self.window_width) + visible_h = new_h if not cropped_due_to_zoom else min(new_h, self.window_height) available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT) - scale_canvas = min(self.window_width / max(1, visible_w), available_height / max(1, visible_h)) + scale_raw = min(self.window_width / max(1, visible_w), available_height / max(1, visible_h)) + scale_canvas = scale_raw if scale_raw < 1.0 else 1.0 final_w = int(visible_w * scale_canvas) final_h = int(visible_h * scale_canvas) start_x_canvas = (self.window_width - final_w) // 2