summaryrefslogtreecommitdiff
path: root/BBB_GOFILES/fontbutton.go
blob: c2281514357cd650613d6a285d8a921675298f74 (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
// 12 december 2015

package ui

import (
	"unsafe"
)

// #include <stdlib.h>
// #include "ui.h"
// #include "util.h"
// extern void doFontButtonOnChanged(uiFontButton *, void *);
// // see golang/go#19835
// typedef void (*fontButtonCallback)(uiFontButton *, void *);
// static inline uiFontDescriptor *pkguiNewFontDescriptor(void)
// {
// 	return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor));
// }
// static inline void pkguiFreeFontDescriptor(uiFontDescriptor *fd)
// {
// 	free(fd);
// }
import "C"

// FontButton is a Control that represents a button that the user can
// click to select a font.
type FontButton struct {
	ControlBase
	b	*C.uiFontButton
	onChanged		func(*FontButton)
}

// NewFontButton creates a new FontButton.
func NewFontButton() *FontButton {
	b := new(FontButton)

	b.b = C.uiNewFontButton()

	C.uiFontButtonOnChanged(b.b, C.fontButtonCallback(C.doFontButtonOnChanged), nil)

	b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
	return b
}

// Font returns the font currently selected in the FontButton.
func (b *FontButton) Font() *FontDescriptor {
	cfd := C.pkguiNewFontDescriptor()
	defer C.pkguiFreeFontDescriptor(cfd)
	C.uiFontButtonFont(b.b, cfd)
	defer C.uiFreeFontButtonFont(cfd)
	fd := &FontDescriptor{}
	fd.fromLibui(cfd)
	return fd
}

// OnChanged registers f to be run when the user changes the
// currently selected font in the FontButton. Only one function can
// be registered at a time.
func (b *FontButton) OnChanged(f func(*FontButton)) {
	b.onChanged = f
}

//export doFontButtonOnChanged
func doFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) {
	b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*FontButton)
	if b.onChanged != nil {
		b.onChanged(b)
	}
}