[GTK+] Added buttons. Things aren't quite being positioned properly yet though...
This commit is contained in:
parent
1bcbce4142
commit
7c365b3920
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
@ -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{}{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue