tui/views/view_text.go

29 lines
494 B
Go
Raw Permalink Normal View History

2021-01-10 21:52:29 +01:00
package views
import (
2023-04-24 11:55:04 +02:00
"git.milar.in/milarin/tui"
2021-01-10 21:52:29 +01:00
)
2022-04-02 13:01:41 +02:00
// TextView is a tui.View which prints text
2021-01-10 21:52:29 +01:00
type TextView struct {
tui.ViewTmpl
Text string
}
var _ tui.View = &TextView{}
func NewTextView(text string) *TextView {
return &TextView{
Text: text,
}
}
2022-04-02 13:01:41 +02:00
func (v *TextView) Draw(buf *tui.ViewBuffer) {
v.ViewTmpl.Draw(buf)
tui.WriteMultiLineString(buf, v.Text, v.Style(), 0, 0)
}
2022-04-02 13:01:41 +02:00
func (v *TextView) Layout() (prefWidth, prefHeight int) {
return tui.MeasureMultiLineString(v.Text)
}