diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-26 14:11:03 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-26 14:11:03 -0400 |
| commit | d34ffa326c98f1c385d2068ede115887e23b3e7e (patch) | |
| tree | 30de1c8a595a117184d48ce9524b2fff0fc0b13b | |
| parent | 22989c13da1ece51a815046ee68ff57c36bbeaeb (diff) | |
Made the sizing recursive chain idempotent and added a -spaced option to the test program to test spacing.
| -rw-r--r-- | redo/sizing.go | 17 | ||||
| -rw-r--r-- | redo/window_darwin.go | 2 | ||||
| -rw-r--r-- | redo/window_unix.go | 2 | ||||
| -rw-r--r-- | redo/window_windows.go | 2 | ||||
| -rw-r--r-- | redo/zz_test.go | 3 |
5 files changed, 11 insertions, 15 deletions
diff --git a/redo/sizing.go b/redo/sizing.go index 3c71feb..b7f76d8 100644 --- a/redo/sizing.go +++ b/redo/sizing.go @@ -28,23 +28,17 @@ type controlSizing interface { // on Windows, this is only embedded by window, as all other containers cannot have their own children; beginResize() points to an instance method literal (TODO get correct term) from window // 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 - beginResize func() (d *sizing) // for the initial call - d *sizing // for recursive calls + child Control + spaced bool + d *sizing } func (c *container) resize(width, height int) { if c.child == nil { // no children; nothing to do return } - 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() + 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 allocations := c.child.allocate(0, 0, width, height, d) @@ -54,6 +48,5 @@ func (c *container) resize(width, height int) { allocations[i].this.commitResize(allocations[i], 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/window_darwin.go b/redo/window_darwin.go index 16f8b9f..7c10861 100644 --- a/redo/window_darwin.go +++ b/redo/window_darwin.go @@ -32,7 +32,6 @@ func newWindow(title string, width int, height int, control Control) *window { closing: newEvent(), container: new(container), } - w.container.beginResize = w.beginResize C.windowSetDelegate(id, unsafe.Pointer(w)) w.child = control w.child.setParent(C.windowContentView(w.id)) @@ -78,6 +77,7 @@ 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 6ab68b1..953de49 100644 --- a/redo/window_unix.go +++ b/redo/window_unix.go @@ -49,7 +49,6 @@ func newWindow(title string, width int, height int, control Control) *window { closing: newEvent(), container: new(container), } - w.container.beginResize = w.beginResize C.gtk_window_set_title(w.window, ctitle) g_signal_connect( C.gpointer(unsafe.Pointer(w.window)), @@ -111,6 +110,7 @@ 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/window_windows.go b/redo/window_windows.go index 96a9d5e..90b3e5e 100644 --- a/redo/window_windows.go +++ b/redo/window_windows.go @@ -43,7 +43,6 @@ func newWindow(title string, width int, height int, control Control) *window { closing: newEvent(), container: new(container), } - w.container.beginResize = w.beginResize hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w)) if hwnd != w.hwnd { panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window (%p) differ", hwnd, w.hwnd)) @@ -97,6 +96,7 @@ func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) { //export windowResize func windowResize(data unsafe.Pointer, r *C.RECT) { w := (*window)(data) + w.container.d = w.beginResize() w.resize(int(r.right - r.left), int(r.bottom - r.top)) } diff --git a/redo/zz_test.go b/redo/zz_test.go index e137494..d282cba 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -11,6 +11,7 @@ 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() { @@ -20,6 +21,8 @@ func init() { 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)") |
