summaryrefslogtreecommitdiff
path: root/container_darwin.go
blob: ef0355bb3c902b073edeafa49f445287c3515e3c (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 4 august 2014

package ui

import (
	"unsafe"
)

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

type container struct {
	containerbase
	id C.id
}

type sizing struct {
	sizingbase

	// for size calculations
	// nothing for mac

	// for the actual resizing
	neighborAlign C.struct_xalignment
}

func newContainer(child Control) *container {
	c := new(container)
	c.id = C.newContainerView(unsafe.Pointer(c))
	c.child = child
	c.child.setParent(&controlParent{c.id})
	return c
}

//export containerResized
func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
	c := (*container)(unsafe.Pointer(data))
	// the origin of a view's content area is always (0, 0)
	c.resize(0, 0, int(width), int(height))
}

// These are based on measurements from Interface Builder.
const (
	macXMargin  = 20
	macYMargin  = 20
	macXPadding = 8
	macYPadding = 8
)

func (c *container) beginResize() (d *sizing) {
	d = new(sizing)
	if c.spaced {
		d.xmargin = macXMargin
		d.ymargintop = macYMargin
		d.ymarginbottom = d.ymargintop
		d.xpadding = macXPadding
		d.ypadding = macYPadding
	}
	return d
}

func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
	for _, a := range allocations {
		// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
		// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
		a.y = (winheight - a.y) - a.height
	}
}