diff options
Diffstat (limited to 'go/ui/buffer.go')
| -rw-r--r-- | go/ui/buffer.go | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/go/ui/buffer.go b/go/ui/buffer.go index 8294c905..7a69766d 100644 --- a/go/ui/buffer.go +++ b/go/ui/buffer.go @@ -22,17 +22,28 @@ type Buffer struct { font *text.GoTextFace lineSpacing float64 xMargin float64 + bg color.Color + fg color.Color } func NewBuffer(x, y int, width, height int) *Buffer { - b := &Buffer{NewWidgetBase(x, y, width, height), []string{}, 0, font.Font18, 1.5, 10.} + b := &Buffer{ + NewWidgetBase(x, y, width, height), + []string{}, + 0, + font.Font18, + 1.5, + 10., + BUFFER_BACKGROUND, + BUFFER_FOREGROUND, + } b.renderImpl = func() *ebiten.Image { return b.render() } return b } func (b *Buffer) render() *ebiten.Image { img := ebiten.NewImage(b.Width, b.Height) - img.Fill(BUFFER_BACKGROUND) + img.Fill(b.bg) var y float64 = -b.font.Size for _, line := range b.lines[b.pos:] { _, h := text.Measure(line, b.font, b.font.Size*b.lineSpacing) @@ -41,7 +52,7 @@ func (b *Buffer) render() *ebiten.Image { break } op := &text.DrawOptions{} - op.ColorScale.ScaleWithColor(BUFFER_FOREGROUND) + op.ColorScale.ScaleWithColor(b.fg) op.GeoM.Translate(b.xMargin, float64(y)) op.LineSpacing = b.font.Size * b.lineSpacing text.Draw(img, line, b.font, op) @@ -58,6 +69,12 @@ func (b *Buffer) AddLine(line string) { b.AddLines([]string{line}) } +func (b *Buffer) AddText(text string) { + // TODO: auto break text + lines := []string{text} + b.AddLines(lines) +} + func (b *Buffer) ClearLines() { b.lines = []string{} b.ForceRedraw() @@ -102,3 +119,13 @@ func (b *Buffer) Scroll(x, y int) { } b.ForceRedraw() } + +func (b *Buffer) Bg(bg color.Color) *Buffer { + b.bg = bg + return b +} + +func (b *Buffer) Fg(fg color.Color) *Buffer { + b.fg = fg + return b +} |
