2014-07-25 22:11:41 -05:00
|
|
|
// 25 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type tab struct {
|
2014-07-30 11:34:54 -05:00
|
|
|
*controlbase
|
2014-07-25 22:11:41 -05:00
|
|
|
|
2014-08-02 06:28:20 -05:00
|
|
|
tabs []*sizer
|
2014-07-25 22:11:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTab() Tab {
|
|
|
|
t := new(tab)
|
|
|
|
id := C.newTab(unsafe.Pointer(t))
|
2014-07-30 11:34:54 -05:00
|
|
|
t.controlbase = newControl(id)
|
2014-08-02 07:04:44 -05:00
|
|
|
t.fpreferredSize = t.tabpreferredSize
|
2014-07-25 22:11:41 -05:00
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tab) Append(name string, control Control) {
|
2014-08-02 06:28:20 -05:00
|
|
|
s := new(sizer)
|
|
|
|
t.tabs = append(t.tabs, s)
|
2014-07-25 22:11:41 -05:00
|
|
|
cname := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cname))
|
|
|
|
tabview := C.tabAppend(t.id, cname)
|
2014-08-02 06:28:20 -05:00
|
|
|
s.child = control
|
|
|
|
s.child.setParent(&controlParent{tabview})
|
2014-07-25 22:11:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-02 07:04:44 -05:00
|
|
|
func (t *tab) tabpreferredSize(d *sizing) (width, height int) {
|
|
|
|
s := C.tabPrefSize(t.id)
|
|
|
|
return int(s.width), int(s.height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// no need to override Control.commitResize() as only prepared the tabbed control; its children will be reallocated when that one is resized
|
2014-07-25 22:11:41 -05:00
|
|
|
|
|
|
|
//export tabResized
|
|
|
|
func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
|
|
|
t := (*tab)(unsafe.Pointer(data))
|
2014-08-02 06:28:20 -05:00
|
|
|
for _, s := range t.tabs {
|
2014-07-28 14:02:27 -05:00
|
|
|
// the tab area's coordinate system is localized, so the origin is (0, 0)
|
2014-08-02 06:28:20 -05:00
|
|
|
s.resize(0, 0, int(width), int(height))
|
2014-07-25 22:11:41 -05:00
|
|
|
}
|
|
|
|
}
|