Updated the test program to the new AreaHandler interface. The deadlock still happens... just not so easily... so it's elsewhere...
This commit is contained in:
parent
ae554f10c3
commit
7c3647712b
17
areasnafu.md
17
areasnafu.md
|
@ -86,3 +86,20 @@ type Area interface {
|
||||||
but I don't know how I'm going to handle the Control embed, as that uses unexported methods. The unexported methods are needed to do the acutal OS-dependent work, and I figured exporting these to the public would result in misuse.
|
but I don't know how I'm going to handle the Control embed, as that uses unexported methods. The unexported methods are needed to do the acutal OS-dependent work, and I figured exporting these to the public would result in misuse.
|
||||||
|
|
||||||
So I'm stuck. Unless there's a way I can get either attempt working, or I can figure out some other Go-like approach... I personally felt weird about Attempt 2, but go.wde does it. I personally don't want to use a delegate type that provides the event functions and have Area require one, as that sounds both not-Go-like and more OOP-like than I want this to be. I already silently reject requests for the callback approach as it is (I should respond to them)...
|
So I'm stuck. Unless there's a way I can get either attempt working, or I can figure out some other Go-like approach... I personally felt weird about Attempt 2, but go.wde does it. I personally don't want to use a delegate type that provides the event functions and have Area require one, as that sounds both not-Go-like and more OOP-like than I want this to be. I already silently reject requests for the callback approach as it is (I should respond to them)...
|
||||||
|
|
||||||
|
## Attempt 3: Delegates
|
||||||
|
Well I did it anyway
|
||||||
|
```
|
||||||
|
type Area {
|
||||||
|
handler AreaHandler
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
type AreaHandler interface {
|
||||||
|
Paint(image.Rectangle) *image.NRGBA
|
||||||
|
Mouse(MouseEvent)
|
||||||
|
}
|
||||||
|
func NewArea(handler AreaHandler) *Area {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
This seems to have fixed the deadlocks!... but I can still deadlock elsewhere, so something /else/ is wrong, sigh...
|
||||||
|
|
34
test/main.go
34
test/main.go
|
@ -116,6 +116,24 @@ func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
|
||||||
|
|
||||||
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
|
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
|
||||||
|
|
||||||
|
type areaHandler struct {
|
||||||
|
img *image.NRGBA
|
||||||
|
}
|
||||||
|
func (a *areaHandler) Paint(rect image.Rectangle) *image.NRGBA {
|
||||||
|
fmt.Println(rect)
|
||||||
|
/*
|
||||||
|
req.Out <- img[i].SubImage(req.Rect).(*image.NRGBA)
|
||||||
|
if lastrect != req.Rect {
|
||||||
|
lastrect = req.Rect
|
||||||
|
i = 1 - i
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return a.img.SubImage(rect).(*image.NRGBA)
|
||||||
|
}
|
||||||
|
func (a *areaHandler) Mouse(e MouseEvent) {
|
||||||
|
fmt.Printf("%#v\n", e)
|
||||||
|
}
|
||||||
|
|
||||||
var doArea = flag.Bool("area", false, "run area test instead")
|
var doArea = flag.Bool("area", false, "run area test instead")
|
||||||
func areaTest() {
|
func areaTest() {
|
||||||
/*
|
/*
|
||||||
|
@ -136,7 +154,9 @@ func areaTest() {
|
||||||
img := image.NewNRGBA(ximg.Bounds())
|
img := image.NewNRGBA(ximg.Bounds())
|
||||||
draw.Draw(img, img.Rect, ximg, image.ZP, draw.Over)
|
draw.Draw(img, img.Rect, ximg, image.ZP, draw.Over)
|
||||||
w := NewWindow("Area Test", 100, 100)
|
w := NewWindow("Area Test", 100, 100)
|
||||||
a := NewArea()
|
a := NewArea(&areaHandler{
|
||||||
|
img: img,
|
||||||
|
})
|
||||||
timedisp := NewLabel("")
|
timedisp := NewLabel("")
|
||||||
timechan := time.Tick(time.Second)
|
timechan := time.Tick(time.Second)
|
||||||
layout := NewVerticalStack(a,
|
layout := NewVerticalStack(a,
|
||||||
|
@ -152,18 +172,6 @@ func areaTest() {
|
||||||
return
|
return
|
||||||
case t := <-timechan:
|
case t := <-timechan:
|
||||||
timedisp.SetText(t.String())
|
timedisp.SetText(t.String())
|
||||||
case req := <-a.Paint:
|
|
||||||
fmt.Println(req)
|
|
||||||
/*
|
|
||||||
req.Out <- img[i].SubImage(req.Rect).(*image.NRGBA)
|
|
||||||
if lastrect != req.Rect {
|
|
||||||
lastrect = req.Rect
|
|
||||||
i = 1 - i
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
req.Out <- img.SubImage(req.Rect).(*image.NRGBA)
|
|
||||||
case e := <-a.Mouse:
|
|
||||||
fmt.Printf("%#v\n", e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue