forked from AllenDang/giu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemoryEditor.go
56 lines (46 loc) · 1.34 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
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 contents.
func (me *MemoryEditorWidget) Contents(contents []byte) *MemoryEditorWidget {
me.contents = contents
return me
}
// Build implements widget interface.
func (me *MemoryEditorWidget) Build() {
me.getState().editor.DrawContents(me.contents)
}
func (me *MemoryEditorWidget) getState() (state *memoryEditorState) {
if state = GetState[memoryEditorState](Context, me.id); state == nil {
state = &memoryEditorState{
editor: imgui.NewMemoryEditor(),
}
SetState(Context, me.id, state)
}
return state
}