1
0
mirror of https://git.sr.ht/~sircmpwn/aerc synced 2024-11-23 08:32:12 +01:00
aerc/lib/ui/text.go
y0ast 03650474e2 update tcell to v2 and enable TrueColor support
Also update to the tcell v2 PaletteColor api, which should keep the chosen
theme of the user intact.

Note, that if $TRUECOLOR is defined and a truecolor given, aerc will now stop
clipping the value to one of the theme colors.
Generally this is desired behaviour though.
2020-12-18 07:23:22 +01:00

56 lines
899 B
Go

package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
)
const (
TEXT_LEFT = iota
TEXT_CENTER = iota
TEXT_RIGHT = iota
)
type Text struct {
Invalidatable
text string
strategy uint
style tcell.Style
}
func NewText(text string, style tcell.Style) *Text {
return &Text{
text: text,
style: style,
}
}
func (t *Text) Text(text string) *Text {
t.text = text
t.Invalidate()
return t
}
func (t *Text) Strategy(strategy uint) *Text {
t.strategy = strategy
t.Invalidate()
return t
}
func (t *Text) Draw(ctx *Context) {
size := runewidth.StringWidth(t.text)
x := 0
if t.strategy == TEXT_CENTER {
x = (ctx.Width() - size) / 2
}
if t.strategy == TEXT_RIGHT {
x = ctx.Width() - size
}
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', t.style)
ctx.Printf(x, 0, t.style, "%s", t.text)
}
func (t *Text) Invalidate() {
t.DoInvalidate(t)
}