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