summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-16 17:30:58 -0500
committerPietro Gagliardi <[email protected]>2014-02-16 17:30:58 -0500
commit7c365b39205310d042d17fcb0825e84ee19477a5 (patch)
treef58c8c42b1126e0bf16125f737d7f74c133afcd1
parent1bcbce414287a9eecfd291522f4a8e2dd0c28102 (diff)
[GTK+] Added buttons. Things aren't quite being positioned properly yet though...
-rw-r--r--callbacks_unix.go7
-rw-r--r--gtkcalls_unix.go15
-rw-r--r--sysdata_unix.go24
3 files changed, 42 insertions, 4 deletions
diff --git a/callbacks_unix.go b/callbacks_unix.go
index dd29399..466beed 100644
--- a/callbacks_unix.go
+++ b/callbacks_unix.go
@@ -17,6 +17,7 @@ while we're at it the callback for our idle function will be handled here too fo
// #include <gtk/gtk.h>
// extern gboolean our_callback(gpointer);
// extern gboolean our_delete_event_callback(GtkWidget *, GdkEvent *, gpointer);
+// extern void our_clicked_callback(GtkButton *, gpointer);
import "C"
//export our_callback
@@ -30,7 +31,13 @@ func our_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gp
return our_callback(what)
}
+//export our_clicked_callback
+func our_clicked_callback(button *C.GtkButton, what C.gpointer) {
+ our_callback(what)
+}
+
var callbacks = map[string]C.GCallback{
"idle": C.GCallback(C.our_callback),
"delete-event": C.GCallback(C.our_delete_event_callback),
+ "clicked": C.GCallback(C.our_clicked_callback),
}
diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go
index 0f4f818..fa69789 100644
--- a/gtkcalls_unix.go
+++ b/gtkcalls_unix.go
@@ -88,11 +88,22 @@ func gtk_container_add(container *gtkWidget, widget *gtkWidget) {
C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(container)), gtkwidget(widget))
}
-func gtk_fixed_put(container *gtkWidget, widget *gtkWidget, x int, y int) {
- C.gtk_fixed_put((*C.GtkFixed)(unsafe.Pointer(container)), gtkwidget(widget),
+func gtk_fixed_move(container *gtkWidget, widget *gtkWidget, x int, y int) {
+ C.gtk_fixed_move((*C.GtkFixed)(unsafe.Pointer(container)), gtkwidget(widget),
C.gint(x), C.gint(y))
}
func gtk_widget_set_size_request(widget *gtkWidget, width int, height int) {
C.gtk_widget_set_size_request(gtkwidget(widget), C.gint(width), C.gint(height))
}
+
+func gtk_button_new() *gtkWidget {
+ return (*gtkWidget)(unsafe.Pointer(C.gtk_button_new()))
+}
+
+func gtk_button_set_label(button *gtkWidget, label string) {
+ clabel := C.CString(label)
+ defer C.free(unsafe.Pointer(clabel))
+ C.gtk_button_set_label((*C.GtkButton)(unsafe.Pointer(button)),
+ (*C.gchar)(unsafe.Pointer(clabel)))
+}
diff --git a/sysdata_unix.go b/sysdata_unix.go
index 9685004..dfe3a8c 100644
--- a/sysdata_unix.go
+++ b/sysdata_unix.go
@@ -38,7 +38,18 @@ var classTypes = [nctypes]*classData{
},
},
c_button: &classData{
-// make: gtk_button_new,
+ make: gtk_button_new,
+ setText: gtk_button_set_label,
+ signals: map[string]func(*sysData) func() bool{
+ "clicked": func(w *sysData) func() bool {
+ return func() bool {
+ if w.event != nil {
+ w.event <- struct{}{}
+ }
+ return true // do not close the window
+ }
+ },
+ },
},
c_checkbox: &classData{
},
@@ -77,6 +88,14 @@ println(s.widget)
s.container = <-ret
} else {
s.container = window.container
+ uitask <- func() {
+ gtk_container_add(s.container, s.widget)
+ for signal, generator := range ct.signals {
+ g_signal_connect(s.widget, signal, generator(s))
+ }
+ ret <- nil
+ }
+ <-ret
}
err := s.setText(initText)
if err != nil {
@@ -123,7 +142,8 @@ func (s *sysData) setRect(x int, y int, width int, height int) error {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
- gtk_fixed_put(s.container, s.widget, x, y)
+println(s.ctype, x, y, width, height)
+ gtk_fixed_move(s.container, s.widget, x, y)
gtk_widget_set_size_request(s.widget, width, height)
ret <- struct{}{}
}