summaryrefslogtreecommitdiff
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
parenteb945bcb7ea2f1291713c7947d86c018f3d5b101 (diff)
group view in image view, image set callback, rename giant lock variable
-rw-r--r--image.go68
-rw-r--r--main.go16
-rw-r--r--remote.go6
3 files changed, 75 insertions, 15 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 {
diff --git a/main.go b/main.go
index b23eb88..93d190d 100644
--- a/main.go
+++ b/main.go
@@ -12,12 +12,12 @@ import (
//go:generate sh gen.sh
var (
- remote *client.Remote
- application = app.NewWithID("jp.chars.rand.imageboard")
- window = application.NewWindow("Image Board")
- mainWindowContentMutex = sync.Mutex{}
- menu *fyne.MainMenu
- inPageView = false
+ remote *client.Remote
+ application = app.NewWithID("jp.chars.rand.imageboard")
+ window = application.NewWindow("Image Board")
+ giantLock = sync.Mutex{}
+ menu *fyne.MainMenu
+ inPageView = false
)
func init() {
@@ -55,8 +55,8 @@ func main() {
}
func mainMenuRefresh() {
- mainWindowContentMutex.Lock()
- defer mainWindowContentMutex.Unlock()
+ giantLock.Lock()
+ defer giantLock.Unlock()
window.SetMainMenu(menu)
}
diff --git a/remote.go b/remote.go
index a96d288..ab8d3d8 100644
--- a/remote.go
+++ b/remote.go
@@ -28,11 +28,11 @@ func newRemote() error {
return nil
}
- mainWindowContentMutex.Lock()
+ giantLock.Lock()
defer loading("Connecting", "Waiting for server...")()
log.Printf("Connecting to %s...", url)
if r, err := client.New(url); err != nil {
- mainWindowContentMutex.Unlock()
+ giantLock.Unlock()
return err
} else {
dropImageCache()
@@ -42,7 +42,7 @@ func newRemote() error {
url, r.SingleUser(), r.Revision, r.Compat, r.Register)
go func() {
- mainWindowContentMutex.Unlock()
+ giantLock.Unlock()
// Attempt initializing user
initUser()
if this.ID == "" && remote.Private() {