summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--container_darwin.go24
-rw-r--r--container_darwin.m6
-rw-r--r--group_darwin.go20
-rw-r--r--tab_darwin.go15
-rw-r--r--window_darwin.go18
-rw-r--r--window_darwin.m5
6 files changed, 28 insertions, 60 deletions
diff --git a/container_darwin.go b/container_darwin.go
index 58b7777..539ed57 100644
--- a/container_darwin.go
+++ b/container_darwin.go
@@ -10,7 +10,9 @@ import (
import "C"
type container struct {
- *controlSingleObject
+ id C.id
+ resize func(x int, y int, width int, height int, d *sizing)
+ margined bool
}
type sizing struct {
@@ -25,7 +27,7 @@ type sizing struct {
func newContainer() *container {
c := new(container)
- c.controlSingleObject = newControlSingleObject(C.newContainerView(unsafe.Pointer(c)))
+ c.id = C.newContainerView(unsafe.Pointer(c))
return c
}
@@ -33,21 +35,19 @@ func (c *container) parent() *controlParent {
return &controlParent{c.id}
}
-func (c *container) allocation(margined bool) C.struct_xrect {
+//export containerResized
+func containerResized(data unsafe.Pointer) {
+ c := (*container)(data)
+ d := beginResize()
+ // TODO make this a parameter
b := C.containerBounds(c.id)
- if margined {
+ if c.margined {
b.x += C.intptr_t(macXMargin)
b.y += C.intptr_t(macYMargin)
b.width -= C.intptr_t(macXMargin) * 2
b.height -= C.intptr_t(macYMargin) * 2
}
- return b
-}
-
-// we can just return these values as is
-func (c *container) bounds(d *sizing) (int, int, int, int) {
- b := C.containerBounds(c.id)
- return int(b.x), int(b.y), int(b.width), int(b.height)
+ c.resize(int(b.x), int(b.y), int(b.width), int(b.height), d)
}
// These are based on measurements from Interface Builder.
@@ -58,7 +58,7 @@ const (
macYPadding = 8
)
-func (w *window) beginResize() (d *sizing) {
+func beginResize() (d *sizing) {
d = new(sizing)
d.xpadding = macXPadding
d.ypadding = macYPadding
diff --git a/container_darwin.m b/container_darwin.m
index b8c61b0..7e87cf9 100644
--- a/container_darwin.m
+++ b/container_darwin.m
@@ -21,6 +21,12 @@
@implementation goContainerView
+- (void)setFrameSize:(NSSize)s
+{
+ [super setFrameSize:s];
+ containerResized(self->gocontainer);
+}
+
@end
id newContainerView(void *gocontainer)
diff --git a/group_darwin.go b/group_darwin.go
index 23dd563..eb3055c 100644
--- a/group_darwin.go
+++ b/group_darwin.go
@@ -14,10 +14,6 @@ type group struct {
child Control
container *container
-
- margined bool
-
- chainresize func(x int, y int, width int, height int, d *sizing)
}
func newGroup(text string, control Control) Group {
@@ -26,9 +22,8 @@ func newGroup(text string, control Control) Group {
g.controlSingleObject = newControlSingleObject(C.newGroup(g.container.id))
g.child = control
g.child.setParent(g.container.parent())
+ g.container.resize = g.child.resize
g.SetText(text)
- g.chainresize = g.fresize
- g.fresize = g.xresize
return g
}
@@ -43,18 +38,11 @@ func (g *group) SetText(text string) {
}
func (g *group) Margined() bool {
- return g.margined
+ return g.container.margined
}
func (g *group) SetMargined(margined bool) {
- g.margined = margined
+ g.container.margined = margined
}
-func (g *group) xresize(x int, y int, width int, height int, d *sizing) {
- // first, chain up to change the GtkFrame and its child container
- g.chainresize(x, y, width, height, d)
-
- // now that the container has the correct size, we can resize the child
- a := g.container.allocation(g.margined)
- g.child.resize(int(a.x), int(a.y), int(a.width), int(a.height), d)
-}
+// no need to override resize; the child container handles that for us
diff --git a/tab_darwin.go b/tab_darwin.go
index 112b81e..9f5ecff 100644
--- a/tab_darwin.go
+++ b/tab_darwin.go
@@ -13,7 +13,6 @@ type tab struct {
*controlSingleObject
tabs []*container
children []Control
- chainresize func(x int, y int, width int, height int, d *sizing)
}
func newTab() Tab {
@@ -21,8 +20,6 @@ func newTab() Tab {
controlSingleObject: newControlSingleObject(C.newTab()),
}
t.fpreferredSize = t.xpreferredSize
- t.chainresize = t.fresize
- t.fresize = t.xresize
return t
}
@@ -30,6 +27,7 @@ func (t *tab) Append(name string, control Control) {
c := newContainer()
t.tabs = append(t.tabs, c)
control.setParent(c.parent())
+ c.resize = control.resize
t.children = append(t.children, control)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
@@ -41,13 +39,4 @@ func (t *tab) xpreferredSize(d *sizing) (width, height int) {
return int(s.width), int(s.height)
}
-func (t *tab) xresize(x int, y int, width int, height int, d *sizing) {
- // first, chain up to change the GtkFrame and its child container
- t.chainresize(x, y, width, height, d)
-
- // now that the containers have the correct size, we can resize the children
- for i, _ := range t.tabs {
- a := t.tabs[i].allocation(false/*TODO*/)
- t.children[i].resize(int(a.x), int(a.y), int(a.width), int(a.height), d)
- }
-}
+// no need to handle resize; the children containers handle that for us
diff --git a/window_darwin.go b/window_darwin.go
index e0804be..32f744a 100644
--- a/window_darwin.go
+++ b/window_darwin.go
@@ -16,8 +16,6 @@ type window struct {
child Control
container *container
-
- margined bool
}
func newWindow(title string, width int, height int, control Control) *window {
@@ -34,6 +32,7 @@ func newWindow(title string, width int, height int, control Control) *window {
C.windowSetDelegate(w.id, unsafe.Pointer(w))
C.windowSetContentView(w.id, w.container.id)
w.child.setParent(w.container.parent())
+ w.container.resize = w.child.resize
// trigger an initial resize
return w
}
@@ -50,9 +49,6 @@ func (w *window) SetTitle(title string) {
func (w *window) Show() {
C.windowShow(w.id)
- // trigger an initial resize
- // TODO fine-tune this
- windowResized(unsafe.Pointer(w))
}
func (w *window) Hide() {
@@ -68,11 +64,11 @@ func (w *window) OnClosing(e func() bool) {
}
func (w *window) Margined() bool {
- return w.margined
+ return w.container.margined
}
func (w *window) SetMargined(margined bool) {
- w.margined = margined
+ w.container.margined = margined
}
//export windowClosing
@@ -85,10 +81,4 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
return C.NO
}
-//export windowResized
-func windowResized(data unsafe.Pointer) {
- w := (*window)(data)
- a := w.container.allocation(w.margined)
- d := w.beginResize()
- w.child.resize(int(a.x), int(a.y), int(a.width), int(a.height), d)
-}
+// no need for windowResized; the child container takes care of that
diff --git a/window_darwin.m b/window_darwin.m
index b156392..21287cf 100644
--- a/window_darwin.m
+++ b/window_darwin.m
@@ -20,11 +20,6 @@
return windowClosing(self->gowin);
}
-- (void)windowDidResize:(NSNotification *)note
-{
- windowResized(self->gowin);
-}
-
@end
id newWindow(intptr_t width, intptr_t height)