summaryrefslogtreecommitdiff
path: root/prefsize_darwin.go
blob: 630969e52d806af98bf8362924fe4986ae2acf3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 1 march 2014
package ui

// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
// #include "objc_darwin.h"
import "C"

// -[NSCell cellSize] is documented as determining the minimum size needed to draw its receiver. This will work for our case; it appears to be what GTK+ does as well.
// See also: http://stackoverflow.com/questions/1056079/is-there-a-way-to-programmatically-determine-the-proper-sizes-for-apples-built
// TODO figure out what to do if one of our controls returns the sentinel (10000, 10000) that indicates we can't use -[NSCell cellSize]

var (
	_cell = sel_getUid("cell")
	_cellSize = sel_getUid("cellSize")
)

func (s *sysData) preferredSize() (width int, height int) {
if classTypes[s.ctype].make == nil { return 0, 0 }	// prevent lockup during window resize
	cell := C.objc_msgSend_noargs(s.id, _cell)
	cs := C.objc_msgSend_stret_size_noargs(cell, _cellSize)
	return int(cs.width), int(cs.height)
}