2014-08-02 21:35:58 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type button struct {
|
2014-08-03 19:08:25 -05:00
|
|
|
_id C.id
|
|
|
|
clicked *event
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func newButton(text string) *button {
|
2014-08-02 21:35:58 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
b := &button{
|
2014-08-03 19:08:25 -05:00
|
|
|
_id: C.newButton(),
|
2014-08-02 21:35:58 -05:00
|
|
|
clicked: newEvent(),
|
|
|
|
}
|
2014-08-03 19:08:25 -05:00
|
|
|
C.buttonSetText(b._id, ctext)
|
|
|
|
C.buttonSetDelegate(b._id, unsafe.Pointer(b))
|
2014-08-02 21:35:58 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) OnClicked(e func()) {
|
|
|
|
b.clicked.set(e)
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func (b *button) Text() string {
|
|
|
|
return C.GoString(C.buttonText(b._id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) SetText(text string) {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
C.buttonSetText(b._id, ctext)
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
//export buttonClicked
|
|
|
|
func buttonClicked(xb unsafe.Pointer) {
|
|
|
|
b := (*button)(unsafe.Pointer(xb))
|
|
|
|
b.clicked.fire()
|
|
|
|
println("button clicked")
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func (b *button) id() C.id {
|
|
|
|
return b._id
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func (b *button) setParent(p *controlParent) {
|
|
|
|
basesetParent(b, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
|
|
return baseallocate(b, x, y, width, height, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) preferredSize(d *sizing) (width, height int) {
|
|
|
|
return basepreferredSize(b, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) commitResize(a *allocation, d *sizing) {
|
|
|
|
basecommitResize(b, a, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) getAuxResizeInfo(d *sizing) {
|
|
|
|
basegetAuxResizeInfo(b, d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|