Added the GTK+ implementation of Window, added the Window constructors, and rewrote the GTK+ Button constructor to use Requests.

This commit is contained in:
Pietro Gagliardi 2014-07-07 15:30:55 -04:00
parent 7966d70230
commit c0c38ac8f5
3 changed files with 136 additions and 7 deletions

View File

@ -24,13 +24,19 @@ type button struct {
button *C.GtkButton button *C.GtkButton
} }
func newButton(text string) Button { func newButton(text string) *Request {
ctext := togstr(text) c := make(chan interface{})
defer freegstr(ctext) return &Request{
widget := C.gtk_button_new_with_label(ctext) op: func() {
return &button{ ctext := togstr(text)
widget: newWidget(widget), defer freegstr(ctext)
button: (*C.GtkButton)(unsafe.Pointer(widget)), widget := C.gtk_button_new_with_label(ctext)
c <- &button{
widget: newWidget(widget),
button: (*C.GtkButton)(unsafe.Pointer(widget)),
}
},
resp: c,
} }
} }

View File

@ -31,3 +31,16 @@ type Window interface {
// TODO SetSize (TODO remove?) // TODO SetSize (TODO remove?)
// TODO Center // TODO Center
} }
// NewWindow returns a Request to create a new Window with the given title text and size.
func NewWindow(title string, width int, height int) *Request {
return newWindow(title, width, height)
}
// GetNewWindow is like NewWindow but sends the Request along the given Doer and returns the resultant Window.
// Example:
// w := ui.GetNewWindow(ui.Do, "Main Window")
func GetNewWindow(c Doer, title string, width int, height int) Window {
c <- newWindow(title, width, height)
return (<-c.resp).(Window)
}

110
redo/window_unix.go Normal file
View File

@ -0,0 +1,110 @@
// 7 july 2014
package ui
import (
"unsafe"
)
// #include "gtk_unix.h"
import "C"
type window struct {
widget *C.GtkWidget
container *C.GtkContainer
bin *C.GtkBin
window *C.GtkWindow
}
func newWindow(title string, width int, height int) *Request {
c := make(chan interface{})
return &Request{
op: func() {
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
ctext := togstr(text)
defer freegstr(ctext)
w := &window{
widget: widget,
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
window: (*C.GtkWindow)(unsafe.Pointer(widget)),
}
C.gtk_window_set_title(w.window, ctext)
// TODO size
// TODO content
c <- w
},
resp: c,
}
}
func (w *window) SetControl(c Control) *Request {
c := make(chan interface{})
return &Request{
op: func() {
// TODO unparent
// TODO reparent
c <- struct{}{}
},
done: c,
}
}
func (w *window) Title() *Request {
c := make(chan interface{})
return &Request{
op: func() {
c <- fromgstr(C.gtk_window_get_title(w.window))
},
resp: c,
}
}
func (w *window) SetTitle(title string) *Request {
c := make(chan interface{})
return &Request{
op: func() {
ctext := togstr(text)
defer freegstr(ctext)
C.gtk_window_set_title(w.window, ctext)
c <- struct{}{}
},
resp: c,
}
}
func (w *window) Show() *Request {
c := make(chan interface{})
return &Request{
op: func() {
C.gtk_widget_show_all(w.widget)
c <- struct{}{}
},
resp: c,
}
}
func (w *window) Hide() *Request {
c := make(chan interface{})
return &Request{
op: func() {
C.gtk_widget_hide(w.widget)
c <- struct{}{}
},
resp: c,
}
}
func (w *window) Close() *Request {
c := make(chan interface{})
return &Request{
op: func() {
C.gtk_widget_destroy(w.widget)
c <- struct{}{}
},
resp: c,
}
}
// TODO OnClosing