forked from HACKERALERT/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.go
68 lines (57 loc) · 1.76 KB
/
Context.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package imgui
import (
"errors"
)
// #include "imguiWrapper.h"
import "C"
// Context specifies a scope of ImGui.
//
// All contexts share a same FontAtlas by default.
// If you want different font atlas, you can create them and overwrite the CurrentIO.Fonts of an ImGui context.
type Context struct {
handle C.IggContext
}
// CreateContext produces a new internal state scope.
// Passing nil for the fontAtlas creates a default font.
func CreateContext(fontAtlas *FontAtlas) *Context {
var fontAtlasPtr C.IggFontAtlas
if fontAtlas != nil {
fontAtlasPtr = fontAtlas.handle()
}
return &Context{handle: C.iggCreateContext(fontAtlasPtr)}
}
func (c *Context) GetHandle() C.IggContext {
return c.handle
}
// ErrNoContext is used when no context is current.
var ErrNoContext = errors.New("no current context")
// CurrentContext returns the currently active state scope.
// Returns ErrNoContext if no context is available.
func CurrentContext() (*Context, error) {
raw := C.iggGetCurrentContext()
if raw == nil {
return nil, ErrNoContext
}
return &Context{handle: raw}, nil
}
// Destroy removes the internal state scope.
// Trying to destroy an already destroyed context does nothing.
func (context *Context) Destroy() {
if context.handle != nil {
C.iggDestroyContext(context.handle)
context.handle = nil
}
}
// ErrContextDestroyed is returned when trying to use an already destroyed context.
var ErrContextDestroyed = errors.New("context is destroyed")
// SetCurrent activates this context as the currently active state scope.
func (context Context) SetCurrent() error {
if context.handle == nil {
return ErrContextDestroyed
}
C.iggSetCurrentContext(context.handle)
return nil
}
func SetMaxWaitBeforeNextFrame(time float32) {
C.iggSetMaxWaitBeforeNextFrame(C.double(time))
}