add Text.LineHeight and text.TabWidth

This commit is contained in:
faiface 2017-05-03 21:04:18 +02:00
parent e2a16764c4
commit 6a7500959f
1 changed files with 21 additions and 6 deletions

View File

@ -40,10 +40,13 @@ type Text struct {
Orig pixel.Vec Orig pixel.Vec
Dot pixel.Vec Dot pixel.Vec
color pixel.RGBA atlas atlas
color pixel.RGBA
lineHeight float64
tabWidth float64
prevR rune prevR rune
atlas atlas
glyph pixel.TrianglesData glyph pixel.TrianglesData
tris pixel.TrianglesData tris pixel.TrianglesData
d pixel.Drawer d pixel.Drawer
@ -55,9 +58,13 @@ func New(face font.Face, runeSets ...[]rune) *Text {
runes = append(runes, set...) runes = append(runes, set...)
} }
atlas := makeAtlas(face, runes)
txt := &Text{ txt := &Text{
color: pixel.Alpha(1), atlas: atlas,
atlas: makeAtlas(face, runes), color: pixel.Alpha(1),
lineHeight: 1,
tabWidth: atlas.mapping[' '].advance * 4,
} }
txt.glyph.SetLen(6) txt.glyph.SetLen(6)
txt.d.Picture = txt.atlas.pic txt.d.Picture = txt.atlas.pic
@ -72,6 +79,14 @@ func (txt *Text) Color(c color.Color) {
txt.color = pixel.ToRGBA(c) txt.color = pixel.ToRGBA(c)
} }
func (txt *Text) LineHeight(scale float64) {
txt.lineHeight = scale
}
func (txt *Text) TabWidth(width float64) {
txt.tabWidth = width
}
func (txt *Text) Clear() { func (txt *Text) Clear() {
txt.prevR = -1 txt.prevR = -1
txt.tris.SetLen(0) txt.tris.SetLen(0)
@ -96,14 +111,14 @@ func (txt *Text) Write(p []byte) (n int, err error) {
switch r { switch r {
case '\n': case '\n':
txt.Dot -= pixel.Y(txt.atlas.lineHeight) txt.Dot -= pixel.Y(txt.atlas.lineHeight * txt.lineHeight)
txt.Dot = txt.Dot.WithX(txt.Orig.X()) txt.Dot = txt.Dot.WithX(txt.Orig.X())
continue continue
case '\r': case '\r':
txt.Dot = txt.Dot.WithX(txt.Orig.X()) txt.Dot = txt.Dot.WithX(txt.Orig.X())
continue continue
case '\t': case '\t':
//TODO txt.Dot += pixel.X(txt.tabWidth)
continue continue
} }