summaryrefslogtreecommitdiff
path: root/container_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-30 23:02:02 -0400
committerPietro Gagliardi <[email protected]>2014-08-30 23:02:02 -0400
commit77bf566ebbcb62acd4d08d905d9542d6ff9b6b80 (patch)
treeeeb8e72bc3bf57f5be7f0c0af4319189ac6de838 /container_darwin.go
parent155899c65ed32245e2ccad4197a10c77017d835b (diff)
...in with the new.
Diffstat (limited to 'container_darwin.go')
-rw-r--r--container_darwin.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/container_darwin.go b/container_darwin.go
new file mode 100644
index 0000000..8b98b64
--- /dev/null
+++ b/container_darwin.go
@@ -0,0 +1,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 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
+ }
+}