Restructured container on Mac OS X likewise. Still have to test.
This commit is contained in:
parent
a2cbccd41e
commit
6b27bd7327
|
@ -10,7 +10,9 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type container struct {
|
type container struct {
|
||||||
*controlSingleObject
|
id C.id
|
||||||
|
resize func(x int, y int, width int, height int, d *sizing)
|
||||||
|
margined bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type sizing struct {
|
type sizing struct {
|
||||||
|
@ -25,7 +27,7 @@ type sizing struct {
|
||||||
|
|
||||||
func newContainer() *container {
|
func newContainer() *container {
|
||||||
c := new(container)
|
c := new(container)
|
||||||
c.controlSingleObject = newControlSingleObject(C.newContainerView(unsafe.Pointer(c)))
|
c.id = C.newContainerView(unsafe.Pointer(c))
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,21 +35,19 @@ func (c *container) parent() *controlParent {
|
||||||
return &controlParent{c.id}
|
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)
|
b := C.containerBounds(c.id)
|
||||||
if margined {
|
if c.margined {
|
||||||
b.x += C.intptr_t(macXMargin)
|
b.x += C.intptr_t(macXMargin)
|
||||||
b.y += C.intptr_t(macYMargin)
|
b.y += C.intptr_t(macYMargin)
|
||||||
b.width -= C.intptr_t(macXMargin) * 2
|
b.width -= C.intptr_t(macXMargin) * 2
|
||||||
b.height -= C.intptr_t(macYMargin) * 2
|
b.height -= C.intptr_t(macYMargin) * 2
|
||||||
}
|
}
|
||||||
return b
|
c.resize(int(b.x), int(b.y), int(b.width), int(b.height), d)
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are based on measurements from Interface Builder.
|
// These are based on measurements from Interface Builder.
|
||||||
|
@ -58,7 +58,7 @@ const (
|
||||||
macYPadding = 8
|
macYPadding = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *window) beginResize() (d *sizing) {
|
func beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
d.xpadding = macXPadding
|
d.xpadding = macXPadding
|
||||||
d.ypadding = macYPadding
|
d.ypadding = macYPadding
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
|
|
||||||
@implementation goContainerView
|
@implementation goContainerView
|
||||||
|
|
||||||
|
- (void)setFrameSize:(NSSize)s
|
||||||
|
{
|
||||||
|
[super setFrameSize:s];
|
||||||
|
containerResized(self->gocontainer);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
id newContainerView(void *gocontainer)
|
id newContainerView(void *gocontainer)
|
||||||
|
|
|
@ -14,10 +14,6 @@ type group struct {
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
container *container
|
container *container
|
||||||
|
|
||||||
margined bool
|
|
||||||
|
|
||||||
chainresize func(x int, y int, width int, height int, d *sizing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGroup(text string, control Control) Group {
|
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.controlSingleObject = newControlSingleObject(C.newGroup(g.container.id))
|
||||||
g.child = control
|
g.child = control
|
||||||
g.child.setParent(g.container.parent())
|
g.child.setParent(g.container.parent())
|
||||||
|
g.container.resize = g.child.resize
|
||||||
g.SetText(text)
|
g.SetText(text)
|
||||||
g.chainresize = g.fresize
|
|
||||||
g.fresize = g.xresize
|
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,18 +38,11 @@ func (g *group) SetText(text string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *group) Margined() bool {
|
func (g *group) Margined() bool {
|
||||||
return g.margined
|
return g.container.margined
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *group) SetMargined(margined bool) {
|
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) {
|
// no need to override resize; the child container handles that for us
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ type tab struct {
|
||||||
*controlSingleObject
|
*controlSingleObject
|
||||||
tabs []*container
|
tabs []*container
|
||||||
children []Control
|
children []Control
|
||||||
chainresize func(x int, y int, width int, height int, d *sizing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTab() Tab {
|
func newTab() Tab {
|
||||||
|
@ -21,8 +20,6 @@ func newTab() Tab {
|
||||||
controlSingleObject: newControlSingleObject(C.newTab()),
|
controlSingleObject: newControlSingleObject(C.newTab()),
|
||||||
}
|
}
|
||||||
t.fpreferredSize = t.xpreferredSize
|
t.fpreferredSize = t.xpreferredSize
|
||||||
t.chainresize = t.fresize
|
|
||||||
t.fresize = t.xresize
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +27,7 @@ func (t *tab) Append(name string, control Control) {
|
||||||
c := newContainer()
|
c := newContainer()
|
||||||
t.tabs = append(t.tabs, c)
|
t.tabs = append(t.tabs, c)
|
||||||
control.setParent(c.parent())
|
control.setParent(c.parent())
|
||||||
|
c.resize = control.resize
|
||||||
t.children = append(t.children, control)
|
t.children = append(t.children, control)
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
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)
|
return int(s.width), int(s.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) xresize(x int, y int, width int, height int, d *sizing) {
|
// no need to handle resize; the children containers handle that for us
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,8 +16,6 @@ type window struct {
|
||||||
|
|
||||||
child Control
|
child Control
|
||||||
container *container
|
container *container
|
||||||
|
|
||||||
margined bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWindow(title string, width int, height int, control Control) *window {
|
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.windowSetDelegate(w.id, unsafe.Pointer(w))
|
||||||
C.windowSetContentView(w.id, w.container.id)
|
C.windowSetContentView(w.id, w.container.id)
|
||||||
w.child.setParent(w.container.parent())
|
w.child.setParent(w.container.parent())
|
||||||
|
w.container.resize = w.child.resize
|
||||||
// trigger an initial resize
|
// trigger an initial resize
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
@ -50,9 +49,6 @@ func (w *window) SetTitle(title string) {
|
||||||
|
|
||||||
func (w *window) Show() {
|
func (w *window) Show() {
|
||||||
C.windowShow(w.id)
|
C.windowShow(w.id)
|
||||||
// trigger an initial resize
|
|
||||||
// TODO fine-tune this
|
|
||||||
windowResized(unsafe.Pointer(w))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Hide() {
|
func (w *window) Hide() {
|
||||||
|
@ -68,11 +64,11 @@ func (w *window) OnClosing(e func() bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) Margined() bool {
|
func (w *window) Margined() bool {
|
||||||
return w.margined
|
return w.container.margined
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) SetMargined(margined bool) {
|
func (w *window) SetMargined(margined bool) {
|
||||||
w.margined = margined
|
w.container.margined = margined
|
||||||
}
|
}
|
||||||
|
|
||||||
//export windowClosing
|
//export windowClosing
|
||||||
|
@ -85,10 +81,4 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
|
||||||
return C.NO
|
return C.NO
|
||||||
}
|
}
|
||||||
|
|
||||||
//export windowResized
|
// no need for windowResized; the child container takes care of that
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,11 +20,6 @@
|
||||||
return windowClosing(self->gowin);
|
return windowClosing(self->gowin);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification *)note
|
|
||||||
{
|
|
||||||
windowResized(self->gowin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
id newWindow(intptr_t width, intptr_t height)
|
id newWindow(intptr_t width, intptr_t height)
|
||||||
|
|
Loading…
Reference in New Issue