-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbreakpoints_panel.go
101 lines (81 loc) · 2.38 KB
/
breakpoints_panel.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"sort"
. "github.com/emad-elsaid/debugger/ui"
"golang.org/x/exp/shiny/materialdesign/icons"
)
var (
BreakPointColor = DangerColor
BreakPointDisabledColor = MixColor(BreakPointColor, WHITE, 50)
IconBreakPoint = Icon(icons.AVFiberManualRecord, BreakPointColor)
IconBreakPointDisabled = Icon(icons.AVFiberManualRecord, BreakPointDisabledColor)
IconDelete = Icon(icons.ContentClear, DangerColor)
)
type BreakpointsPanel struct {
BreakpointsList ClickableList
EnableAll Clickable
DisableAll Clickable
ClearAll Clickable
Clickables Clickables
}
func NewBreakpointsPanel() BreakpointsPanel {
return BreakpointsPanel{
BreakpointsList: NewClickableList(),
Clickables: NewClickables(),
}
}
func (b *BreakpointsPanel) Layout(d *Debugger) W {
return Rows(
Rigid(b.Toolbar(d)),
Flexed(1, b.BreakpointsPanel(d)),
)
}
func (b *BreakpointsPanel) BreakpointsPanel(d *Debugger) W {
breakpoints := d.Breakpoints()
sort.Slice(breakpoints, func(i, j int) bool {
return breakpoints[i].ID < breakpoints[j].ID
})
IconFont := FontEnlarge(2)
elem := func(c C, i int) D {
r := breakpoints[i]
id := fmt.Sprintf("breakpoint-%d", r.ID)
delId := fmt.Sprintf("breakpoint-del-%d", r.ID)
click := func() { d.ToggleBreakpoint(r) }
delClick := func() { d.ClearBreakpoint(r) }
return Columns(
Rigid(IconFont(Checkbox(b.Clickables.Get(id), !r.Disabled, click))),
Flexed(1,
Rows(
Rigid(Label(r.Name)),
Rigid(Wrap(Text(fmt.Sprintf("%s:%d", r.File, r.Line)), TextColor(SecondaryTextColor), MaxLines(3))),
),
),
Rigid(OnClick(b.Clickables.Get(delId), IconFont(IconDelete), delClick)),
)(c)
}
click := func(i int) {
bp := breakpoints[i]
d.SetFileLine(bp.File, bp.Line)
}
return b.BreakpointsList.Layout(len(breakpoints), elem, click)
}
func (b *BreakpointsPanel) Toolbar(d *Debugger) W {
if b.EnableAll.Clicked() {
d.EnableAllBreakpoints()
}
if b.DisableAll.Clicked() {
d.DisableAllBreakpoints()
}
if b.ClearAll.Clicked() {
d.ClearAllBreakpoints()
}
IconFont := FontEnlarge(2)
return Background(ToolbarBgColor,
Columns(
Rigid(ToolbarButton(&b.EnableAll, IconFont(IconBreakPoint), "Enable All")),
Rigid(ToolbarButton(&b.DisableAll, IconFont(IconBreakPointDisabled), "Disable All")),
Rigid(ToolbarButton(&b.ClearAll, IconFont(IconDelete), "Clear All")),
),
)
}