Same as three commits ago, but for the GTK+ backend.

This commit is contained in:
Pietro Gagliardi 2014-08-04 22:21:58 -04:00
parent b84cdaf077
commit 515a605dda
3 changed files with 23 additions and 19 deletions

View File

@ -20,6 +20,16 @@ type container struct {
layout *C.GtkLayout
}
type sizing struct {
sizingbase
// for size calculations
// gtk+ needs nothing
// for the actual resizing
shouldVAlignTop bool
}
func newContainer(child Control) *container {
widget := C.gtk_layout_new(nil, nil)
c := &container{
@ -41,6 +51,10 @@ func newContainer(child Control) *container {
return c
}
func (c *container) setParent(p *controlParent) {
C.gtk_container_add(p.c, c.layoutwidget)
}
//export containerResizing
func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
c := (*container)(unsafe.Pointer(data))
@ -49,16 +63,6 @@ func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
fmt.Printf("new size %d x %d\n", r.width, r.height)
}
type sizing struct {
sizingbase
// for size calculations
// gtk+ needs nothing
// for the actual resizing
shouldVAlignTop bool
}
const (
gtkXMargin = 12
gtkYMargin = 12

View File

@ -13,6 +13,7 @@ import "C"
type tab struct {
_widget *C.GtkWidget
container *C.GtkContainer
notebook *C.GtkNotebook
tabs []*container
@ -22,6 +23,7 @@ func newTab() Tab {
widget := C.gtk_notebook_new()
t := &tab{
_widget: widget,
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)),
}
// there are no scrolling arrows by default; add them in case there are too many tabs
@ -32,15 +34,14 @@ func newTab() Tab {
func (t *tab) Append(name string, control Control) {
c := newContainer(control)
t.tabs = append(t.tabs, c)
// this calls gtk_container_add(), which, according to gregier in irc.gimp.net/#gtk+, acts just like gtk_notebook_append_page()
c.setParent(&controlParent{t.container})
cname := togstr(name)
defer freegstr(cname)
tab := C.gtk_notebook_append_page(t.notebook,
// TODO figure out how to keep this private
c.layoutwidget,
C.gtk_label_new(cname))
if tab == -1 {
panic("gtk_notebook_append_page() failed")
}
C.gtk_notebook_set_tab_label_text(t.notebook,
// unfortunately there does not seem to be a gtk_notebook_set_nth_tab_label_text()
C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs) - 1)),
cname)
}
func (t *tab) widget() *C.GtkWidget {

View File

@ -42,8 +42,7 @@ func newWindow(title string, width int, height int, control Control) *window {
C.gpointer(unsafe.Pointer(w)))
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
w.container = newContainer(control)
// TODO make a method of container? because this would conflict with tabs...
C.gtk_container_add(w.wc, w.container.layoutwidget)
w.container.setParent(&controlParent{w.wc})
return w
}