Improve thumbnail handling in ProjectView: add bounds checking for thumbnail placement on canvas and adjust resizing logic to prevent exceeding canvas dimensions. Update thumbnail size constraints for resizing operations to ensure minimum size limits.
This commit is contained in:
@@ -190,7 +190,19 @@ class ProjectView:
|
||||
thumbnail = self.get_thumbnail_for_video(video_path)
|
||||
# Resize thumbnail to fit
|
||||
resized_thumbnail = cv2.resize(thumbnail, (thumbnail_width, thumbnail_height))
|
||||
canvas[y:y+thumbnail_height, x:x+thumbnail_width] = resized_thumbnail
|
||||
|
||||
# Ensure thumbnail doesn't exceed canvas bounds
|
||||
end_y = min(y + thumbnail_height, self.window_height)
|
||||
end_x = min(x + thumbnail_width, self.window_width)
|
||||
actual_height = end_y - y
|
||||
actual_width = end_x - x
|
||||
|
||||
if actual_height > 0 and actual_width > 0:
|
||||
# Resize thumbnail to fit within bounds if necessary
|
||||
if actual_height != thumbnail_height or actual_width != thumbnail_width:
|
||||
resized_thumbnail = cv2.resize(thumbnail, (actual_width, actual_height))
|
||||
|
||||
canvas[y:end_y, x:end_x] = resized_thumbnail
|
||||
|
||||
# Draw progress bar
|
||||
progress_y = y + thumbnail_height + 5
|
||||
@@ -286,15 +298,15 @@ class ProjectView:
|
||||
self.selected_index += 1
|
||||
self._update_scroll()
|
||||
elif key == ord('q') or key == ord('Q'): # Q - Make thumbnails LARGER
|
||||
# Increase thumbnail size (maximum 300x225)
|
||||
new_width = min(300, self.THUMBNAIL_SIZE[0] + 20)
|
||||
# Increase thumbnail size (no maximum limit)
|
||||
new_width = self.THUMBNAIL_SIZE[0] + 20
|
||||
new_height = int(new_width * self.THUMBNAIL_SIZE[1] / self.THUMBNAIL_SIZE[0])
|
||||
self.THUMBNAIL_SIZE = (new_width, new_height)
|
||||
self.ITEM_HEIGHT = self.THUMBNAIL_SIZE[1] + self.PROGRESS_BAR_HEIGHT + self.TEXT_HEIGHT + self.THUMBNAIL_MARGIN
|
||||
print(f"Thumbnail size: {self.THUMBNAIL_SIZE}")
|
||||
elif key == ord('y') or key == ord('Y'): # Y - Make thumbnails SMALLER
|
||||
# Decrease thumbnail size (minimum 100x75)
|
||||
new_width = max(100, self.THUMBNAIL_SIZE[0] - 20)
|
||||
# Decrease thumbnail size (minimum 20x15 to prevent division by zero)
|
||||
new_width = max(20, self.THUMBNAIL_SIZE[0] - 20)
|
||||
new_height = int(new_width * self.THUMBNAIL_SIZE[1] / self.THUMBNAIL_SIZE[0])
|
||||
self.THUMBNAIL_SIZE = (new_width, new_height)
|
||||
self.ITEM_HEIGHT = self.THUMBNAIL_SIZE[1] + self.PROGRESS_BAR_HEIGHT + self.TEXT_HEIGHT + self.THUMBNAIL_MARGIN
|
||||
|
Reference in New Issue
Block a user