summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/containers_unix.go11
-rw-r--r--redo/sizing.go18
-rw-r--r--redo/sizing_unix.go15
-rw-r--r--redo/window_unix.go2
4 files changed, 33 insertions, 13 deletions
diff --git a/redo/containers_unix.go b/redo/containers_unix.go
index 20d1bef..2bae60b 100644
--- a/redo/containers_unix.go
+++ b/redo/containers_unix.go
@@ -36,7 +36,7 @@ func (t *tab) Append(name string, control Control) {
t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
c := new(container)
- c.beginResize = beginResize
+ // don't set beginResize; this container's resize() will be a recursive call
t.containers = append(t.containers, c)
c.child = control
c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
@@ -55,6 +55,15 @@ func (t *tab) Append(name string, control Control) {
}
}
+func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
+ // set up the recursive calls
+ for _, c := range t.containers {
+ c.d = d
+ }
+ // and prepare the tabbed control itself
+ return t.widgetbase.allocate(x, y, width, height, d)
+}
+
//export layoutResizing
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
c := (*container)(unsafe.Pointer(data))
diff --git a/redo/sizing.go b/redo/sizing.go
index 0db6216..97cf4e8 100644
--- a/redo/sizing.go
+++ b/redo/sizing.go
@@ -30,19 +30,31 @@ type controlSizing interface {
type container struct {
child Control
spaced bool
- beginResize func() (d *sizing)
+ beginResize func() (d *sizing) // for the initial call
+ d *sizing // for recursive calls
}
func (c *container) resize(width, height int) {
if c.child == nil { // no children; nothing to do
return
}
- d := c.beginResize()
+ if c.d == nil { // initial call
+ if c.beginResize == nil {
+ // should be a recursive call, but is not
+ // TODO get rid of this
+ return
+ }
+ c.d = c.beginResize()
+ defer c.endResize(c.d)
+ }
+ d := c.d
allocations := c.child.allocate(0, 0, width, height, d)
c.translateAllocationCoords(allocations, width, height)
// move in reverse so as to approximate right->left order so neighbors make sense
for i := len(allocations) - 1; i >= 0; i-- {
allocations[i].this.commitResize(allocations[i], d)
}
- c.endResize(d)
+ // always set c.d to nil so it can be garbage-collected
+ // the c.endResize() above won't matter since the c.d there is evaluated then, not when c.endResize() is called
+ c.d = nil
}
diff --git a/redo/sizing_unix.go b/redo/sizing_unix.go
index 2180b8d..5b19f9e 100644
--- a/redo/sizing_unix.go
+++ b/redo/sizing_unix.go
@@ -24,15 +24,14 @@ const (
gtkYPadding = 6
)
-func beginResize() (d *sizing) {
+func (w *window) beginResize() (d *sizing) {
d = new(sizing)
-//TODO
-// if w.spaced {
-// d.xmargin = gtkXMargin
-// d.ymargin = gtkYMargin
-// d.xpadding = gtkXPadding
-// d.ypadding = gtkYPadding
-// }
+ if w.spaced {
+ d.xmargin = gtkXMargin
+ d.ymargin = gtkYMargin
+ d.xpadding = gtkXPadding
+ d.ypadding = gtkYPadding
+ }
return d
}
diff --git a/redo/window_unix.go b/redo/window_unix.go
index 736ad7e..6ab68b1 100644
--- a/redo/window_unix.go
+++ b/redo/window_unix.go
@@ -49,7 +49,7 @@ func newWindow(title string, width int, height int, control Control) *window {
closing: newEvent(),
container: new(container),
}
- w.container.beginResize = beginResize
+ w.container.beginResize = w.beginResize
C.gtk_window_set_title(w.window, ctitle)
g_signal_connect(
C.gpointer(unsafe.Pointer(w.window)),