summaryrefslogtreecommitdiff
path: root/button.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-11 16:18:01 -0400
committerPietro Gagliardi <[email protected]>2018-08-11 16:18:01 -0400
commit308e253e0f7873710bf77312d7a12c576aaa9781 (patch)
treefd20704da886ce82a3621ec1502897a8766b11be /button.go
parent0f75ebb5fa7a12bd1df26622ed3f5544a9d1d32b (diff)
Moved the existing .go files out of the way and replaced ui.h with the alpha4 ui.h.
Diffstat (limited to 'button.go')
-rw-r--r--button.go114
1 files changed, 0 insertions, 114 deletions
diff --git a/button.go b/button.go
deleted file mode 100644
index 2696f82..0000000
--- a/button.go
+++ /dev/null
@@ -1,114 +0,0 @@
-// 12 december 2015
-
-package ui
-
-import (
- "unsafe"
-)
-
-// #include "ui.h"
-// extern void doButtonOnClicked(uiButton *, void *);
-// static inline void realuiButtonOnClicked(uiButton *b)
-// {
-// uiButtonOnClicked(b, doButtonOnClicked, NULL);
-// }
-import "C"
-
-// no need to lock this; only the GUI thread can access it
-var buttons = make(map[*C.uiButton]*Button)
-
-// Button is a Control that represents a button that the user can
-// click to perform an action. A Button has a text label that should
-// describe what the button does.
-type Button struct {
- c *C.uiControl
- b *C.uiButton
-
- onClicked func(*Button)
-}
-
-// NewButton creates a new Button with the given text as its label.
-func NewButton(text string) *Button {
- b := new(Button)
-
- ctext := C.CString(text)
- b.b = C.uiNewButton(ctext)
- b.c = (*C.uiControl)(unsafe.Pointer(b.b))
- freestr(ctext)
-
- C.realuiButtonOnClicked(b.b)
- buttons[b.b] = b
-
- return b
-}
-
-// Destroy destroys the Button.
-func (b *Button) Destroy() {
- delete(buttons, b.b)
- C.uiControlDestroy(b.c)
-}
-
-// LibuiControl returns the libui uiControl pointer that backs
-// the Button. This is only used by package ui itself and should
-// not be called by programs.
-func (b *Button) LibuiControl() uintptr {
- return uintptr(unsafe.Pointer(b.c))
-}
-
-// Handle returns the OS-level handle associated with this Button.
-// On Windows this is an HWND of a standard Windows API BUTTON
-// class (as provided by Common Controls version 6).
-// On GTK+ this is a pointer to a GtkButton.
-// On OS X this is a pointer to a NSButton.
-func (b *Button) Handle() uintptr {
- return uintptr(C.uiControlHandle(b.c))
-}
-
-// Show shows the Button.
-func (b *Button) Show() {
- C.uiControlShow(b.c)
-}
-
-// Hide hides the Button.
-func (b *Button) Hide() {
- C.uiControlHide(b.c)
-}
-
-// Enable enables the Button.
-func (b *Button) Enable() {
- C.uiControlEnable(b.c)
-}
-
-// Disable disables the Button.
-func (b *Button) Disable() {
- C.uiControlDisable(b.c)
-}
-
-// Text returns the Button's text.
-func (b *Button) Text() string {
- ctext := C.uiButtonText(b.b)
- text := C.GoString(ctext)
- C.uiFreeText(ctext)
- return text
-}
-
-// SetText sets the Button's text to text.
-func (b *Button) SetText(text string) {
- ctext := C.CString(text)
- C.uiButtonSetText(b.b, ctext)
- freestr(ctext)
-}
-
-// OnClicked registers f to be run when the user clicks the Button.
-// Only one function can be registered at a time.
-func (b *Button) OnClicked(f func(*Button)) {
- b.onClicked = f
-}
-
-//export doButtonOnClicked
-func doButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) {
- b := buttons[bb]
- if b.onClicked != nil {
- b.onClicked(b)
- }
-}