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:
parent
c676a2d9b7
commit
41f3ef292f
|
@ -36,7 +36,7 @@ func (t *tab) Append(name string, control Control) {
|
||||||
t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
|
t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
|
||||||
t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
|
t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
|
||||||
c := new(container)
|
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)
|
t.containers = append(t.containers, c)
|
||||||
c.child = control
|
c.child = control
|
||||||
c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
|
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
|
//export layoutResizing
|
||||||
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||||
c := (*container)(unsafe.Pointer(data))
|
c := (*container)(unsafe.Pointer(data))
|
||||||
|
|
|
@ -30,19 +30,31 @@ type controlSizing interface {
|
||||||
type container struct {
|
type container struct {
|
||||||
child Control
|
child Control
|
||||||
spaced bool
|
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) {
|
func (c *container) resize(width, height int) {
|
||||||
if c.child == nil { // no children; nothing to do
|
if c.child == nil { // no children; nothing to do
|
||||||
return
|
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)
|
allocations := c.child.allocate(0, 0, width, height, d)
|
||||||
c.translateAllocationCoords(allocations, width, height)
|
c.translateAllocationCoords(allocations, width, height)
|
||||||
// move in reverse so as to approximate right->left order so neighbors make sense
|
// move in reverse so as to approximate right->left order so neighbors make sense
|
||||||
for i := len(allocations) - 1; i >= 0; i-- {
|
for i := len(allocations) - 1; i >= 0; i-- {
|
||||||
allocations[i].this.commitResize(allocations[i], d)
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,14 @@ const (
|
||||||
gtkYPadding = 6
|
gtkYPadding = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
func beginResize() (d *sizing) {
|
func (w *window) beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
//TODO
|
if w.spaced {
|
||||||
// if w.spaced {
|
d.xmargin = gtkXMargin
|
||||||
// d.xmargin = gtkXMargin
|
d.ymargin = gtkYMargin
|
||||||
// d.ymargin = gtkYMargin
|
d.xpadding = gtkXPadding
|
||||||
// d.xpadding = gtkXPadding
|
d.ypadding = gtkYPadding
|
||||||
// d.ypadding = gtkYPadding
|
}
|
||||||
// }
|
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
||||||
closing: newEvent(),
|
closing: newEvent(),
|
||||||
container: new(container),
|
container: new(container),
|
||||||
}
|
}
|
||||||
w.container.beginResize = beginResize
|
w.container.beginResize = w.beginResize
|
||||||
C.gtk_window_set_title(w.window, ctitle)
|
C.gtk_window_set_title(w.window, ctitle)
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
C.gpointer(unsafe.Pointer(w.window)),
|
C.gpointer(unsafe.Pointer(w.window)),
|
||||||
|
|
Loading…
Reference in New Issue