Cleaned up sizing a bit. Being able to know how big something will be ahead of time would be better.

This commit is contained in:
Pietro Gagliardi 2014-07-25 22:13:09 -04:00
parent c676a2d9b7
commit 41f3ef292f
4 changed files with 33 additions and 13 deletions

View File

@ -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))

View File

@ -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
}

View File

@ -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
}

View File

@ -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)),