andlabs-ui/prev/container_darwin.go

80 lines
1.8 KiB
Go
Raw Normal View History

// 4 august 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type container struct {
id C.id
resize func(x int, y int, width int, height int, d *sizing)
margined bool
}
type sizing struct {
sizingbase
// for size calculations
2014-10-18 16:03:07 -05:00
// nothing on Mac OS X
// for the actual resizing
neighborAlign C.struct_xalignment
}
2014-10-27 23:13:18 -05:00
// containerResized() gets called early so we have to do this in the constructor
func newContainer(resize func(x int, y int, width int, height int, d *sizing)) *container {
c := new(container)
2014-10-27 23:13:18 -05:00
c.resize = resize
c.id = C.newContainerView(unsafe.Pointer(c))
return c
}
2014-10-18 16:03:07 -05:00
func (c *container) parent() *controlParent {
return &controlParent{c.id}
}
//export containerResized
func containerResized(data unsafe.Pointer) {
c := (*container)(data)
d := beginResize()
// TODO make this a parameter
2014-10-18 16:03:07 -05:00
b := C.containerBounds(c.id)
if c.margined {
2014-10-18 16:03:07 -05:00
b.x += C.intptr_t(macXMargin)
b.y += C.intptr_t(macYMargin)
b.width -= C.intptr_t(macXMargin) * 2
b.height -= C.intptr_t(macYMargin) * 2
}
c.resize(int(b.x), int(b.y), int(b.width), int(b.height), d)
}
// These are based on measurements from Interface Builder.
// TODO reverify these against /layout rects/, not /frame rects/
const (
macXMargin = 20
macYMargin = 20
macXPadding = 8
macYPadding = 8
)
func beginResize() (d *sizing) {
d = new(sizing)
2014-10-18 16:03:07 -05:00
d.xpadding = macXPadding
d.ypadding = macYPadding
return d
}
2014-10-18 16:03:07 -05:00
/*TODO
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
}
}
2014-10-18 16:03:07 -05:00
*/