summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/containers_darwin.go7
-rw-r--r--redo/containers_unix.go7
-rw-r--r--redo/sizing.go12
-rw-r--r--redo/sizing_darwin.go4
-rw-r--r--redo/sizing_unix.go4
-rw-r--r--redo/window_darwin.go1
-rw-r--r--redo/window_unix.go1
-rw-r--r--redo/zz_test.go4
8 files changed, 11 insertions, 29 deletions
diff --git a/redo/containers_darwin.go b/redo/containers_darwin.go
index b42708c..abb9e00 100644
--- a/redo/containers_darwin.go
+++ b/redo/containers_darwin.go
@@ -25,7 +25,6 @@ func newTab() Tab {
func (t *tab) Append(name string, control Control) {
// TODO isolate and standardize
c := new(container)
- // don't set beginResize; this container's resize() will be a recursive call
t.containers = append(t.containers, c)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
@@ -35,11 +34,7 @@ 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
+ // only prepared the tabbed control; its children will be reallocated when that one is resized
return t.widgetbase.allocate(x, y, width, height, d)
}
diff --git a/redo/containers_unix.go b/redo/containers_unix.go
index 68dbf08..fbb63ee 100644
--- a/redo/containers_unix.go
+++ b/redo/containers_unix.go
@@ -40,7 +40,6 @@ 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)
- // 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)))
@@ -60,11 +59,7 @@ 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
+ // only prepared the tabbed control; its children will be reallocated when that one is resized
return t.widgetbase.allocate(x, y, width, height, d)
}
diff --git a/redo/sizing.go b/redo/sizing.go
index 4098f06..b828cd7 100644
--- a/redo/sizing.go
+++ b/redo/sizing.go
@@ -29,24 +29,20 @@ type controlSizing interface {
// on GTK+ and Mac OS X, one is embedded by window and all containers; beginResize() points to a global function (TODO NOT GOOD; ideally the sizing data should be passed across size-allocate requests)
type container struct {
child Control
- spaced bool
- d *sizing
}
+// set to true to apply spacing to all windows
+var spaced bool = false
+
func (c *container) resize(width, height int) {
if c.child == nil { // no children; nothing to do
return
}
- if c.d == nil { // not ready (called early or out of the proper recursive call chain (such as by the underlying system when marking an unparented Tab as shown))
- return
- }
- d := c.d
+ d := c.beginResize()
allocations := c.child.allocate(0 + d.xmargin, 0 + d.ymargin, width - (2 * d.xmargin), height - (2 * d.ymargin), 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)
}
- // always set c.d to nil so it can be garbage-collected
- c.d = nil
}
diff --git a/redo/sizing_darwin.go b/redo/sizing_darwin.go
index afd4bca..be29666 100644
--- a/redo/sizing_darwin.go
+++ b/redo/sizing_darwin.go
@@ -24,9 +24,9 @@ const (
macYPadding = 12
)
-func (w *window) beginResize() (d *sizing) {
+func (c *container) beginResize() (d *sizing) {
d = new(sizing)
- if w.spaced {
+ if spaced {
d.xmargin = macXMargin
d.ymargin = macYMargin
d.xpadding = macXPadding
diff --git a/redo/sizing_unix.go b/redo/sizing_unix.go
index 9f95e77..d94bc01 100644
--- a/redo/sizing_unix.go
+++ b/redo/sizing_unix.go
@@ -24,9 +24,9 @@ const (
gtkYPadding = 6
)
-func (w *window) beginResize() (d *sizing) {
+func (c *container) beginResize() (d *sizing) {
d = new(sizing)
- if w.spaced {
+ if spaced {
d.xmargin = gtkXMargin
d.ymargin = gtkYMargin
d.xpadding = gtkXPadding
diff --git a/redo/window_darwin.go b/redo/window_darwin.go
index 7c10861..8474c8a 100644
--- a/redo/window_darwin.go
+++ b/redo/window_darwin.go
@@ -77,7 +77,6 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
//export windowResized
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
w := (*window)(unsafe.Pointer(xw))
- w.container.d = w.beginResize()
w.resize(int(width), int(height))
fmt.Printf("new size %d x %d\n", width, height)
}
diff --git a/redo/window_unix.go b/redo/window_unix.go
index 953de49..5e9bbec 100644
--- a/redo/window_unix.go
+++ b/redo/window_unix.go
@@ -110,7 +110,6 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
//export windowResizing
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
w := (*window)(unsafe.Pointer(data))
- w.container.d = w.beginResize()
w.resize(int(r.width), int(r.height))
fmt.Printf("new size %d x %d\n", r.width, r.height)
}
diff --git a/redo/zz_test.go b/redo/zz_test.go
index d282cba..5fc821e 100644
--- a/redo/zz_test.go
+++ b/redo/zz_test.go
@@ -11,18 +11,16 @@ import (
)
var closeOnClick = flag.Bool("close", false, "close on click")
-var spaced = flag.Bool("spaced", false, "enable spacing")
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
func init() {
+ flag.BoolVar(&spaced, "spaced", false, "enable spacing")
flag.Parse()
go func() {
done := make(chan struct{})
Do(func() {
t := NewTab()
w := NewWindow("Hello", 320, 240, t)
- // TODO use a method here
- w.(*window).spaced = *spaced
w.OnClosing(func() bool {
if *closeOnClick {
panic("window closed normally in close on click mode (should not happen)")