summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-16 21:52:50 -0400
committerPietro Gagliardi <[email protected]>2014-03-16 21:52:50 -0400
commit7c3647712b38e08a8f0daa970ab1a2b0857df8b0 (patch)
tree570bec783c588d9a899c87289339a1eb30a9017b
parentae554f10c3b652a3dfe765fd63107237e9aafa28 (diff)
Updated the test program to the new AreaHandler interface. The deadlock still happens... just not so easily... so it's elsewhere...
-rw-r--r--areasnafu.md17
-rw-r--r--test/main.go34
2 files changed, 38 insertions, 13 deletions
diff --git a/areasnafu.md b/areasnafu.md
index eef08c6..807f496 100644
--- a/areasnafu.md
+++ b/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.
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...
diff --git a/test/main.go b/test/main.go
index d8b69c7..e032aca 100644
--- a/test/main.go
+++ b/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")
+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")
func areaTest() {
/*
@@ -136,7 +154,9 @@ func areaTest() {
img := image.NewNRGBA(ximg.Bounds())
draw.Draw(img, img.Rect, ximg, image.ZP, draw.Over)
w := NewWindow("Area Test", 100, 100)
- a := NewArea()
+ a := NewArea(&areaHandler{
+ img: img,
+ })
timedisp := NewLabel("")
timechan := time.Tick(time.Second)
layout := NewVerticalStack(a,
@@ -152,18 +172,6 @@ func areaTest() {
return
case t := <-timechan:
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)
}
}
}