andlabs-ui/tab_darwin.go

54 lines
1.2 KiB
Go
Raw Normal View History

// 25 july 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type tab struct {
2014-10-18 16:03:07 -05:00
*controlSingleObject
tabs []*container
children []Control
chainresize func(x int, y int, width int, height int, d *sizing)
}
func newTab() Tab {
2014-10-18 16:03:07 -05:00
t := &tab{
controlSingleObject: newControlSingleObject(C.newTab()),
}
2014-10-18 16:03:07 -05:00
t.fpreferredSize = t.xpreferredSize
t.chainresize = t.fresize
t.fresize = t.xresize
return t
}
func (t *tab) Append(name string, control Control) {
2014-10-18 16:03:07 -05:00
c := newContainer()
t.tabs = append(t.tabs, c)
2014-10-18 16:03:07 -05:00
control.setParent(c.parent())
t.children = append(t.children, control)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
2014-10-18 16:03:07 -05:00
C.tabAppend(t.id, cname, c.id)
}
2014-10-18 16:03:07 -05:00
func (t *tab) xpreferredSize(d *sizing) (width, height int) {
s := C.tabPreferredSize(t.id)
return int(s.width), int(s.height)
}
2014-10-18 16:03:07 -05:00
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)
2014-10-18 16:03:07 -05:00
// 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)
}
}