2014-07-16 12:25:09 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type widgetbase struct {
|
|
|
|
id C.id
|
|
|
|
parentw *window
|
|
|
|
floating bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWidget(id C.id) *widgetbase {
|
|
|
|
return &widgetbase{
|
|
|
|
id: id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// these few methods are embedded by all the various Controls since they all will do the same thing
|
|
|
|
|
|
|
|
func (w *widgetbase) unparent() {
|
|
|
|
if w.parentw != nil {
|
|
|
|
C.unparent(w.id)
|
|
|
|
w.floating = true
|
|
|
|
w.parentw = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetbase) parent(win *window) {
|
|
|
|
C.parent(w.id, win.id, toBOOL(w.floating))
|
|
|
|
w.floating = false
|
|
|
|
w.parentw = win
|
|
|
|
}
|
|
|
|
|
|
|
|
type button struct {
|
|
|
|
*widgetbase
|
2014-07-17 11:02:39 -05:00
|
|
|
clicked *event
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func newButton(text string) *button {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
b := &button{
|
|
|
|
widgetbase: newWidget(C.newButton(ctext)),
|
|
|
|
clicked: newEvent(),
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
2014-07-19 08:44:32 -05:00
|
|
|
C.buttonSetDelegate(b.id, unsafe.Pointer(b))
|
|
|
|
return b
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) OnClicked(e func()) {
|
|
|
|
b.clicked.set(e)
|
2014-07-17 11:02:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export buttonClicked
|
|
|
|
func buttonClicked(xb unsafe.Pointer) {
|
|
|
|
b := (*button)(unsafe.Pointer(xb))
|
|
|
|
b.clicked.fire()
|
|
|
|
println("button clicked")
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) Text() string {
|
|
|
|
return C.GoString(C.buttonText(b.id))
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) SetText(text string) {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
C.buttonSetText(b.id, ctext)
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|