diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-21 16:34:16 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-21 16:34:16 +0300 |
| commit | 18390dc18f397207e6eb8e67991dc7078b5e7515 (patch) | |
| tree | 75a5b4862346adebe6616ef157c94b9b00cac6fb /internal/gui/widgets.go | |
| parent | f3e301168ad742a556b336761e28f739eb1d7143 (diff) | |
more on this
Diffstat (limited to 'internal/gui/widgets.go')
| -rw-r--r-- | internal/gui/widgets.go | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/internal/gui/widgets.go b/internal/gui/widgets.go index eb9818c..6ad428c 100644 --- a/internal/gui/widgets.go +++ b/internal/gui/widgets.go @@ -18,27 +18,27 @@ import ( // ImageDisplay is a custom widget for displaying images type ImageDisplay struct { widget.BaseWidget - - container *fyne.Container - imageCanvas *canvas.Image - imageLabel *widget.Label - - currentImage string + + container *fyne.Container + imageCanvas *canvas.Image + imageLabel *widget.Label + + currentImage string } // NewImageDisplay creates a new image display widget func NewImageDisplay() *ImageDisplay { d := &ImageDisplay{} - + // Create image canvas d.imageCanvas = canvas.NewImageFromResource(nil) d.imageCanvas.FillMode = canvas.ImageFillContain - d.imageCanvas.SetMinSize(fyne.NewSize(200, 150)) // Half the size - + d.imageCanvas.SetMinSize(fyne.NewSize(200, 150)) // Half the size + // Create label d.imageLabel = widget.NewLabel("No image") d.imageLabel.Alignment = fyne.TextAlignCenter - + // Create main container - no navigation buttons here d.container = container.NewBorder( nil, @@ -46,7 +46,7 @@ func NewImageDisplay() *ImageDisplay { nil, nil, d.imageCanvas, ) - + d.ExtendBaseWidget(d) return d } @@ -62,9 +62,9 @@ func (d *ImageDisplay) SetImage(imagePath string) { d.Clear() return } - + d.currentImage = imagePath - + // Load image from file file, err := os.Open(imagePath) if err != nil { @@ -72,17 +72,17 @@ func (d *ImageDisplay) SetImage(imagePath string) { return } defer file.Close() - + img, _, err := image.Decode(file) if err != nil { d.imageLabel.SetText(fmt.Sprintf("Error decoding image: %v", err)) return } - + // Update canvas d.imageCanvas.Image = img d.imageCanvas.Refresh() - + // Update label d.imageLabel.SetText(filepath.Base(imagePath)) } @@ -104,6 +104,13 @@ func (d *ImageDisplay) Clear() { d.imageLabel.SetText("No image") } +// SetGenerating shows a generating status +func (d *ImageDisplay) SetGenerating() { + d.currentImage = "" + d.imageCanvas.Image = nil + d.imageCanvas.Refresh() + d.imageLabel.SetText("Generating...") +} // ResourceFromPath creates a Fyne resource from a file path func ResourceFromPath(path string) (fyne.Resource, error) { @@ -112,11 +119,11 @@ func ResourceFromPath(path string) (fyne.Resource, error) { return nil, err } defer file.Close() - + data, err := os.ReadFile(path) if err != nil { return nil, err } - + return fyne.NewStaticResource(filepath.Base(path), data), nil -}
\ No newline at end of file +} |
