summaryrefslogtreecommitdiff
path: root/redo/button_darwin.go
blob: 1e6cf3347e5c1be51cfc1e23f70caf1d73b7346b (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
72
73
74
75
76
77
78
79
80
// 16 july 2014

package ui

import (
	"unsafe"
)

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

type button struct {
	_id		C.id
	clicked	*event
}

func newButton(text string) *button {
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))
	b := &button{
		_id:			C.newButton(),
		clicked:		newEvent(),
	}
	C.buttonSetText(b._id, ctext)
	C.buttonSetDelegate(b._id, unsafe.Pointer(b))
	return b
}

func (b *button) OnClicked(e func()) {
	b.clicked.set(e)
}

func (b *button) Text() string {
	return C.GoString(C.buttonText(b._id))
}

func (b *button) SetText(text string) {
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))
	C.buttonSetText(b._id, ctext)
}

//export buttonClicked
func buttonClicked(xb unsafe.Pointer) {
	b := (*button)(unsafe.Pointer(xb))
	b.clicked.fire()
	println("button clicked")
}

func (b *button) id() C.id {
	return b._id
}

func (b *button) setParent(p *controlParent) {
	basesetParent(b, p)
}

func (b *button) containerShow() {
	basecontainerShow(b)
}

func (b *button) containerHide() {
	basecontainerHide(b)
}

func (b *button) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
	return baseallocate(b, x, y, width, height, d)
}

func (b *button) preferredSize(d *sizing) (width, height int) {
	return basepreferredSize(b, d)
}

func (b *button) commitResize(a *allocation, d *sizing) {
	basecommitResize(b, a, d)
}

func (b *button) getAuxResizeInfo(d *sizing) {
	basegetAuxResizeInfo(b, d)
}