forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_unix.go
70 lines (57 loc) · 1.25 KB
/
container_unix.go
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
// +build !windows,!darwin
// 23 february 2014
package ui
import (
"unsafe"
)
// #include "gtk_unix.h"
import "C"
// TODO avoid direct access to contents?
type container struct {
widget *C.GtkWidget
container *C.GtkContainer
resize func(x int, y int, width int, height int, d *sizing)
margined bool
}
type sizing struct {
sizingbase
// for size calculations
// gtk+ needs nothing
// for the actual resizing
// gtk+ needs nothing
}
func newContainer() *container {
c := new(container)
c.widget = C.newContainer(unsafe.Pointer(c))
c.container = (*C.GtkContainer)(unsafe.Pointer(c.widget))
return c
}
func (c *container) parent() *controlParent {
return &controlParent{c.container}
}
//export containerResize
func containerResize(data unsafe.Pointer, aorig *C.GtkAllocation) {
c := (*container)(data)
d := beginResize()
// copy aorig
a := *aorig
if c.margined {
a.x += C.int(gtkXMargin)
a.y += C.int(gtkYMargin)
a.width -= C.int(gtkXMargin) * 2
a.height -= C.int(gtkYMargin) * 2
}
c.resize(int(a.x), int(a.y), int(a.width), int(a.height), d)
}
const (
gtkXMargin = 12
gtkYMargin = 12
gtkXPadding = 12
gtkYPadding = 6
)
func beginResize() (d *sizing) {
d = new(sizing)
d.xpadding = gtkXPadding
d.ypadding = gtkYPadding
return d
}