summaryrefslogtreecommitdiff
path: root/tab_darwin.go
blob: 112b81e7c89bdc28d40fb5c99ff7457de52ce45f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 25 july 2014

package ui

import (
	"unsafe"
)

// #include "objc_darwin.h"
import "C"

type tab struct {
	*controlSingleObject
	tabs			[]*container
	children		[]Control
	chainresize	func(x int, y int, width int, height int, d *sizing)
}

func newTab() Tab {
	t := &tab{
		controlSingleObject:		newControlSingleObject(C.newTab()),
	}
	t.fpreferredSize = t.xpreferredSize
	t.chainresize = t.fresize
	t.fresize = t.xresize
	return t
}

func (t *tab) Append(name string, control Control) {
	c := newContainer()
	t.tabs = append(t.tabs, c)
	control.setParent(c.parent())
	t.children = append(t.children, control)
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	C.tabAppend(t.id, cname, c.id)
}

func (t *tab) xpreferredSize(d *sizing) (width, height int) {
	s := C.tabPreferredSize(t.id)
	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)
	}
}