summaryrefslogtreecommitdiff
path: root/image.go
diff options
context:
space:
mode:
authorRandomChars <random@chars.jp>2021-10-10 12:28:54 +0900
committerRandomChars <random@chars.jp>2021-10-10 12:28:54 +0900
commit7dfc1d3e5c0892d72928b8aac7b9b11e2475533d (patch)
tree182882c209094b6565c781853cdde2f637583702 /image.go
parenteb945bcb7ea2f1291713c7947d86c018f3d5b101 (diff)
group view in image view, image set callback, rename giant lock variable
Diffstat (limited to 'image.go')
-rw-r--r--image.go68
1 files changed, 64 insertions, 4 deletions
diff --git a/image.go b/image.go
index 7fc47d1..d3867bb 100644
--- a/image.go
+++ b/image.go
@@ -24,6 +24,8 @@ import (
"time"
)
+var imageSwitchCallbacks []func()
+
var imageMenu = &fyne.MenuItem{
ChildMenu: &fyne.Menu{
Label: "Image",
@@ -433,8 +435,8 @@ func setPage(page int) {
if gallery, err := makePageView(page); err != nil {
dialog.ShowError(err, window)
} else {
- mainWindowContentMutex.Lock()
- defer mainWindowContentMutex.Unlock()
+ giantLock.Lock()
+ defer giantLock.Unlock()
setContent(gallery)
inPageView = true
currentPage = page
@@ -758,6 +760,46 @@ func makeImageView(image store.Image) (*fyne.Container, error) {
r.Disable()
}
+ var (
+ groupView *container.Scroll
+ groupViewBox = container.NewGridWrap(fyne.Size{Width: 128, Height: 128})
+ )
+ groupView = container.NewHScroll(groupViewBox)
+ for _, e := range group {
+ eImg := &canvas.Image{
+ FillMode: canvas.ImageFillContain,
+ ScaleMode: canvas.ImageScaleFastest,
+ }
+ if res, err := e.resource(true); err != nil {
+ return nil, err
+ } else {
+ if e.image.Snowflake == entry.image.Snowflake {
+ if i, err := makeImageBorder(res.Content(), color.RGBA{R: 0x00, G: 0x00, B: 0xff, A: 0xff}, 0.03); err != nil {
+ return nil, err
+ } else {
+ eImg.Image = i
+ }
+ } else {
+ eImg.Resource = res
+ }
+ }
+
+ groupViewBox.Add(newImageButton(eImg, e.image))
+ log.Printf("Added image %s to group view of %s.", e.image.Snowflake, entry.image.Snowflake)
+ }
+ groupViewDiag := dialog.NewCustom("Image group", "Close", groupView, window)
+ groupViewDiag.Resize(fyne.Size{Width: window.Content().Size().Width - 16})
+ groupView.SetMinSize(fyne.Size{Height: 128})
+
+ var groupViewToggle *widget.Button
+ groupViewToggle = widget.NewButton("Show group", func() {
+ groupViewDiag.Show()
+ })
+ ops.Add(groupViewToggle)
+ registerImageSwitchCallback(func() {
+ groupViewDiag.Hide()
+ })
+
border = container.NewBorder(ops, container.NewBorder(nil, nil, b, r), nil, nil,
container.NewBorder(widget.NewSeparator(), nil, nil, nil, lf))
}
@@ -767,15 +809,33 @@ func makeImageView(image store.Image) (*fyne.Container, error) {
func setImage(image store.Image) {
defer loading("Loading", "Loading image...")()
+ func() {
+ giantLock.Lock()
+ defer giantLock.Unlock()
+
+ // Fire callbacks
+ for i, f := range imageSwitchCallbacks {
+ log.Printf("Firing image switch callback %v.", i)
+ f()
+ }
+ imageSwitchCallbacks = []func(){}
+ }()
+
if img, err := makeImageView(image); err != nil {
dialog.ShowError(err, window)
} else {
- mainWindowContentMutex.Lock()
- defer mainWindowContentMutex.Unlock()
setContent(img)
}
}
+func registerImageSwitchCallback(f func()) {
+ giantLock.Lock()
+ defer giantLock.Unlock()
+
+ log.Printf("Registering image switch callback.")
+ imageSwitchCallbacks = append(imageSwitchCallbacks, f)
+}
+
func addImage(path string, reader io.ReadCloser) {
s := time.Now()
if img, err := remote.ImageAdd(reader); err != nil {