2014-07-16 12:25:09 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type button struct {
|
2014-07-30 11:34:54 -05:00
|
|
|
*controlbase
|
2014-07-17 11:02:39 -05:00
|
|
|
clicked *event
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-22 22:32:32 -05:00
|
|
|
func finishNewButton(id C.id, text string) *button {
|
2014-07-19 08:44:32 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
b := &button{
|
2014-07-30 11:34:54 -05:00
|
|
|
controlbase: newControl(id),
|
2014-07-19 08:44:32 -05:00
|
|
|
clicked: newEvent(),
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
2014-07-22 22:32:32 -05:00
|
|
|
C.buttonSetText(b.id, ctext)
|
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-22 22:32:32 -05:00
|
|
|
func newButton(text string) *button {
|
|
|
|
return finishNewButton(C.newButton(), text)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2014-07-22 22:32:32 -05:00
|
|
|
|
|
|
|
type checkbox struct {
|
|
|
|
*button
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCheckbox(text string) *checkbox {
|
|
|
|
return &checkbox{
|
|
|
|
button: finishNewButton(C.newCheckbox(), text),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we don't need to define our own event here; we can just reuse Button's
|
|
|
|
// (it's all target-action anyway)
|
|
|
|
|
2014-07-23 16:09:08 -05:00
|
|
|
func (c *checkbox) Checked() bool {
|
2014-07-22 22:32:32 -05:00
|
|
|
return fromBOOL(C.checkboxChecked(c.id))
|
|
|
|
}
|
|
|
|
|
2014-07-23 16:09:08 -05:00
|
|
|
func (c *checkbox) SetChecked(checked bool) {
|
2014-07-22 22:32:32 -05:00
|
|
|
C.checkboxSetChecked(c.id, toBOOL(checked))
|
|
|
|
}
|
2014-07-26 08:20:33 -05:00
|
|
|
|
|
|
|
type textField struct {
|
2014-07-30 11:34:54 -05:00
|
|
|
*controlbase
|
2014-07-26 08:20:33 -05:00
|
|
|
}
|
|
|
|
|
2014-07-29 12:48:31 -05:00
|
|
|
func finishNewTextField(id C.id) *textField {
|
2014-07-26 08:20:33 -05:00
|
|
|
return &textField{
|
2014-07-30 11:34:54 -05:00
|
|
|
controlbase: newControl(id),
|
2014-07-26 08:20:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 12:48:31 -05:00
|
|
|
func newTextField() *textField {
|
|
|
|
return finishNewTextField(C.newTextField())
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:20:33 -05:00
|
|
|
func newPasswordField() *textField {
|
2014-07-29 12:48:31 -05:00
|
|
|
return finishNewTextField(C.newPasswordField())
|
2014-07-26 08:20:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *textField) Text() string {
|
|
|
|
return C.GoString(C.textFieldText(t.id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *textField) SetText(text string) {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
C.textFieldSetText(t.id, ctext)
|
|
|
|
}
|
2014-07-29 12:48:31 -05:00
|
|
|
|
|
|
|
// cheap trick
|
|
|
|
type label struct {
|
|
|
|
*textField
|
|
|
|
standalone bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func finishNewLabel(text string, standalone bool) *label {
|
|
|
|
l := &label{
|
|
|
|
textField: finishNewTextField(C.newLabel()),
|
|
|
|
standalone: standalone,
|
|
|
|
}
|
|
|
|
l.SetText(text)
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func newLabel(text string) Label {
|
|
|
|
return finishNewLabel(text, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newStandaloneLabel(text string) Label {
|
|
|
|
return finishNewLabel(text, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO label commitResize
|