Same as three commits ago, but for the GTK+ backend.
This commit is contained in:
parent
b84cdaf077
commit
515a605dda
|
@ -20,6 +20,16 @@ type container struct {
|
||||||
layout *C.GtkLayout
|
layout *C.GtkLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sizing struct {
|
||||||
|
sizingbase
|
||||||
|
|
||||||
|
// for size calculations
|
||||||
|
// gtk+ needs nothing
|
||||||
|
|
||||||
|
// for the actual resizing
|
||||||
|
shouldVAlignTop bool
|
||||||
|
}
|
||||||
|
|
||||||
func newContainer(child Control) *container {
|
func newContainer(child Control) *container {
|
||||||
widget := C.gtk_layout_new(nil, nil)
|
widget := C.gtk_layout_new(nil, nil)
|
||||||
c := &container{
|
c := &container{
|
||||||
|
@ -41,6 +51,10 @@ func newContainer(child Control) *container {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *container) setParent(p *controlParent) {
|
||||||
|
C.gtk_container_add(p.c, c.layoutwidget)
|
||||||
|
}
|
||||||
|
|
||||||
//export containerResizing
|
//export containerResizing
|
||||||
func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||||
c := (*container)(unsafe.Pointer(data))
|
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)
|
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 (
|
const (
|
||||||
gtkXMargin = 12
|
gtkXMargin = 12
|
||||||
gtkYMargin = 12
|
gtkYMargin = 12
|
||||||
|
|
|
@ -13,6 +13,7 @@ import "C"
|
||||||
|
|
||||||
type tab struct {
|
type tab struct {
|
||||||
_widget *C.GtkWidget
|
_widget *C.GtkWidget
|
||||||
|
container *C.GtkContainer
|
||||||
notebook *C.GtkNotebook
|
notebook *C.GtkNotebook
|
||||||
|
|
||||||
tabs []*container
|
tabs []*container
|
||||||
|
@ -22,6 +23,7 @@ func newTab() Tab {
|
||||||
widget := C.gtk_notebook_new()
|
widget := C.gtk_notebook_new()
|
||||||
t := &tab{
|
t := &tab{
|
||||||
_widget: widget,
|
_widget: widget,
|
||||||
|
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
|
||||||
notebook: (*C.GtkNotebook)(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
|
// 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) {
|
func (t *tab) Append(name string, control Control) {
|
||||||
c := newContainer(control)
|
c := newContainer(control)
|
||||||
t.tabs = append(t.tabs, c)
|
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)
|
cname := togstr(name)
|
||||||
defer freegstr(cname)
|
defer freegstr(cname)
|
||||||
tab := C.gtk_notebook_append_page(t.notebook,
|
C.gtk_notebook_set_tab_label_text(t.notebook,
|
||||||
// TODO figure out how to keep this private
|
// unfortunately there does not seem to be a gtk_notebook_set_nth_tab_label_text()
|
||||||
c.layoutwidget,
|
C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs) - 1)),
|
||||||
C.gtk_label_new(cname))
|
cname)
|
||||||
if tab == -1 {
|
|
||||||
panic("gtk_notebook_append_page() failed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) widget() *C.GtkWidget {
|
func (t *tab) widget() *C.GtkWidget {
|
||||||
|
|
|
@ -42,8 +42,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
||||||
C.gpointer(unsafe.Pointer(w)))
|
C.gpointer(unsafe.Pointer(w)))
|
||||||
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
|
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
|
||||||
w.container = newContainer(control)
|
w.container = newContainer(control)
|
||||||
// TODO make a method of container? because this would conflict with tabs...
|
w.container.setParent(&controlParent{w.wc})
|
||||||
C.gtk_container_add(w.wc, w.container.layoutwidget)
|
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue