diff options
| author | Pietro Gagliardi <[email protected]> | 2018-08-19 17:22:12 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2018-08-19 17:22:12 -0400 |
| commit | 8281a8946556f00d1003e530f6abd0252d5e2ffb (patch) | |
| tree | a16d90ef0fd57242f06dec99a079e5ad9ac2a81f /fontbutton.go | |
| parent | bd0dbfb686436485541fc35191d23565135a4ebf (diff) | |
Added FontButton.
Diffstat (limited to 'fontbutton.go')
| -rw-r--r-- | fontbutton.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/fontbutton.go b/fontbutton.go new file mode 100644 index 0000000..c228151 --- /dev/null +++ b/fontbutton.go @@ -0,0 +1,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) + } +} |
