Started the work I guess.
This commit is contained in:
parent
f8e3f12ab0
commit
eef149060f
|
@ -0,0 +1,14 @@
|
||||||
|
// 11 december 2015
|
||||||
|
|
||||||
|
#ifndef __UI_INTEROP_H__
|
||||||
|
#define __UI_INTEROP_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern char *interopInit(void);
|
||||||
|
extern void interopFreeStr(char *);
|
||||||
|
extern void interopRun(void);
|
||||||
|
extern void interopQuit(void);
|
||||||
|
extern void interopQueueMain(uintptr_t);
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,8 @@
|
||||||
|
// +build !windows
|
||||||
|
// +build !darwin
|
||||||
|
|
||||||
|
// 11 december 2015
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
// #cgo LDFLAGS: -L. -lui -lpthread
|
|
@ -0,0 +1,60 @@
|
||||||
|
// 11 december 2015
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #include "interop.h"
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// Main initializes package ui, runs f to set up the program,
|
||||||
|
// and executes the GUI main loop. f should set up the program's
|
||||||
|
// initial state: open the main window, create controls, and set up
|
||||||
|
// events. It should then return, at which point Main will
|
||||||
|
// process events until Quit is called, at which point Main will return
|
||||||
|
// nil. If package ui fails to initialize, Main returns an appropriate
|
||||||
|
// error.
|
||||||
|
func Main(f func()) error {
|
||||||
|
errchan := make(chan error)
|
||||||
|
go start(errchan, f)
|
||||||
|
return <-errchan
|
||||||
|
}
|
||||||
|
|
||||||
|
func start(errchan chan error, f func()) {
|
||||||
|
estr := C.interopInit()
|
||||||
|
if estr != "" {
|
||||||
|
errchan <- errors.New(C.GoString(estr))
|
||||||
|
C.interopFreeStr(estr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
QueueMain(f)
|
||||||
|
C.interopRun()
|
||||||
|
errchan <- nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quit queues an exit from the GUI thread. It does not exit the
|
||||||
|
// program. Quit must be called from the GUI thread.
|
||||||
|
func Quit() {
|
||||||
|
C.interopQuit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueueMain queues f to be executed on the GUI thread when
|
||||||
|
// next possible. It returns immediately; that is, it does not wait
|
||||||
|
// for the function to actually be executed. QueueMain is the only
|
||||||
|
// function that can be called from other goroutines, and its
|
||||||
|
// primary purpose is to allow communication between other
|
||||||
|
// goroutines and the GUI thread. Calling QueueMain after Quit
|
||||||
|
// has been called results in undefined behavior.
|
||||||
|
func QueueMain(f func()) {
|
||||||
|
n := interoperAdd(f)
|
||||||
|
C.interopQueueMain(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export interopDoQueued
|
||||||
|
func interopDoQueued(n C.uintptr_t) {
|
||||||
|
ff := interoperTake(n)
|
||||||
|
f := ff.(func())
|
||||||
|
f()
|
||||||
|
}
|
Loading…
Reference in New Issue