From 6b8a8d2d15ef016650ac277f4439b6f0cfb9b371 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 1 Mar 2014 04:16:42 -0500 Subject: [PATCH] Added preferred size code for Mac OS X. --- prefsize_darwin.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 prefsize_darwin.go diff --git a/prefsize_darwin.go b/prefsize_darwin.go new file mode 100644 index 0000000..316662e --- /dev/null +++ b/prefsize_darwin.go @@ -0,0 +1,21 @@ +// 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) { + cell := C.objc_msgSend_noargs(s.id, _cell) + cs := C.objc_msgSend_stret_size_noargs(cell, _cellSize) + return int(cs.width), int(cs.height) +}