summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-01 04:16:42 -0500
committerPietro Gagliardi <[email protected]>2014-03-01 04:16:42 -0500
commit6b8a8d2d15ef016650ac277f4439b6f0cfb9b371 (patch)
tree17d72a36987f0436301b5032e1587a6184ffaefa
parentc2bf04c7cd9a80345cb55f58eea71d825a2b6b8a (diff)
Added preferred size code for Mac OS X.
-rw-r--r--prefsize_darwin.go21
1 files changed, 21 insertions, 0 deletions
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)
+}