2014-08-02 21:35:58 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
|
|
|
// 7 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
// extern void buttonClicked(GtkButton *, gpointer);
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type button struct {
|
2014-10-18 16:03:07 -05:00
|
|
|
*controlSingleWidget
|
2014-10-02 09:05:53 -05:00
|
|
|
button *C.GtkButton
|
|
|
|
clicked *event
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// shared code for setting up buttons, check boxes, etc.
|
2014-08-03 15:28:21 -05:00
|
|
|
func newButton(text string) *button {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
widget := C.gtk_button_new_with_label(ctext)
|
2014-08-02 21:35:58 -05:00
|
|
|
b := &button{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleWidget: newControlSingleWidget(widget),
|
2014-10-02 09:05:53 -05:00
|
|
|
button: (*C.GtkButton)(unsafe.Pointer(widget)),
|
|
|
|
clicked: newEvent(),
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
g_signal_connect(
|
|
|
|
C.gpointer(unsafe.Pointer(b.button)),
|
2014-08-03 15:28:21 -05:00
|
|
|
"clicked",
|
|
|
|
C.GCallback(C.buttonClicked),
|
2014-08-02 21:35:58 -05:00
|
|
|
C.gpointer(unsafe.Pointer(b)))
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) OnClicked(e func()) {
|
|
|
|
b.clicked.set(e)
|
|
|
|
}
|
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
func (b *button) Text() string {
|
|
|
|
return fromgstr(C.gtk_button_get_label(b.button))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) SetText(text string) {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
C.gtk_button_set_label(b.button, ctext)
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
//export buttonClicked
|
|
|
|
func buttonClicked(bwid *C.GtkButton, data C.gpointer) {
|
|
|
|
b := (*button)(unsafe.Pointer(data))
|
|
|
|
b.clicked.fire()
|
|
|
|
}
|