vendor raymenu dependencies
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
Copyright (C) 2016 Milan Nikolic (gen2brain)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
## raygui [](https://godoc.org/github.com/gen2brain/raylib-go/raygui)
|
||||
|
||||
raygui is simple and easy-to-use IMGUI (immediate mode GUI API) library.
|
||||
|
||||
|
||||
### controls_test_suite
|
||||
|
||||

|
||||
|
||||
|
||||
### scroll_panel
|
||||
|
||||

|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package raygui
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -std=gnu99 -Wno-unused-result
|
||||
*/
|
||||
import "C"
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package raygui
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
// Code from https://blog.pytool.com/language/golang/cgo/go-cgo-string/
|
||||
|
||||
static char** make_str_array(int size) {
|
||||
return calloc(sizeof(char*), size);
|
||||
}
|
||||
|
||||
static int len_str_array(char **arr) {
|
||||
int i = 0;
|
||||
while (arr[i] != NULL) i++;
|
||||
return i+1; // NULL does count
|
||||
}
|
||||
|
||||
static void set_str_array(char **arr, int idx, char *s) {
|
||||
arr[idx] = s;
|
||||
}
|
||||
|
||||
static void free_str_array(char **arr, int size) {
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
free(arr[i]);
|
||||
}
|
||||
free(arr);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// CStringArray represents an array of pointers to NULL terminated C strings,
|
||||
// the array itself is terminated with a NULL
|
||||
type CStringArray struct {
|
||||
Pointer unsafe.Pointer
|
||||
Length int
|
||||
}
|
||||
|
||||
// NewCStringArray returns an instance of CStringArray
|
||||
func NewCStringArray() *CStringArray {
|
||||
return &CStringArray{}
|
||||
}
|
||||
|
||||
// NewCStringArrayFromSlice makes an instance of CStringArray then copy the
|
||||
// input slice to it.
|
||||
func NewCStringArrayFromSlice(ss []string) *CStringArray {
|
||||
var arr CStringArray
|
||||
arr.Copy(ss)
|
||||
return &arr
|
||||
}
|
||||
|
||||
func NewCStringArrayFromPointer(p unsafe.Pointer) *CStringArray {
|
||||
return &CStringArray{
|
||||
Length: int(C.len_str_array((**C.char)(p))),
|
||||
Pointer: p,
|
||||
}
|
||||
}
|
||||
|
||||
// ToSlice converts CStringArray to Go slice of strings
|
||||
func (arr *CStringArray) ToSlice() []string {
|
||||
if arr.Length == 0 || arr.Pointer == nil {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
var ss []string
|
||||
var cs **C.char
|
||||
defer C.free(unsafe.Pointer(cs))
|
||||
p := uintptr(arr.Pointer)
|
||||
for {
|
||||
cs = *(***C.char)(unsafe.Pointer(&p))
|
||||
if *cs == nil { // skip NULL - the last element
|
||||
break
|
||||
}
|
||||
ss = append(ss, C.GoString(*cs))
|
||||
p += unsafe.Sizeof(p)
|
||||
}
|
||||
|
||||
return ss
|
||||
}
|
||||
|
||||
// Copy converts Go slice of strings to C underlying struct of CStringArray
|
||||
func (arr *CStringArray) Copy(ss []string) {
|
||||
arr.Length = len(ss) + 1 // one more element for NULL at the end
|
||||
arr.Pointer = unsafe.Pointer(C.make_str_array(C.int(arr.Length)))
|
||||
|
||||
for i, s := range ss {
|
||||
cs := C.CString(s) // will be free by Free() method
|
||||
C.set_str_array((**C.char)(arr.Pointer), C.int(i), cs)
|
||||
}
|
||||
}
|
||||
|
||||
// Free frees C underlying struct of CStringArray
|
||||
// MUST call this method after using CStringArray
|
||||
// Exception: If you use NewCStringArrayFromPointer() to create CStringArray object
|
||||
// and you use other way to free C underlying structure pointed by the pointer,
|
||||
// then don't need to call Free()
|
||||
func (arr *CStringArray) Free() {
|
||||
C.free_str_array((**C.char)(arr.Pointer), C.int(arr.Length))
|
||||
}
|
||||
+1538
File diff suppressed because it is too large
Load Diff
+5987
File diff suppressed because it is too large
Load Diff
+1727
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user