2014-08-02 21:35:58 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
type textfield struct {
|
2014-08-20 14:26:48 -05:00
|
|
|
_id C.id
|
|
|
|
changed *event
|
2014-08-20 16:08:47 -05:00
|
|
|
invalid C.id
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:53:34 -05:00
|
|
|
func finishNewTextField(id C.id) *textfield {
|
2014-08-20 14:26:48 -05:00
|
|
|
t := &textfield{
|
2014-08-20 14:53:34 -05:00
|
|
|
_id: id,
|
2014-08-20 14:26:48 -05:00
|
|
|
changed: newEvent(),
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-08-20 14:26:48 -05:00
|
|
|
C.textfieldSetDelegate(t._id, unsafe.Pointer(t))
|
|
|
|
return t
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:53:34 -05:00
|
|
|
func newTextField() *textfield {
|
2014-08-20 16:08:47 -05:00
|
|
|
return finishNewTextField(C.newTextField())
|
2014-08-20 14:53:34 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func newPasswordField() *textfield {
|
2014-08-20 14:53:34 -05:00
|
|
|
return finishNewTextField(C.newPasswordField())
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) Text() string {
|
2014-08-03 19:08:25 -05:00
|
|
|
return C.GoString(C.textFieldText(t._id))
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) SetText(text string) {
|
2014-08-02 21:35:58 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
2014-08-03 19:08:25 -05:00
|
|
|
C.textFieldSetText(t._id, ctext)
|
|
|
|
}
|
|
|
|
|
2014-08-20 14:26:48 -05:00
|
|
|
func (t *textfield) OnChanged(f func()) {
|
|
|
|
t.changed.set(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *textfield) Invalid(reason string) {
|
2014-08-20 16:08:47 -05:00
|
|
|
// TODO disable animations if reason is still valid
|
|
|
|
// TODO don't steal focus
|
|
|
|
if t.invalid != nil {
|
|
|
|
C.textfieldCloseInvalidPopover(t.invalid)
|
|
|
|
t.invalid = nil
|
|
|
|
}
|
|
|
|
if reason == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
creason := C.CString(reason)
|
|
|
|
defer C.free(unsafe.Pointer(creason))
|
|
|
|
t.invalid = C.textfieldOpenInvalidPopover(t._id, creason)
|
2014-08-20 14:26:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export textfieldChanged
|
|
|
|
func textfieldChanged(data unsafe.Pointer) {
|
|
|
|
t := (*textfield)(data)
|
|
|
|
println("changed")
|
|
|
|
t.changed.fire()
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) id() C.id {
|
2014-08-03 19:08:25 -05:00
|
|
|
return t._id
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) setParent(p *controlParent) {
|
2014-08-03 19:08:25 -05:00
|
|
|
basesetParent(t, p)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
2014-08-03 19:08:25 -05:00
|
|
|
return baseallocate(t, x, y, width, height, d)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) preferredSize(d *sizing) (width, height int) {
|
2014-08-03 19:08:25 -05:00
|
|
|
return basepreferredSize(t, d)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) commitResize(a *allocation, d *sizing) {
|
2014-08-03 19:08:25 -05:00
|
|
|
basecommitResize(t, a, d)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) getAuxResizeInfo(d *sizing) {
|
2014-08-03 19:08:25 -05:00
|
|
|
basegetAuxResizeInfo(t, d)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|