-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
55 lines (45 loc) · 1.44 KB
/
Copy pathdebug.go
File metadata and controls
55 lines (45 loc) · 1.44 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
package dfx
import (
"fmt"
"github.com/AllenDang/cimgui-go/imgui"
)
type SizeDebugger struct {
Margin float32
disabled bool
actionRegistry *ActionRegistry
}
func NewSizeDebugger() *SizeDebugger {
sd := &SizeDebugger{
Margin: 4,
actionRegistry: NewActionRegistry(),
}
sd.actionRegistry.MustRegister("disable", "Shift+Alt+D", func() { sd.disabled = !sd.disabled })
return sd
}
func (sd *SizeDebugger) Draw(state *State) {
cursor := imgui.WindowPos()
dl := imgui.WindowDrawList()
color := imgui.ColorConvertFloat4ToU32(imgui.CurrentStyle().Colors()[imgui.ColHeaderHovered])
ul := cursor.Add(imgui.Vec2{X: sd.Margin, Y: sd.Margin})
ll := cursor.Add(imgui.Vec2{X: sd.Margin, Y: state.Size.Y - sd.Margin})
ur := cursor.Add(imgui.Vec2{X: state.Size.X - sd.Margin, Y: sd.Margin})
lr := cursor.Add(imgui.Vec2{X: state.Size.X - sd.Margin, Y: state.Size.Y - sd.Margin})
// crosses
dl.AddLine(ul, lr, color)
dl.AddLine(ur, ll, color)
// outer box
dl.AddLine(ul, ur, color)
dl.AddLine(ur, lr, color)
dl.AddLine(lr, ll, color)
dl.AddLine(ll, ul, color)
if !sd.disabled {
// label
label := fmt.Sprintf("( x: %v, y: %v )", state.Size.X, state.Size.Y)
labelSize := imgui.CalcTextSize(label)
imgui.SetCursorPos(imgui.Vec2{X: (state.Size.X / 2) - (labelSize.X / 2), Y: (state.Size.Y / 2) - (labelSize.Y / 2)})
imgui.TextUnformatted(label)
}
}
func (sd *SizeDebugger) Actions() *ActionRegistry {
return sd.actionRegistry
}