forked from AllenDang/giu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryEditor.go
60 lines (50 loc) · 1.46 KB
/
MemoryEditor.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
package giu
import (
"github.com/AllenDang/imgui-go"
)
type memoryEditorState struct {
editor imgui.MemoryEditor
}
// Dispose implements Disposable interface.
func (s *memoryEditorState) Dispose() {
// noop
}
// MemoryEditorWidget - Mini memory editor for Dear ImGui
// (to embed in your game/tools)
//
// Right-click anywhere to access the Options menu!
// You can adjust the keyboard repeat delay/rate in ImGuiIO.
// The code assume a mono-space font for simplicity!
// If you don't use the default font, use ImGui::PushFont()/PopFont() to switch to a mono-space font before calling this.
type MemoryEditorWidget struct {
id string
contents []byte
}
// MemoryEditor creates nwe memory editor widget.
func MemoryEditor() *MemoryEditorWidget {
return &MemoryEditorWidget{
id: GenAutoID("memoryEditor"),
}
}
// Contents sets editor's conents.
func (me *MemoryEditorWidget) Contents(contents []byte) *MemoryEditorWidget {
me.contents = contents
return me
}
// Build implements widget inetrface.
func (me *MemoryEditorWidget) Build() {
me.getState().editor.DrawContents(me.contents)
}
func (me *MemoryEditorWidget) getState() (state *memoryEditorState) {
if s := Context.GetState(me.id); s == nil {
state = &memoryEditorState{
editor: imgui.NewMemoryEditor(),
}
Context.SetState(me.id, state)
} else {
var ok bool
state, ok = s.(*memoryEditorState)
Assert(ok, "MemoryEditorWidget", "getState", "incorrect state type recovered.")
}
return state
}