Fixed more conversion kinks. Now for a major change...

This commit is contained in:
Pietro Gagliardi 2014-07-19 10:07:42 -04:00
parent 32061353a1
commit e73e7ab733
4 changed files with 18 additions and 18 deletions

View File

@ -25,6 +25,6 @@ type Button interface {
}
// NewButton creates a new Button with the given label text.
func NewButton(text string) {
func NewButton(text string) *button {
return newButton(text)
}

View File

@ -47,7 +47,6 @@ type button struct {
var buttonclass = toUTF16("BUTTON")
func newButton(text string) *button {
op: func() {
w := newWidget(buttonclass,
C.BS_PUSHBUTTON | C.WS_TABSTOP,
0)
@ -70,7 +69,7 @@ func (b *button) Text() string {
}
func (b *button) SetText(text string) {
return b.settext(text)
b.settext(text)
}
//export buttonClicked

View File

@ -5,6 +5,7 @@ package ui
import (
"runtime"
"sync"
"unsafe"
)
// Go initializes package ui.
@ -42,7 +43,7 @@ func Stop() {
type event struct {
// All events internally return bool; those that don't will be wrapped around to return a dummy value.
do func(c Doer) bool
do func() bool
lock sync.Mutex
}
@ -50,31 +51,31 @@ type event struct {
func newEvent() *event {
return &event{
do: func(c Doer) bool {
do: func() bool {
return false
},
}
}
func (e *event) set(f func(Doer)) {
func (e *event) set(f func()) {
e.lock.Lock()
defer e.lock.Unlock()
if f == nil {
f = func(c Doer) {}
f = func() {}
}
e.do = func(c Doer) bool {
f(c)
e.do = func() bool {
f()
return false
}
}
func (e *event) setbool(f func(Doer) bool) {
func (e *event) setbool(f func() bool) {
e.lock.Lock()
defer e.lock.Unlock()
if f == nil {
f = func(c Doer) bool {
f = func() bool {
return false
}
}
@ -87,7 +88,7 @@ func (e *event) fire() bool {
e.lock.Lock()
defer e.lock.Unlock()
return e.do(c)
return e.do()
}
// Common code for performing a requested action (ui.Do() or ui.Stop()).

View File

@ -15,14 +15,14 @@ var closeOnClick = flag.Bool("close", false, "close on click")
func init() {
flag.Parse()
go Do(func() {
w := NewWindow(Do, "Hello", 320, 240)
b := NewButton(Do, "There")
w := NewWindow("Hello", 320, 240)
b := NewButton("There")
w.SetControl(b)
if *closeOnClick {
b.SetText("Click to Close")
}
done := make(chan struct{})
w.OnClosing(func(c Doer) bool {
w.OnClosing(func() bool {
if *closeOnClick {
panic("window closed normally in close on click mode (should not happen)")
}
@ -31,17 +31,17 @@ func init() {
done <- struct{}{}
return true
})
b.OnClicked(func(c Doer) {
b.OnClicked(func() {
println("in OnClicked()")
if *closeOnClick {
Wait(c, w.Close())
w.Close()
Stop()
done <- struct{}{}
}
})
w.Show()
<-done
})()
})
err := Go()
if err != nil {
panic(err)