From cab3771e17286788913255a6abe858b476166837 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Feb 2018 21:17:26 -0500 Subject: Pull main aerc UI into widget --- widgets/aerc.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 widgets/aerc.go (limited to 'widgets') diff --git a/widgets/aerc.go b/widgets/aerc.go new file mode 100644 index 0000000..2168e61 --- /dev/null +++ b/widgets/aerc.go @@ -0,0 +1,91 @@ +package widgets + +import ( + "log" + "time" + + tb "github.com/nsf/termbox-go" + + libui "git.sr.ht/~sircmpwn/aerc2/lib/ui" +) + +type Aerc struct { + grid *libui.Grid + tabs *libui.Tabs + statusbar *libui.Stack + statusline *StatusLine + interactive libui.Interactive +} + +func NewAerc(logger *log.Logger) *Aerc { + tabs := libui.NewTabs() + tabs.Add(libui.NewFill('★'), "白い星") + tabs.Add(libui.NewFill('☆'), "empty stars") + + grid := libui.NewGrid().Rows([]libui.GridSpec{ + libui.GridSpec{libui.SIZE_EXACT, 1}, + libui.GridSpec{libui.SIZE_WEIGHT, 1}, + libui.GridSpec{libui.SIZE_EXACT, 1}, + }).Columns([]libui.GridSpec{ + libui.GridSpec{libui.SIZE_EXACT, 20}, + libui.GridSpec{libui.SIZE_WEIGHT, 1}, + }) + + // TODO: move sidebar into tab content, probably + grid.AddChild(libui.NewText("aerc"). + Strategy(libui.TEXT_CENTER). + Color(tb.ColorBlack, tb.ColorWhite)) + // sidebar placeholder: + grid.AddChild(libui.NewBordered( + libui.NewFill('.'), libui.BORDER_RIGHT)).At(1, 0).Span(2, 1) + grid.AddChild(tabs.TabStrip).At(0, 1) + grid.AddChild(tabs.TabContent).At(1, 1) + + statusbar := libui.NewStack() + grid.AddChild(statusbar).At(2, 1) + + statusline := NewStatusLine() + statusline.Push("test status!", 6 * time.Second) + statusline.Push("test error!", 3 * time.Second). + Color(tb.ColorRed, tb.ColorBlack) + statusbar.Push(statusline) + + exline := NewExLine(func(command string) { + statusbar.Pop() + logger.Printf("TODO: execute command: %s\n", command) + }, func() { + statusbar.Pop() + }) + statusbar.Push(exline) + + go (func() { + for { + time.Sleep(1 * time.Second) + tabs.Select((tabs.Selected + 1) % 2) + } + })() + + return &Aerc{ + grid: grid, + interactive: exline, + statusbar: statusbar, + statusline: statusline, + tabs: tabs, + } +} + +func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) { + aerc.grid.OnInvalidate(onInvalidate) +} + +func (aerc *Aerc) Invalidate() { + aerc.grid.Invalidate() +} + +func (aerc *Aerc) Draw(ctx *libui.Context) { + aerc.grid.Draw(ctx) +} + +func (aerc *Aerc) Event(event tb.Event) bool { + return aerc.interactive.Event(event) +} -- cgit 1.4.1-2-gfad0 a href='/akkartik/mu/tree/html?h=main&id=c4c30c7dc92ad8f5c00bf8facaa089b4ed9cab53'>html/018constant.cc.html
blob: 1f922757a908fbbd85f0c26e31fc23472159e44b (plain) (blame)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127