Restructured container on Mac OS X likewise. Still have to test.

This commit is contained in:
Pietro Gagliardi 2014-10-27 23:57:54 -04:00
parent a2cbccd41e
commit 6b27bd7327
6 changed files with 28 additions and 60 deletions

View File

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

View File

@ -21,6 +21,12 @@
@implementation goContainerView
- (void)setFrameSize:(NSSize)s
{
[super setFrameSize:s];
containerResized(self->gocontainer);
}
@end
id newContainerView(void *gocontainer)

View File

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

View File

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

View File

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

View File

@ -20,11 +20,6 @@
return windowClosing(self->gowin);
}
- (void)windowDidResize:(NSNotification *)note
{
windowResized(self->gowin);
}
@end
id newWindow(intptr_t width, intptr_t height)