31 lines
628 B
Go
31 lines
628 B
Go
|
package views
|
||
|
|
||
|
import (
|
||
|
"git.milar.in/milarin/gui"
|
||
|
)
|
||
|
|
||
|
// TextView is a gui.View which prints text
|
||
|
type TextView struct {
|
||
|
gui.ViewTmpl
|
||
|
Text string
|
||
|
}
|
||
|
|
||
|
var _ gui.View = &TextView{}
|
||
|
|
||
|
func NewTextView(text string) *TextView {
|
||
|
return &TextView{
|
||
|
Text: text,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (v *TextView) Layout(ctx gui.AppContext) (prefWidth, prefHeight int) {
|
||
|
s := ctx.MeasureString(v.Text, v.FontFace(ctx)).Size()
|
||
|
return s.X, s.Y
|
||
|
}
|
||
|
|
||
|
func (v *TextView) Draw(img *gui.Image, ctx gui.AppContext) {
|
||
|
v.ViewTmpl.Draw(img, ctx)
|
||
|
s := ctx.MeasureString(v.Text, v.FontFace(ctx))
|
||
|
img.DrawString(v.Text, v.FontFace(ctx), 0, -s.Min.Y, v.Foreground(ctx))
|
||
|
}
|