]> git.0d.be Git - barnard.git/blob - uiterm/label.go
uiterm: prefix View methods with ui
[barnard.git] / uiterm / label.go
1 package uiterm
2
3 import (
4         "strings"
5
6         "github.com/nsf/termbox-go"
7 )
8
9 type Label struct {
10         Text string
11         Fg   Attribute
12         Bg   Attribute
13
14         ui *Ui
15         x0, y0, x1, y1 int
16 }
17
18 func (l *Label) uiInitialize(ui *Ui) {
19         l.ui = ui
20 }
21
22 func (l *Label) uiSetActive(active bool) {
23 }
24
25 func (l *Label) uiSetBounds(x0, y0, x1, y1 int) {
26         l.x0 = x0
27         l.y0 = y0
28         l.x1 = x1
29         l.y1 = y1
30 }
31
32 func (l *Label) uiDraw() {
33         reader := strings.NewReader(l.Text)
34         for y := l.y0; y < l.y1; y++ {
35                 for x := l.x0; x < l.x1; x++ {
36                         var chr rune
37                         if ch, _, err := reader.ReadRune(); err != nil {
38                                 chr = ' '
39                         } else {
40                                 chr = ch
41                         }
42                         termbox.SetCell(x, y, chr, termbox.Attribute(l.Fg), termbox.Attribute(l.Bg))
43                 }
44         }
45 }
46
47 func (l *Label) uiKeyEvent(mod Modifier, key Key) {
48 }
49
50 func (l *Label) uiCharacterEvent(chr rune) {
51 }