Added window (and thus control) resizing. Other bugs have been fixed along the way.
This commit is contained in:
parent
7c365b3920
commit
622d7b1569
|
@ -16,7 +16,7 @@ while we're at it the callback for our idle function will be handled here too fo
|
||||||
// #cgo pkg-config: gtk+-3.0
|
// #cgo pkg-config: gtk+-3.0
|
||||||
// #include <gtk/gtk.h>
|
// #include <gtk/gtk.h>
|
||||||
// extern gboolean our_callback(gpointer);
|
// extern gboolean our_callback(gpointer);
|
||||||
// extern gboolean our_delete_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
// extern gboolean our_window_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||||
// extern void our_clicked_callback(GtkButton *, gpointer);
|
// extern void our_clicked_callback(GtkButton *, gpointer);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ func our_callback(what C.gpointer) C.gboolean {
|
||||||
return togbool(f())
|
return togbool(f())
|
||||||
}
|
}
|
||||||
|
|
||||||
//export our_delete_event_callback
|
//export our_window_callback
|
||||||
func our_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean {
|
func our_window_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean {
|
||||||
return our_callback(what)
|
return our_callback(what)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ func our_clicked_callback(button *C.GtkButton, what C.gpointer) {
|
||||||
|
|
||||||
var callbacks = map[string]C.GCallback{
|
var callbacks = map[string]C.GCallback{
|
||||||
"idle": C.GCallback(C.our_callback),
|
"idle": C.GCallback(C.our_callback),
|
||||||
"delete-event": C.GCallback(C.our_delete_event_callback),
|
"delete-event": C.GCallback(C.our_window_callback),
|
||||||
|
"configure-event": C.GCallback(C.our_window_callback),
|
||||||
"clicked": C.GCallback(C.our_clicked_callback),
|
"clicked": C.GCallback(C.our_clicked_callback),
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,13 @@ func gtk_window_resize(window *gtkWidget, width int, height int) {
|
||||||
C.gtk_window_resize((*C.GtkWindow)(unsafe.Pointer(window)), C.gint(width), C.gint(height))
|
C.gtk_window_resize((*C.GtkWindow)(unsafe.Pointer(window)), C.gint(width), C.gint(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gtk_window_get_size(window *gtkWidget) (int, int) {
|
||||||
|
var width, height C.gint
|
||||||
|
|
||||||
|
C.gtk_window_get_size((*C.GtkWindow)(unsafe.Pointer(window)), &width, &height)
|
||||||
|
return int(width), int(height)
|
||||||
|
}
|
||||||
|
|
||||||
func gtk_fixed_new() *gtkWidget {
|
func gtk_fixed_new() *gtkWidget {
|
||||||
return (*gtkWidget)(unsafe.Pointer(C.gtk_fixed_new()))
|
return (*gtkWidget)(unsafe.Pointer(C.gtk_fixed_new()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,19 @@ var classTypes = [nctypes]*classData{
|
||||||
return true // do not close the window
|
return true // do not close the window
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"configure-event": func(w *sysData) func() bool {
|
||||||
|
return func() bool {
|
||||||
|
if w.container != nil && w.resize != nil { // wait for init
|
||||||
|
width, height := gtk_window_get_size(w.widget)
|
||||||
|
// run in another goroutine since this will be called in uitask
|
||||||
|
go func() {
|
||||||
|
w.resize(0, 0, width, height)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
// TODO really return true?
|
||||||
|
return true // do not continue events; we just did so
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
c_button: &classData{
|
c_button: &classData{
|
||||||
|
@ -80,6 +93,7 @@ println(s.widget)
|
||||||
uitask <- func() {
|
uitask <- func() {
|
||||||
fixed := gtk_fixed_new()
|
fixed := gtk_fixed_new()
|
||||||
gtk_container_add(s.widget, fixed)
|
gtk_container_add(s.widget, fixed)
|
||||||
|
// TODO return the container before assigning the signals?
|
||||||
for signal, generator := range ct.signals {
|
for signal, generator := range ct.signals {
|
||||||
g_signal_connect(s.widget, signal, generator(s))
|
g_signal_connect(s.widget, signal, generator(s))
|
||||||
}
|
}
|
||||||
|
@ -139,6 +153,7 @@ if classTypes[s.ctype] == nil || classTypes[s.ctype].setText == nil { return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysData) setRect(x int, y int, width int, height int) error {
|
func (s *sysData) setRect(x int, y int, width int, height int) error {
|
||||||
|
if classTypes[s.ctype] == nil || classTypes[s.ctype].setText == nil { return nil }
|
||||||
ret := make(chan struct{})
|
ret := make(chan struct{})
|
||||||
defer close(ret)
|
defer close(ret)
|
||||||
uitask <- func() {
|
uitask <- func() {
|
||||||
|
|
Loading…
Reference in New Issue