From 815319b3f57ec9687e0535b10d51cc02dd393044 Mon Sep 17 00:00:00 2001 From: Stu Leak Date: Thu, 4 Dec 2025 03:39:04 -0500 Subject: [PATCH] Add thumbnail generation and Clear All button to Compare Fixed thumbnails not displaying: - Added preview frame generation to Compare module - Thumbnails now load asynchronously when videos are loaded - Uses capturePreviewFrames() just like Convert module - Thumbnails appear after brief generation delay Added Clear All button: - Positioned to the right of instructions text - Clears both File 1 and File 2 slots - Refreshes view to show empty state - Low importance styling (not highlighted) Layout improvements: - Instructions row now uses Border layout - Clear All button aligned to the right - Clean, accessible button placement Both videos now show thumbnails (240x135) automatically when loaded, providing visual confirmation of loaded content. --- main.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 4d8c6a2..b83f541 100644 --- a/main.go +++ b/main.go @@ -5374,6 +5374,16 @@ func buildCompareView(state *appState) fyne.CanvasObject { instructions.Wrapping = fyne.TextWrapWord instructions.Alignment = fyne.TextAlignCenter + // Clear All button + clearAllBtn := widget.NewButton("Clear All", func() { + state.compareFile1 = nil + state.compareFile2 = nil + state.showCompareView() + }) + clearAllBtn.Importance = widget.LowImportance + + instructionsRow := container.NewBorder(nil, nil, nil, clearAllBtn, instructions) + // File labels file1Label := widget.NewLabel("File 1: Not loaded") file1Label.TextStyle = fyne.TextStyle{Bold: true} @@ -5468,7 +5478,24 @@ func buildCompareView(state *appState) fyne.CanvasObject { // Helper to load thumbnail for a video loadThumbnail := func(src *videoSource, img *canvas.Image) { - if src == nil || len(src.PreviewFrames) == 0 { + if src == nil { + return + } + // Generate preview frames if not already present + if len(src.PreviewFrames) == 0 { + go func() { + if thumb, err := capturePreviewFrames(src.Path, src.Duration); err == nil && len(thumb) > 0 { + src.PreviewFrames = thumb + // Update thumbnail on UI thread + fyne.CurrentApp().Driver().DoFromGoroutine(func() { + thumbImg := canvas.NewImageFromFile(src.PreviewFrames[0]) + if thumbImg.Image != nil { + img.Image = thumbImg.Image + img.Refresh() + } + }, false) + } + }() return } // Load the first preview frame as thumbnail @@ -5659,7 +5686,7 @@ func buildCompareView(state *appState) fyne.CanvasObject { // Main content: instructions at top, then two columns side by side content := container.NewBorder( - container.NewVBox(instructions, widget.NewSeparator()), + container.NewVBox(instructionsRow, widget.NewSeparator()), nil, nil, nil, container.NewGridWithColumns(2, file1Column, file2Column), )