From 2bc76219286dfe39949772ceee4dbd9560ec2c1f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 26 Aug 2018 13:24:47 -0400 Subject: [PATCH] Migrated window.go, box.go, button.go, and checkbox.go back. --- BBB_GOFILES/box.go => box.go | 2 +- BBB_GOFILES/button.go => button.go | 11 ++++------- BBB_GOFILES/checkbox.go => checkbox.go | 11 ++++------- pkgui.c | 15 +++++++++++++++ pkgui.h | 9 +++++++++ BBB_GOFILES/window.go => window.go | 11 ++++------- 6 files changed, 37 insertions(+), 22 deletions(-) rename BBB_GOFILES/box.go => box.go (98%) rename BBB_GOFILES/button.go => button.go (79%) rename BBB_GOFILES/checkbox.go => checkbox.go (82%) rename BBB_GOFILES/window.go => window.go (90%) diff --git a/BBB_GOFILES/box.go b/box.go similarity index 98% rename from BBB_GOFILES/box.go rename to box.go index 65421d4..99be5cb 100644 --- a/BBB_GOFILES/box.go +++ b/box.go @@ -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 diff --git a/BBB_GOFILES/button.go b/button.go similarity index 79% rename from BBB_GOFILES/button.go rename to button.go index 630c684..9e39918 100644 --- a/BBB_GOFILES/button.go +++ b/button.go @@ -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 @@ -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 @@ -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) diff --git a/BBB_GOFILES/checkbox.go b/checkbox.go similarity index 82% rename from BBB_GOFILES/checkbox.go rename to checkbox.go index 8177226..22c4c5f 100644 --- a/BBB_GOFILES/checkbox.go +++ b/checkbox.go @@ -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 @@ -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 @@ -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) diff --git a/pkgui.c b/pkgui.c index 586f5e9..b6871a3 100644 --- a/pkgui.c +++ b/pkgui.c @@ -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); +} diff --git a/pkgui.h b/pkgui.h index 9aaa394..6a0261b 100644 --- a/pkgui.h +++ b/pkgui.h @@ -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); diff --git a/BBB_GOFILES/window.go b/window.go similarity index 90% rename from BBB_GOFILES/window.go rename to window.go index a40ddd9..d597323 100644 --- a/BBB_GOFILES/window.go +++ b/window.go @@ -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. @@ -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 @@ -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