Skip to content

Commit

Permalink
Migrated window.go, box.go, button.go, and checkbox.go back.
Browse files Browse the repository at this point in the history
  • Loading branch information
andlabs committed Aug 26, 2018
1 parent 8096624 commit 2bc7621
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion BBB_GOFILES/box.go → box.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"unsafe"
)

// #include "ui.h"
// #include "pkgui.h"
import "C"

// Box is a Control that holds a group of Controls horizontally
Expand Down
11 changes: 4 additions & 7 deletions BBB_GOFILES/button.go → button.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"unsafe"
)

// #include "ui.h"
// extern void doButtonOnClicked(uiButton *, void *);
// // see golang/go#19835
// typedef void (*buttonCallback)(uiButton *, void *);
// #include "pkgui.h"
import "C"

// Button is a Control that represents a button that the user can
Expand All @@ -29,7 +26,7 @@ func NewButton(text string) *Button {
b.b = C.uiNewButton(ctext)
freestr(ctext)

C.uiButtonOnClicked(b.b, C.buttonCallback(C.doButtonOnClicked), nil)
C.pkguiButtonOnClicked(b.b)

b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
return b
Expand All @@ -56,8 +53,8 @@ func (b *Button) OnClicked(f func(*Button)) {
b.onClicked = f
}

//export doButtonOnClicked
func doButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) {
//export pkguiDoButtonOnClicked
func pkguiDoButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) {
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*Button)
if b.onClicked != nil {
b.onClicked(b)
Expand Down
11 changes: 4 additions & 7 deletions BBB_GOFILES/checkbox.go → checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"unsafe"
)

// #include "ui.h"
// extern void doCheckboxOnToggled(uiCheckbox *, void *);
// // see golang/go#19835
// typedef void (*checkboxCallback)(uiCheckbox *, void *);
// #include "pkgui.h"
import "C"

// Checkbox is a Control that represents a box with a text label at its
Expand All @@ -30,7 +27,7 @@ func NewCheckbox(text string) *Checkbox {
c.c = C.uiNewCheckbox(ctext)
freestr(ctext)

C.uiCheckboxOnToggled(c.c, C.checkboxCallback(C.doCheckboxOnToggled), nil)
C.pkguiCheckboxOnToggled(c.c)

c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c)))
return c
Expand All @@ -57,8 +54,8 @@ func (c *Checkbox) OnToggled(f func(*Checkbox)) {
c.onToggled = f
}

//export doCheckboxOnToggled
func doCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) {
//export pkguiDoCheckboxOnToggled
func pkguiDoCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) {
c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Checkbox)
if c.onToggled != nil {
c.onToggled(c)
Expand Down
15 changes: 15 additions & 0 deletions pkgui.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ void pkguiOnShouldQuit(void)
{
uiOnShouldQuit(pkguiDoOnShouldQuit, NULL);
}

void pkguiWindowOnClosing(uiWindow *w)
{
uiWindowOnClosing(w, pkguiDoWindowOnClosing, NULL);
}

void pkguiButtonOnClicked(uiButton *b)
{
uiButtonOnClicked(b, pkguiDoButtonOnClicked, NULL);
}

void pkguiCheckboxOnToggled(uiCheckbox *c)
{
uiCheckboxOnToggled(c, pkguiDoCheckboxOnToggled, NULL);
}
9 changes: 9 additions & 0 deletions pkgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ extern uiInitOptions *pkguiAllocInitOptions(void);
extern void pkguiFreeInitOptions(uiInitOptions *o);
extern void pkguiQueueMain(uintptr_t n);
extern void pkguiOnShouldQuit(void);

// window.go
extern void pkguiWindowOnClosing(uiWindow *w);

// button.go
extern void pkguiButtonOnClicked(uiButton *b);

// checkbox.go
extern void pkguiCheckboxOnToggled(uiCheckbox *c);
11 changes: 4 additions & 7 deletions BBB_GOFILES/window.go → window.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"unsafe"
)

// #include "ui.h"
// extern int doWindowOnClosing(uiWindow *, void *);
// // see golang/go#19835
// typedef int (*windowOnClosingCallback)(uiWindow *, void *);
// #include "pkgui.h"
import "C"

// Window is a Control that represents a top-level window.
Expand All @@ -31,7 +28,7 @@ func NewWindow(title string, width int, height int, hasMenubar bool) *Window {
w.w = C.uiNewWindow(ctitle, C.int(width), C.int(height), frombool(hasMenubar))
freestr(ctitle)

C.uiWindowOnClosing(w.w, C.windowOnClosingCallback(C.doWindowOnClosing), nil)
C.pkguiWindowOnClosing(w.w)

w.ControlBase = NewControlBase(w, uintptr(unsafe.Pointer(w.w)))
return w
Expand Down Expand Up @@ -79,8 +76,8 @@ func (w *Window) OnClosing(f func(*Window) bool) {
w.onClosing = f
}

//export doWindowOnClosing
func doWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
//export pkguiDoWindowOnClosing
func pkguiDoWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
w := ControlFromLibui(uintptr(unsafe.Pointer(ww))).(*Window)
if w.onClosing == nil {
return 0
Expand Down

0 comments on commit 2bc7621

Please sign in to comment.