2014-08-04 16:03:07 -05:00
|
|
|
// 4 august 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type container struct {
|
2014-08-04 16:46:08 -05:00
|
|
|
containerbase
|
2014-08-11 11:49:39 -05:00
|
|
|
id C.id
|
2014-08-04 16:46:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type sizing struct {
|
|
|
|
sizingbase
|
|
|
|
|
|
|
|
// for size calculations
|
|
|
|
// nothing for mac
|
|
|
|
|
|
|
|
// for the actual resizing
|
|
|
|
neighborAlign C.struct_xalignment
|
2014-08-04 16:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newContainer(child Control) *container {
|
2014-08-04 16:46:08 -05:00
|
|
|
c := new(container)
|
2014-08-11 11:49:39 -05:00
|
|
|
c.id = C.newContainerView(unsafe.Pointer(c))
|
2014-08-04 16:03:07 -05:00
|
|
|
c.child = child
|
2014-08-11 11:49:39 -05:00
|
|
|
c.child.setParent(&controlParent{c.id})
|
2014-08-04 16:03:07 -05:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
//export containerResized
|
|
|
|
func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
|
|
|
c := (*container)(unsafe.Pointer(data))
|
2014-08-04 16:28:53 -05:00
|
|
|
// the origin of a view's content area is always (0, 0)
|
2014-08-04 16:03:07 -05:00
|
|
|
c.resize(0, 0, int(width), int(height))
|
|
|
|
}
|
2014-08-04 16:46:08 -05:00
|
|
|
|
2014-08-14 12:44:24 -05:00
|
|
|
// These are based on measurements from Interface Builder.
|
2014-08-04 16:46:08 -05:00
|
|
|
const (
|
2014-08-14 12:44:24 -05:00
|
|
|
macXMargin = 20
|
|
|
|
macYMargin = 20
|
|
|
|
macXPadding = 8
|
|
|
|
macYPadding = 8
|
2014-08-04 16:46:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *container) beginResize() (d *sizing) {
|
|
|
|
d = new(sizing)
|
|
|
|
if spaced {
|
|
|
|
d.xmargin = macXMargin
|
2014-08-24 20:23:19 -05:00
|
|
|
d.ymargintop = macYMargin
|
|
|
|
d.ymarginbottom = d.ymargintop
|
2014-08-04 16:46:08 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|