Fixed more conversion kinks. Now for a major change...
This commit is contained in:
parent
32061353a1
commit
e73e7ab733
|
@ -25,6 +25,6 @@ type Button interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewButton creates a new Button with the given label text.
|
// NewButton creates a new Button with the given label text.
|
||||||
func NewButton(text string) {
|
func NewButton(text string) *button {
|
||||||
return newButton(text)
|
return newButton(text)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ type button struct {
|
||||||
var buttonclass = toUTF16("BUTTON")
|
var buttonclass = toUTF16("BUTTON")
|
||||||
|
|
||||||
func newButton(text string) *button {
|
func newButton(text string) *button {
|
||||||
op: func() {
|
|
||||||
w := newWidget(buttonclass,
|
w := newWidget(buttonclass,
|
||||||
C.BS_PUSHBUTTON | C.WS_TABSTOP,
|
C.BS_PUSHBUTTON | C.WS_TABSTOP,
|
||||||
0)
|
0)
|
||||||
|
@ -70,7 +69,7 @@ func (b *button) Text() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *button) SetText(text string) {
|
func (b *button) SetText(text string) {
|
||||||
return b.settext(text)
|
b.settext(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export buttonClicked
|
//export buttonClicked
|
||||||
|
|
|
@ -5,6 +5,7 @@ package ui
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Go initializes package ui.
|
// Go initializes package ui.
|
||||||
|
@ -42,7 +43,7 @@ func Stop() {
|
||||||
|
|
||||||
type event struct {
|
type event struct {
|
||||||
// All events internally return bool; those that don't will be wrapped around to return a dummy value.
|
// 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
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,31 +51,31 @@ type event struct {
|
||||||
|
|
||||||
func newEvent() *event {
|
func newEvent() *event {
|
||||||
return &event{
|
return &event{
|
||||||
do: func(c Doer) bool {
|
do: func() bool {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *event) set(f func(Doer)) {
|
func (e *event) set(f func()) {
|
||||||
e.lock.Lock()
|
e.lock.Lock()
|
||||||
defer e.lock.Unlock()
|
defer e.lock.Unlock()
|
||||||
|
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = func(c Doer) {}
|
f = func() {}
|
||||||
}
|
}
|
||||||
e.do = func(c Doer) bool {
|
e.do = func() bool {
|
||||||
f(c)
|
f()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *event) setbool(f func(Doer) bool) {
|
func (e *event) setbool(f func() bool) {
|
||||||
e.lock.Lock()
|
e.lock.Lock()
|
||||||
defer e.lock.Unlock()
|
defer e.lock.Unlock()
|
||||||
|
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = func(c Doer) bool {
|
f = func() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +88,7 @@ func (e *event) fire() bool {
|
||||||
e.lock.Lock()
|
e.lock.Lock()
|
||||||
defer e.lock.Unlock()
|
defer e.lock.Unlock()
|
||||||
|
|
||||||
return e.do(c)
|
return e.do()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common code for performing a requested action (ui.Do() or ui.Stop()).
|
// Common code for performing a requested action (ui.Do() or ui.Stop()).
|
||||||
|
|
|
@ -15,14 +15,14 @@ var closeOnClick = flag.Bool("close", false, "close on click")
|
||||||
func init() {
|
func init() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
go Do(func() {
|
go Do(func() {
|
||||||
w := NewWindow(Do, "Hello", 320, 240)
|
w := NewWindow("Hello", 320, 240)
|
||||||
b := NewButton(Do, "There")
|
b := NewButton("There")
|
||||||
w.SetControl(b)
|
w.SetControl(b)
|
||||||
if *closeOnClick {
|
if *closeOnClick {
|
||||||
b.SetText("Click to Close")
|
b.SetText("Click to Close")
|
||||||
}
|
}
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
w.OnClosing(func(c Doer) bool {
|
w.OnClosing(func() bool {
|
||||||
if *closeOnClick {
|
if *closeOnClick {
|
||||||
panic("window closed normally in close on click mode (should not happen)")
|
panic("window closed normally in close on click mode (should not happen)")
|
||||||
}
|
}
|
||||||
|
@ -31,17 +31,17 @@ func init() {
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
b.OnClicked(func(c Doer) {
|
b.OnClicked(func() {
|
||||||
println("in OnClicked()")
|
println("in OnClicked()")
|
||||||
if *closeOnClick {
|
if *closeOnClick {
|
||||||
Wait(c, w.Close())
|
w.Close()
|
||||||
Stop()
|
Stop()
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.Show()
|
w.Show()
|
||||||
<-done
|
<-done
|
||||||
})()
|
})
|
||||||
err := Go()
|
err := Go()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in New Issue