2014-07-07 09:44:46 -05:00
|
|
|
// 7 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type widgetbase struct {
|
|
|
|
widget *C.GtkWidget
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWidget(w *C.GtkWidget) *widget {
|
|
|
|
return &widget{
|
|
|
|
widget: w,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type button struct {
|
|
|
|
*widgetbase
|
|
|
|
button *C.GtkButton
|
|
|
|
}
|
|
|
|
|
2014-07-07 14:30:55 -05:00
|
|
|
func newButton(text string) *Request {
|
|
|
|
c := make(chan interface{})
|
|
|
|
return &Request{
|
|
|
|
op: func() {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
widget := C.gtk_button_new_with_label(ctext)
|
|
|
|
c <- &button{
|
|
|
|
widget: newWidget(widget),
|
|
|
|
button: (*C.GtkButton)(unsafe.Pointer(widget)),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resp: c,
|
2014-07-07 09:44:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 15:51:17 -05:00
|
|
|
func (b *Button) OnClicked(func e(c Doer)) *Request {
|
|
|
|
// TODO
|
|
|
|
return nil
|
|
|
|
}
|
2014-07-07 09:44:46 -05:00
|
|
|
|
|
|
|
func (b *button) Text() *Request {
|
|
|
|
c := make(chan interface{})
|
|
|
|
return &Request{
|
|
|
|
op: func() {
|
|
|
|
c <- fromgstr(C.gtk_button_get_label(b.button))
|
|
|
|
},
|
|
|
|
resp: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) SetText(text string) *Request {
|
|
|
|
c := make(chan interface{})
|
|
|
|
return &Request{
|
|
|
|
op: func() {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
C.gtk_button_set_label(b.button, ctext)
|
|
|
|
c <- struct{}{}
|
|
|
|
},
|
|
|
|
resp: c,
|
|
|
|
}
|
|
|
|
}
|