/
etc.go
53 lines (44 loc) · 1.12 KB
/
etc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package nk
/*
#include "nuklear.h"
*/
import "C"
import "bytes"
var (
clipboardPlugin ClipboardPlugin
)
type ClipboardPlugin interface {
GetText() string
SetText(content string)
}
//export igClipboardPaste
func igClipboardPaste(user C.nk_handle, edit *TextEdit) {
if clipboardPlugin != nil {
content := clipboardPlugin.GetText()
NkTexteditPaste(edit, content, int32(len(content)))
}
}
//export igClipboardCopy
func igClipboardCopy(user C.nk_handle, text *C.char, len C.int) {
if clipboardPlugin != nil {
clipboardPlugin.SetText(C.GoStringN(text, len))
}
}
// Allocated is the total amount of memory allocated.
func (b *Buffer) Allocated() int {
return (int)(b.allocated)
}
// Size is the current size of the buffer.
func (b *Buffer) Size() int {
return (int)(b.size)
}
// Type is the memory management type of the buffer.
func (b *Buffer) Type() AllocationType {
return (AllocationType)(b._type)
}
func (t *TextEdit) GetGoString() string {
nkstr := t.GetString()
b := C.GoBytes(*nkstr.GetBuffer().GetMemory().GetPtr(), C.int(*nkstr.GetBuffer().GetSize()))
r := bytes.Runes(b)[:*nkstr.GetLen()]
return string(r)
}