Added events and validity methods to TextField and implemented the events on the GTK+ backend.
This commit is contained in:
parent
d07230e55e
commit
5f830deec8
|
@ -48,6 +48,15 @@ type TextField interface {
|
||||||
// Text and SetText are Requests that get and set the TextField's text.
|
// Text and SetText are Requests that get and set the TextField's text.
|
||||||
Text() string
|
Text() string
|
||||||
SetText(text string)
|
SetText(text string)
|
||||||
|
|
||||||
|
// OnChanged is triggered when the text in a TextField is changed somehow.
|
||||||
|
// Do not bother trying to figure out how the text was changed; instead, perform your validation and use Invalid to inform the user that the entered text is invalid instead.
|
||||||
|
OnChanged(func())
|
||||||
|
|
||||||
|
// Invalid throws a non-modal alert (whose nature is system-defined) on or near the TextField that alerts the user that input is invalid.
|
||||||
|
// The string passed to Invalid will be displayed to the user to inform them of what specifically is wrong with the input.
|
||||||
|
// Pass an empty string to remove the warning.
|
||||||
|
Invalid(reason string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextField creates a new TextField.
|
// NewTextField creates a new TextField.
|
||||||
|
|
|
@ -9,21 +9,28 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "gtk_unix.h"
|
// #include "gtk_unix.h"
|
||||||
// extern void buttonClicked(GtkButton *, gpointer);
|
// extern void textfieldChanged(GtkEditable *, gpointer);
|
||||||
// extern void checkboxToggled(GtkToggleButton *, gpointer);
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type textfield struct {
|
type textfield struct {
|
||||||
_widget *C.GtkWidget
|
_widget *C.GtkWidget
|
||||||
entry *C.GtkEntry
|
entry *C.GtkEntry
|
||||||
|
changed *event
|
||||||
}
|
}
|
||||||
|
|
||||||
func startNewTextField() *textfield {
|
func startNewTextField() *textfield {
|
||||||
widget := C.gtk_entry_new()
|
widget := C.gtk_entry_new()
|
||||||
return &textfield{
|
t := &textfield{
|
||||||
_widget: widget,
|
_widget: widget,
|
||||||
entry: (*C.GtkEntry)(unsafe.Pointer(widget)),
|
entry: (*C.GtkEntry)(unsafe.Pointer(widget)),
|
||||||
|
changed: newEvent(),
|
||||||
}
|
}
|
||||||
|
g_signal_connect(
|
||||||
|
C.gpointer(unsafe.Pointer(t._widget)),
|
||||||
|
"changed",
|
||||||
|
C.GCallback(C.textfieldChanged),
|
||||||
|
C.gpointer(unsafe.Pointer(t)))
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTextField() *textfield {
|
func newTextField() *textfield {
|
||||||
|
@ -46,6 +53,21 @@ func (t *textfield) SetText(text string) {
|
||||||
C.gtk_entry_set_text(t.entry, ctext)
|
C.gtk_entry_set_text(t.entry, ctext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *textfield) OnChanged(f func()) {
|
||||||
|
t.changed.set(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textfield) Invalid(reason string) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
//export textfieldChanged
|
||||||
|
func textfieldChanged(editable *C.GtkEditable, data C.gpointer) {
|
||||||
|
t := (*textfield)(unsafe.Pointer(data))
|
||||||
|
println("changed")
|
||||||
|
t.changed.fire()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *textfield) widget() *C.GtkWidget {
|
func (t *textfield) widget() *C.GtkWidget {
|
||||||
return t._widget
|
return t._widget
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue