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.
This commit is contained in:
Stu Leak 2025-12-04 03:39:04 -05:00
parent 653e6721da
commit 815319b3f5

31
main.go
View File

@ -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),
)