-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
53 lines (47 loc) · 1.11 KB
/
debug.go
File metadata and controls
53 lines (47 loc) · 1.11 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
package awtree
type DebugEvent struct {
Detector string `json:"detector"`
Accepted bool `json:"accepted"`
Reason string `json:"reason"`
Label string `json:"label,omitempty"`
Bounds *Rect `json:"bounds,omitempty"`
}
type DebugInfo struct {
Config DetectConfig `json:"config"`
Events []DebugEvent `json:"events"`
}
type debugCollector struct {
info *DebugInfo
}
func newDebugCollector(cfg DetectConfig) *debugCollector {
if !cfg.Debug {
return nil
}
return &debugCollector{info: &DebugInfo{Config: cfg, Events: make([]DebugEvent, 0, 32)}}
}
func (d *debugCollector) accept(detector string, el Element, reason string) {
if d == nil {
return
}
bounds := el.Bounds
d.info.Events = append(d.info.Events, DebugEvent{
Detector: detector,
Accepted: true,
Reason: reason,
Label: el.Label,
Bounds: &bounds,
})
}
func (d *debugCollector) reject(detector, reason string, bounds Rect, label string) {
if d == nil {
return
}
b := bounds
d.info.Events = append(d.info.Events, DebugEvent{
Detector: detector,
Accepted: false,
Reason: reason,
Label: label,
Bounds: &b,
})
}