forked from marcusolsson/tui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusbar.go
52 lines (42 loc) · 1.08 KB
/
statusbar.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
package tui
import (
"image"
)
var _ Widget = &StatusBar{}
// StatusBar is a widget to display status information.
type StatusBar struct {
WidgetBase
text string
permText string
}
// NewStatusBar returns a new StatusBar.
func NewStatusBar(text string) *StatusBar {
return &StatusBar{
text: text,
permText: "",
}
}
// Draw draws the status bar.
func (b *StatusBar) Draw(p *Painter) {
p.WithStyle("statusbar", func(p *Painter) {
p.FillRect(0, 0, b.Size().X, 1)
p.DrawText(0, 0, b.text)
p.DrawText(b.Size().X-stringWidth(b.permText), 0, b.permText)
})
}
// SizeHint returns the recommended size for the status bar.
func (b *StatusBar) SizeHint() image.Point {
return image.Point{10, 1}
}
// SizePolicy returns the default layout behavior.
func (b *StatusBar) SizePolicy() (SizePolicy, SizePolicy) {
return Preferred, Maximum
}
// SetText sets the text content of the status bar.
func (b *StatusBar) SetText(text string) {
b.text = text
}
// SetPermanentText sets the permanent text of the status bar.
func (b *StatusBar) SetPermanentText(text string) {
b.permText = text
}