forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformIO.go
More file actions
75 lines (67 loc) · 2.1 KB
/
PlatformIO.go
File metadata and controls
75 lines (67 loc) · 2.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package imgui
// #include "wrapper/PlatformIO.h"
import "C"
// PlatformIO is the platform (SLD, GLFW, etc.) specific IO for Imgui. Access via CurrentPlatformIO().
type PlatformIO struct {
handle C.IggPlatformIO
}
// CurrentPlatformIO returns the current PlatformIO.
func CurrentPlatformIO() PlatformIO {
return PlatformIO{handle: C.iggGetCurrentPlatformIO()}
}
// Clipboard describes the access to the text clipboard of the window manager.
type Clipboard interface {
// Text returns the current text from the clipboard, if available.
ClipboardText() (string, error)
// SetText sets the text as the current text on the clipboard.
SetClipboardText(value string)
}
var clipboard Clipboard
var freeClipboardString func()
// SetClipboard registers a clipboard for text copy/paste actions.
// If no clipboard is set, then a fallback implementation may be used, if available for the OS.
// To disable clipboard handling overall, pass nil as the Clipboard.
//
// Since ImGui queries the clipboard text via a return value, the wrapper has to hold the
// current clipboard text as a copy in memory. This memory will be freed at the next clipboard operation.
func (io PlatformIO) SetClipboard(board Clipboard) {
if freeClipboardString != nil {
freeClipboardString()
freeClipboardString = nil
}
if board != nil {
clipboard = board
C.iggPlatformIoRegisterClipboardFunctions(io.handle)
} else {
clipboard = nil
C.iggPlatformIoClearClipboardFunctions(io.handle)
}
}
//export iggPlatformIoGetClipboardText
func iggPlatformIoGetClipboardText(_ C.IggPlatformIO) *C.char {
if freeClipboardString != nil {
freeClipboardString()
freeClipboardString = nil
}
if clipboard == nil {
return nil
}
text, err := clipboard.ClipboardText()
if err != nil {
return nil
}
textPtr, textFin := wrapString(text)
freeClipboardString = textFin
return textPtr
}
//export iggPlatformIoSetClipboardText
func iggPlatformIoSetClipboardText(_ C.IggPlatformIO, text *C.char) {
if freeClipboardString != nil {
freeClipboardString()
freeClipboardString = nil
}
if clipboard == nil {
return
}
clipboard.SetClipboardText(C.GoString(text))
}