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-10-27 22:57:54 -05:00
|
|
|
id C.id
|
|
|
|
resize func(x int, y int, width int, height int, d *sizing)
|
|
|
|
margined bool
|
2014-08-04 16:46:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type sizing struct {
|
|
|
|
sizingbase
|
|
|
|
|
|
|
|
// for size calculations
|
2014-10-18 16:03:07 -05:00
|
|
|
// nothing on Mac OS X
|
2014-08-04 16:46:08 -05:00
|
|
|
|
|
|
|
// for the actual resizing
|
2014-10-02 09:05:53 -05:00
|
|
|
neighborAlign C.struct_xalignment
|
2014-08-04 16:03:07 -05:00
|
|
|
}
|
|
|
|
|
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 {
|
2014-08-04 16:46:08 -05:00
|
|
|
c := new(container)
|
2014-10-27 23:13:18 -05:00
|
|
|
c.resize = resize
|
2014-10-27 22:57:54 -05:00
|
|
|
c.id = C.newContainerView(unsafe.Pointer(c))
|
2014-08-04 16:03:07 -05:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (c *container) parent() *controlParent {
|
|
|
|
return &controlParent{c.id}
|
|
|
|
}
|
|
|
|
|
2014-10-27 22:57:54 -05:00
|
|
|
//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)
|
2014-10-27 22:57:54 -05:00
|
|
|
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
|
|
|
|
}
|
2014-10-27 22:57:54 -05:00
|
|
|
c.resize(int(b.x), int(b.y), int(b.width), int(b.height), d)
|
2014-08-04 16:03:07 -05:00
|
|
|
}
|
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-10-29 11:12:00 -05:00
|
|
|
// TODO reverify these against /layout rects/, not /frame rects/
|
2014-08-04 16:46:08 -05:00
|
|
|
const (
|
2014-10-02 09:05:53 -05:00
|
|
|
macXMargin = 20
|
|
|
|
macYMargin = 20
|
2014-08-14 12:44:24 -05:00
|
|
|
macXPadding = 8
|
|
|
|
macYPadding = 8
|
2014-08-04 16:46:08 -05:00
|
|
|
)
|
|
|
|
|
2014-10-27 22:57:54 -05:00
|
|
|
func beginResize() (d *sizing) {
|
2014-08-04 16:46:08 -05:00
|
|
|
d = new(sizing)
|
2014-10-18 16:03:07 -05:00
|
|
|
d.xpadding = macXPadding
|
|
|
|
d.ypadding = macYPadding
|
2014-08-04 16:46:08 -05:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
/*TODO
|
2014-08-04 16:46:08 -05:00
|
|
|
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
|
|
|
*/
|