Migrated window.go, box.go, button.go, and checkbox.go back.
This commit is contained in:
parent
809662459d
commit
2bc7621928
|
@ -6,7 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Box is a Control that holds a group of Controls horizontally
|
// Box is a Control that holds a group of Controls horizontally
|
|
@ -6,10 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
// extern void doButtonOnClicked(uiButton *, void *);
|
|
||||||
// // see golang/go#19835
|
|
||||||
// typedef void (*buttonCallback)(uiButton *, void *);
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Button is a Control that represents a button that the user can
|
// 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)
|
b.b = C.uiNewButton(ctext)
|
||||||
freestr(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)))
|
b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
|
||||||
return b
|
return b
|
||||||
|
@ -56,8 +53,8 @@ func (b *Button) OnClicked(f func(*Button)) {
|
||||||
b.onClicked = f
|
b.onClicked = f
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doButtonOnClicked
|
//export pkguiDoButtonOnClicked
|
||||||
func doButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) {
|
func pkguiDoButtonOnClicked(bb *C.uiButton, data unsafe.Pointer) {
|
||||||
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*Button)
|
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*Button)
|
||||||
if b.onClicked != nil {
|
if b.onClicked != nil {
|
||||||
b.onClicked(b)
|
b.onClicked(b)
|
|
@ -6,10 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
// extern void doCheckboxOnToggled(uiCheckbox *, void *);
|
|
||||||
// // see golang/go#19835
|
|
||||||
// typedef void (*checkboxCallback)(uiCheckbox *, void *);
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Checkbox is a Control that represents a box with a text label at its
|
// 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)
|
c.c = C.uiNewCheckbox(ctext)
|
||||||
freestr(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)))
|
c.ControlBase = NewControlBase(c, uintptr(unsafe.Pointer(c.c)))
|
||||||
return c
|
return c
|
||||||
|
@ -57,8 +54,8 @@ func (c *Checkbox) OnToggled(f func(*Checkbox)) {
|
||||||
c.onToggled = f
|
c.onToggled = f
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doCheckboxOnToggled
|
//export pkguiDoCheckboxOnToggled
|
||||||
func doCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) {
|
func pkguiDoCheckboxOnToggled(cc *C.uiCheckbox, data unsafe.Pointer) {
|
||||||
c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Checkbox)
|
c := ControlFromLibui(uintptr(unsafe.Pointer(cc))).(*Checkbox)
|
||||||
if c.onToggled != nil {
|
if c.onToggled != nil {
|
||||||
c.onToggled(c)
|
c.onToggled(c)
|
15
pkgui.c
15
pkgui.c
|
@ -21,3 +21,18 @@ void pkguiOnShouldQuit(void)
|
||||||
{
|
{
|
||||||
uiOnShouldQuit(pkguiDoOnShouldQuit, NULL);
|
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
pkgui.h
9
pkgui.h
|
@ -7,3 +7,12 @@ extern uiInitOptions *pkguiAllocInitOptions(void);
|
||||||
extern void pkguiFreeInitOptions(uiInitOptions *o);
|
extern void pkguiFreeInitOptions(uiInitOptions *o);
|
||||||
extern void pkguiQueueMain(uintptr_t n);
|
extern void pkguiQueueMain(uintptr_t n);
|
||||||
extern void pkguiOnShouldQuit(void);
|
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);
|
||||||
|
|
|
@ -6,10 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
// extern int doWindowOnClosing(uiWindow *, void *);
|
|
||||||
// // see golang/go#19835
|
|
||||||
// typedef int (*windowOnClosingCallback)(uiWindow *, void *);
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Window is a Control that represents a top-level window.
|
// 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))
|
w.w = C.uiNewWindow(ctitle, C.int(width), C.int(height), frombool(hasMenubar))
|
||||||
freestr(ctitle)
|
freestr(ctitle)
|
||||||
|
|
||||||
C.uiWindowOnClosing(w.w, C.windowOnClosingCallback(C.doWindowOnClosing), nil)
|
C.pkguiWindowOnClosing(w.w)
|
||||||
|
|
||||||
w.ControlBase = NewControlBase(w, uintptr(unsafe.Pointer(w.w)))
|
w.ControlBase = NewControlBase(w, uintptr(unsafe.Pointer(w.w)))
|
||||||
return w
|
return w
|
||||||
|
@ -79,8 +76,8 @@ func (w *Window) OnClosing(f func(*Window) bool) {
|
||||||
w.onClosing = f
|
w.onClosing = f
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doWindowOnClosing
|
//export pkguiDoWindowOnClosing
|
||||||
func doWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
|
func pkguiDoWindowOnClosing(ww *C.uiWindow, data unsafe.Pointer) C.int {
|
||||||
w := ControlFromLibui(uintptr(unsafe.Pointer(ww))).(*Window)
|
w := ControlFromLibui(uintptr(unsafe.Pointer(ww))).(*Window)
|
||||||
if w.onClosing == nil {
|
if w.onClosing == nil {
|
||||||
return 0
|
return 0
|
Loading…
Reference in New Issue