summaryrefslogtreecommitdiff
path: root/container_unix.go
blob: 4db046c4553259276f8b1cb56613d99af23a2ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// +build !windows,!darwin

// 23 february 2014

package ui

import (
	"unsafe"
)

// #include "gtk_unix.h"
import "C"

type container struct {
	containerbase
	layoutwidget    *C.GtkWidget
	layoutcontainer *C.GtkContainer
}

type sizing struct {
	sizingbase

	// for size calculations
	// gtk+ needs nothing

	// for the actual resizing
	shouldVAlignTop bool
}

func newContainer(child Control) *container {
	c := new(container)
	widget := C.newContainer(unsafe.Pointer(c))
	c.layoutwidget = widget
	c.layoutcontainer = (*C.GtkContainer)(unsafe.Pointer(widget))
	c.child = child
	c.child.setParent(&controlParent{c.layoutcontainer})
	return c
}

func (c *container) setParent(p *controlParent) {
	C.gtk_container_add(p.c, c.layoutwidget)
}

//export containerResizing
func containerResizing(data unsafe.Pointer, r *C.GtkAllocation) {
	c := (*container)(data)
	c.resize(int(r.x), int(r.y), int(r.width), int(r.height))
}

const (
	gtkXMargin  = 12
	gtkYMargin  = 12
	gtkXPadding = 12
	gtkYPadding = 6
)

func (c *container) beginResize() (d *sizing) {
	d = new(sizing)
	if c.spaced {
		d.xmargin = gtkXMargin
		d.ymargintop = gtkYMargin
		d.ymarginbottom = d.ymargintop
		d.xpadding = gtkXPadding
		d.ypadding = gtkYPadding
	}
	return d
}

func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
	// no need for coordinate conversion with gtk+
}